forked from rchain/perf-harness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContinuousRunner.scala
71 lines (56 loc) · 1.96 KB
/
ContinuousRunner.scala
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
package coop.rchain.perf
import java.nio.file.{FileSystems, Files, Path, Paths}
import io.gatling.app.Gatling
import io.gatling.core.Predef.{Simulation, scenario}
import io.gatling.core.Predef._
import io.gatling.core.config.GatlingPropertiesBuilder
import scala.collection.JavaConverters._
import scala.io.Source
import scala.concurrent.duration._
import scala.language.postfixOps
object ContinuousRunner {
val rhoMatcher = FileSystems.getDefault.getPathMatcher("glob:**.rho")
def main(args: Array[String]): Unit = {
val simClass = classOf[ContinuousSimulation].getName
val props = new GatlingPropertiesBuilder
props.simulationClass(simClass)
Gatling.fromMap(props.build)
}
class ContinuousSimulation extends Simulation {
import RNodeActionDSL._
val contractsPath = System.getProperty("path")
val hosts = System.getProperty("hosts")
val sessions = Integer.getInteger("sessions", 1)
val loops = Integer.getInteger("loops", 1)
val deploy2ProposeRatio: Int = Integer.getInteger("ratio", 1)
val basePath = Paths.get(contractsPath)
private val termsWithNames: List[(String, String)] = getAllRhosFromPath(
basePath)
println("will run contracts:")
termsWithNames.map(_._1).foreach(println)
println("-------------------")
val protocol: RNodeProtocol =
RNodeProtocol(hosts.split(" ").map((_, 40401)).toList)
val scn = scenario("ContinuousSimulation").repeat(Int.unbox(loops)) {
foreach(termsWithNames, "contract") {
repeat(deploy2ProposeRatio) {
exec(deploy())
}.exec(propose())
}
}
setUp(
scn.inject(atOnceUsers(sessions))
).protocols(protocol)
}
def getAllRhosFromPath(basePath: Path): List[(String, String)] =
Files
.walk(basePath)
.filter(rhoMatcher.matches(_))
.iterator()
.asScala
.map { p =>
(basePath.relativize(p).toString, Source.fromFile(p.toFile).mkString)
}
.toList
.sortBy(_._1)
}