Skip to content

Commit

Permalink
Added additional profiler, no longer killing after timeouts, improvin…
Browse files Browse the repository at this point in the history
…g neo4j resource handling
  • Loading branch information
DavidBakerEffendi committed Jul 22, 2024
1 parent f837566 commit 424ba5a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ final class Neo4jEmbeddedDriver(
Try(tx.execute(query, params)) match {
case Failure(e) =>
logger.error(s"Unable to write bulk create node transaction $query", e)
case Success(_) =>
case Success(x) => x.close()
}
}
tx.commit()
Expand Down Expand Up @@ -174,7 +174,7 @@ final class Neo4jEmbeddedDriver(
Try(tx.execute(query, params)) match {
case Failure(e) =>
logger.error(s"Unable to write bulk set node property transaction $query", e)
case Success(_) =>
case Success(x) => x.close()
}
}
tx.commit()
Expand All @@ -200,7 +200,7 @@ final class Neo4jEmbeddedDriver(
) match {
case Failure(e) =>
logger.error(s"Unable to write bulk create edge transaction $query", e)
case Success(_) =>
case Success(x) => x.close()
}
}
tx.commit()
Expand Down Expand Up @@ -253,7 +253,7 @@ final class Neo4jEmbeddedDriver(
Using.resource(graphDb.beginTx) { tx =>
val payload = buildSchemaPayload()
try {
payload.lines().forEach(line => tx.execute(line))
payload.lines().forEach(line => tx.execute(line).close())
} catch {
case e: Exception =>
logger.error(s"Unable to set schema: $payload", e)
Expand Down
15 changes: 8 additions & 7 deletions runBenchmarks.sc
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def runAndMonitorBenchmarkProcess(cmd: String, writeOutputFile: File, readOutput
writeOutputFile.createIfNotExists
readOutputFile.createIfNotExists

val processBuilder = new java.lang.ProcessBuilder("sbt", cmd)
.redirectOutput(File(writeOutputFile.getAbsolutePath.stripSuffix("write.txt") + "sbt.txt"))
val sbtFile = File(writeOutputFile.getAbsolutePath.stripSuffix("write.txt") + "sbt.txt")
val processBuilder = new java.lang.ProcessBuilder("sbt", cmd).redirectOutput(sbtFile)

// Ignore locks for aborted JMH processes
val env = processBuilder.environment
Expand All @@ -101,10 +101,11 @@ def runAndMonitorBenchmarkProcess(cmd: String, writeOutputFile: File, readOutput
try {
var line: String = null
while ({ line = reader.readLine(); line != null }) {
if (line.contains("benchmark timed out")) {
println("Timeout detected. Sending Ctrl+C signal to process...")
shouldTerminate = true
} else if (line.contains("java.lang.OutOfMemoryError")) {
// if (line.contains("benchmark timed out")) {
// println("Timeout detected. Sending Ctrl+C signal to process...")
// shouldTerminate = true
// }
if (line.contains("java.lang.OutOfMemoryError")) {
println("OutOfMemoryError detected. Sending Ctrl+C signal to process...")
shouldTerminate = true
}
Expand All @@ -123,7 +124,7 @@ def runAndMonitorBenchmarkProcess(cmd: String, writeOutputFile: File, readOutput
var shouldTerminate = false
while (!shouldTerminate && process.isAlive) {
Thread.sleep(5000)
shouldTerminate = readLogsForErrors(writeOutputFile) || readLogsForErrors(readOutputFile)
shouldTerminate = readLogsForErrors(writeOutputFile) || readLogsForErrors(readOutputFile) || readLogsForErrors(sbtFile)
}
}

Expand Down
8 changes: 2 additions & 6 deletions src/main/scala/com/github/plume/oss/Benchmark.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.github.plume.oss.benchmarking.{
TinkerGraphReadBenchmark
}
import com.github.plume.oss.drivers.{IDriver, TinkerGraphDriver}
import org.cache2k.benchmark.jmh.HeapProfiler
import org.cache2k.benchmark.jmh.{HeapProfiler, LinuxVmProfiler}
import org.openjdk.jmh.annotations.Mode
import org.openjdk.jmh.runner.Runner
import org.openjdk.jmh.runner.options.{ChainedOptionsBuilder, OptionsBuilder, TimeValue}
Expand All @@ -24,7 +24,6 @@ object Benchmark {
.foreach { config =>
val writeOptsBenchmark = createOptionsBoilerPlate(config, WRITE)
.include(classOf[GraphWriteBenchmark].getSimpleName)
.warmupIterations(5)
.build()
new Runner(writeOptsBenchmark).run()
println(
Expand All @@ -36,21 +35,18 @@ object Benchmark {
Option(
createOptionsBoilerPlate(config, READ)
.include(classOf[TinkerGraphReadBenchmark].getSimpleName)
.warmupIterations(1)
.build()
)
case _: OverflowDbConfig =>
Option(
createOptionsBoilerPlate(config, READ)
.include(classOf[OverflowDbReadBenchmark].getSimpleName)
.warmupIterations(1)
.build()
)
case _: Neo4jEmbeddedConfig =>
Option(
createOptionsBoilerPlate(config, READ)
.include(classOf[Neo4jEmbedReadBenchmark].getSimpleName)
.warmupIterations(1)
.build()
)
case x =>
Expand All @@ -70,8 +66,8 @@ object Benchmark {
private def createOptionsBoilerPlate(config: PlumeConfig, benchmarkType: BenchmarkType): ChainedOptionsBuilder = {
new OptionsBuilder()
.addProfiler(classOf[HeapProfiler])
.addProfiler(classOf[LinuxVmProfiler])
.warmupTime(TimeValue.seconds(30))
.measurementIterations(3)
.mode(Mode.AverageTime)
.forks(1)
.output(s"${config.jmhOutputFile}-${benchmarkType.toString.toLowerCase}.txt")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import org.openjdk.jmh.annotations.{
Setup,
State,
TearDown,
Timeout
Timeout,
Warmup
}
import org.openjdk.jmh.infra.{BenchmarkParams, Blackhole}

Expand All @@ -25,6 +26,8 @@ import scala.compiletime.uninitialized
@State(Scope.Benchmark)
@Timeout(5, TimeUnit.MINUTES)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Measurement(iterations = 3, time = 5, timeUnit = TimeUnit.SECONDS)
@Warmup(iterations = 1, time = 1, timeUnit = TimeUnit.SECONDS)
trait GraphReadBenchmark {

@Param(Array(""))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import scala.compiletime.uninitialized
@State(Scope.Benchmark)
@Timeout(6, TimeUnit.MINUTES)
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 10, time = 2, timeUnit = TimeUnit.MINUTES)
@Warmup(iterations = 1, time = 5, timeUnit = TimeUnit.SECONDS)
class GraphWriteBenchmark {

@Param(Array(""))
Expand Down

0 comments on commit 424ba5a

Please sign in to comment.