From 03ee75266d45f975cc1ebdf4e3ad74ec412b09b1 Mon Sep 17 00:00:00 2001 From: Walter Oggioni Date: Thu, 16 Jan 2025 14:54:21 +0800 Subject: [PATCH] added average turnaround time calculation in benchmark --- .../gbcs/cli/impl/commands/BenchmarkCommand.kt | 13 +++++++++++++ .../resources/net/woggioni/gbcs/schema/gbcs.xsd | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/gbcs-cli/src/main/kotlin/net/woggioni/gbcs/cli/impl/commands/BenchmarkCommand.kt b/gbcs-cli/src/main/kotlin/net/woggioni/gbcs/cli/impl/commands/BenchmarkCommand.kt index b654894..9a61088 100644 --- a/gbcs-cli/src/main/kotlin/net/woggioni/gbcs/cli/impl/commands/BenchmarkCommand.kt +++ b/gbcs-cli/src/main/kotlin/net/woggioni/gbcs/cli/impl/commands/BenchmarkCommand.kt @@ -13,6 +13,7 @@ import java.util.Base64 import java.util.concurrent.ExecutionException import java.util.concurrent.Future import java.util.concurrent.LinkedBlockingQueue +import java.util.concurrent.atomic.AtomicLong import kotlin.random.Random @CommandLine.Command( @@ -53,9 +54,12 @@ class BenchmarkCommand : GbcsCommand() { val entries = let { val completionQueue = LinkedBlockingQueue>>(numberOfEntries) val start = Instant.now() + val totalElapsedTime = AtomicLong(0) entryGenerator.take(numberOfEntries).forEach { entry -> + val requestStart = System.nanoTime() val future = client.put(entry.first, entry.second).thenApply { entry } future.whenComplete { _, _ -> + totalElapsedTime.addAndGet((System.nanoTime() - requestStart)) completionQueue.put(future) } } @@ -78,6 +82,9 @@ class BenchmarkCommand : GbcsCommand() { val elapsed = Duration.between(start, end).toMillis() "Insertion rate: ${numberOfEntries.toDouble() / elapsed * 1000} ops/s" } + log.info { + "Average time per insertion: ${totalElapsedTime.get() / numberOfEntries.toDouble() * 1000} ms" + } inserted } log.info { @@ -86,8 +93,11 @@ class BenchmarkCommand : GbcsCommand() { if (entries.isNotEmpty()) { val completionQueue = LinkedBlockingQueue>(entries.size) val start = Instant.now() + val totalElapsedTime = AtomicLong(0) entries.forEach { entry -> + val requestStart = System.nanoTime() val future = client.get(entry.first).thenApply { + totalElapsedTime.addAndGet((System.nanoTime() - requestStart)) if (it == null) { log.error { "Missing entry for key '${entry.first}'" @@ -112,6 +122,9 @@ class BenchmarkCommand : GbcsCommand() { val elapsed = Duration.between(start, end).toMillis() "Retrieval rate: ${entries.size.toDouble() / elapsed * 1000} ops/s" } + log.info { + "Average time per retrieval: ${totalElapsedTime.get() / numberOfEntries.toDouble() * 1e6} ms" + } } else { log.error("Skipping retrieval benchmark as it was not possible to insert any entry in the cache") } diff --git a/src/main/resources/net/woggioni/gbcs/schema/gbcs.xsd b/src/main/resources/net/woggioni/gbcs/schema/gbcs.xsd index cb62b35..f32e6dd 100644 --- a/src/main/resources/net/woggioni/gbcs/schema/gbcs.xsd +++ b/src/main/resources/net/woggioni/gbcs/schema/gbcs.xsd @@ -48,8 +48,8 @@ - - + +