forked from playframework/playframework.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGitFileRepositoryPerformanceTest.scala
More file actions
91 lines (77 loc) · 3.11 KB
/
Copy pathGitFileRepositoryPerformanceTest.scala
File metadata and controls
91 lines (77 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package utils
import java.io.File
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Await
import scala.concurrent.Future
import scala.util.Random
import org.apache.commons.io.IOUtils
import scala.concurrent.duration.Duration
import java.util.concurrent.atomic.AtomicLong
object GitFileRepositoryPerformanceTest {
def main(args: Array[String]): Unit = {
// Performance test should be performed on the actual Play git repository.
// Substitute here with the path to your own git repository to run this test.
val repo = new PlayGitRepository(new File("data/main"))
val basePath = "documentation/manual"
// First, find all the files that we might want to look up
val tags = repo.allTags
val allFiles = tags.flatMap { case (_, ref) =>
repo.listAllFilesInPath(ref, basePath).map((ref, _))
}
// Filter markdown files
val allMarkdown = allFiles.filter(_._2.endsWith(".md")).toIndexedSeq
println("Testing with " + allMarkdown.size + " markdown files")
def runTest(threads: Int, seconds: Long) = {
@volatile var running = true
val findFileWithNameTiming = new AtomicLong()
val loadFileTiming = new AtomicLong()
val tasks = Future.sequence(for (i <- 0 to threads) yield {
Future {
var markdownLoaded = 0
while (running) {
// Get a random markdown file
val (ref, file) = allMarkdown(Random.nextInt(allMarkdown.size))
// Strip the path off it, this is how requests come in
val name = file.drop(file.lastIndexOf('/') + 1)
// Find and then load it
val fileRepo = new GitFileRepository(repo, ref, Some(basePath))
def findFileWithName(name: String) = {
val start = System.nanoTime()
val result = fileRepo.findFileWithName(name)
findFileWithNameTiming.addAndGet(System.nanoTime() - start)
result
}
def loadFile(path: String) = {
val start = System.nanoTime()
val result = fileRepo.loadFile(path)(IOUtils.toString(_, "utf-8"))
loadFileTiming.addAndGet(System.nanoTime() - start)
result
}
markdownLoaded += findFileWithName(name).flatMap(loadFile).map(_ => 1).getOrElse(0)
}
markdownLoaded
}
})
Thread.sleep(seconds * 1000)
println("Stopping tests...")
running = false
val loaded = Await.result(tasks, Duration.Inf).reduce((a, b) => a + b)
println("Loaded " + loaded + " files in " + seconds + " seconds")
println("That's " + (loaded / seconds) + " files a second")
println(s"Total time spent finding markdown files: ${findFileWithNameTiming.get() / 1000000}ms")
println(s"Total time spent loading markdown files: ${loadFileTiming.get() / 1000000}ms")
}
println()
println("Test run 1:")
println()
runTest(10, 10)
println()
println("Test run 2:")
println()
runTest(10, 10)
println()
println("Test run 3:")
println()
runTest(10, 10)
}
}