improved benchmark accuracy

This commit is contained in:
2025-02-05 19:10:25 +08:00
parent 7d0f24fa58
commit 53b24e3d54

View File

@@ -81,6 +81,8 @@ class BenchmarkCommand : GbcsCommand() {
semaphore.release() semaphore.release()
completionCounter.incrementAndGet() completionCounter.incrementAndGet()
} }
} else {
Thread.sleep(0)
} }
} }
@@ -103,23 +105,27 @@ class BenchmarkCommand : GbcsCommand() {
val completionCounter = AtomicLong(0) val completionCounter = AtomicLong(0)
val semaphore = Semaphore(profile.maxConnections * 3) val semaphore = Semaphore(profile.maxConnections * 3)
val start = Instant.now() val start = Instant.now()
entries.forEach { entry -> val it = entries.iterator()
semaphore.acquire() while (completionCounter.get() < entries.size) {
if (it.hasNext()) {
val future = client.get(entry.first).thenApply { val entry = it.next()
if (it == null) { val future = client.get(entry.first).thenApply {
log.error { if (it == null) {
"Missing entry for key '${entry.first}'" log.error {
} "Missing entry for key '${entry.first}'"
} else if (!entry.second.contentEquals(it)) { }
log.error { } else if (!entry.second.contentEquals(it)) {
"Retrieved a value different from what was inserted for key '${entry.first}'" log.error {
"Retrieved a value different from what was inserted for key '${entry.first}'"
}
} }
} }
} future.whenComplete { _, _ ->
future.whenComplete { _, _ -> completionCounter.incrementAndGet()
completionCounter.incrementAndGet() semaphore.release()
semaphore.release() }
} else {
Thread.sleep(0)
} }
} }
val end = Instant.now() val end = Instant.now()