Skip to content

Commit

Permalink
Use batch in benchmark.
Browse files Browse the repository at this point in the history
  • Loading branch information
kenwenzel committed Jun 19, 2024
1 parent 345a7d4 commit 6857268
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package io.github.linkedfactory.core.kvin.leveldb
import io.github.linkedfactory.core.kvin.{Kvin, KvinTuple}
import net.enilink.komma.core.URIs

import scala.collection.mutable
import scala.jdk.CollectionConverters._
import scala.util.Random

Expand All @@ -41,16 +42,22 @@ abstract class KvinBenchmarkBase extends App {
var rand = new Random(seed)

var currentTime = startTimeValues
val batch = new mutable.ArrayBuffer[KvinTuple]
(0 to writeValues).foreach { i =>
if (i % 100000 == 0) println(" at: " + i)

val randomNr = nrs(rand.nextInt(nrs.length))
val uri = URIs.createURI("http://linkedfactory.github.io/" + randomNr + "/e3fabrik/rollex/" + randomNr + "/measured-point-1")
val ctx = URIs.createURI("ctx:" + randomNr)

val value = if (randomNr % 2 == 0) rand.nextGaussian else rand.nextLong(100000)
batch.addOne(new KvinTuple(uri, valueProperty, ctx, currentTime, value))

// insert data via batch
if (i % 100000 == 0 || i == writeValues) {
println(" at: " + i)
store.put(batch.asJava)
batch.clear()
}

store.put(new KvinTuple(uri, valueProperty, ctx, currentTime, value))
currentTime += rand.nextInt(1000)
}

Expand All @@ -70,8 +77,6 @@ abstract class KvinBenchmarkBase extends App {
}

println(s"Reading $readValues values took: " + String.format("%1$,.2f seconds", ((System.currentTimeMillis - benchmarkStart) / 1000.0).asInstanceOf[AnyRef]))

store.descendants(URIs.createURI("")).toList.asScala.foreach { x => println("D: " + x) }
} finally {
Thread.sleep(5000)
store.close()
Expand Down

0 comments on commit 6857268

Please sign in to comment.