diff --git a/storage-shared-benchmarking/src/main/java/com/google/cloud/storage/benchmarking/StorageSharedBenchmarkingUtils.java b/storage-shared-benchmarking/src/main/java/com/google/cloud/storage/benchmarking/StorageSharedBenchmarkingUtils.java index 0407cf7015..137fee5162 100644 --- a/storage-shared-benchmarking/src/main/java/com/google/cloud/storage/benchmarking/StorageSharedBenchmarkingUtils.java +++ b/storage-shared-benchmarking/src/main/java/com/google/cloud/storage/benchmarking/StorageSharedBenchmarkingUtils.java @@ -28,9 +28,12 @@ public static void cleanupObject(Storage storage, Blob created) { created.getBlobId(), Storage.BlobSourceOption.generationMatch(created.getGeneration())); } - public static double calculateThroughput(long size, Duration elapsedTime) { - return size >= StorageSharedBenchmarkingUtils.SSB_SIZE_THRESHOLD_BYTES - ? size / 1024 / 1024 / (elapsedTime.toNanos()) - : size / 1024 / (elapsedTime.toNanos()); + public static double calculateThroughput(double size, Duration elapsedTime) { + double adjustedSize = + size >= StorageSharedBenchmarkingUtils.SSB_SIZE_THRESHOLD_BYTES + ? (size / 1024D) / 1024D + : size / 1024D; + double throughput = adjustedSize / (elapsedTime.toMillis() / 1000D); + return throughput; } } diff --git a/storage-shared-benchmarking/src/main/java/com/google/cloud/storage/benchmarking/W1R3.java b/storage-shared-benchmarking/src/main/java/com/google/cloud/storage/benchmarking/W1R3.java index 9833edee57..fc96f7090b 100644 --- a/storage-shared-benchmarking/src/main/java/com/google/cloud/storage/benchmarking/W1R3.java +++ b/storage-shared-benchmarking/src/main/java/com/google/cloud/storage/benchmarking/W1R3.java @@ -58,9 +58,9 @@ final class W1R3 implements Callable { @Override public String call() throws Exception { // Create the file to be uploaded and fill it with data + try (TmpFile file = DataGenerator.base64Characters().tempFile(tempDirectory, objectSize)) { BlobInfo blob = BlobInfo.newBuilder(bucketName, file.toString()).build(); - // Get the start time Clock clock = Clock.systemDefaultZone(); Instant startTime = clock.instant(); @@ -71,7 +71,7 @@ public String call() throws Exception { generateCloudMonitoringResult( "WRITE", StorageSharedBenchmarkingUtils.calculateThroughput( - created.getSize().longValue(), elapsedTimeUpload), + created.getSize().doubleValue(), elapsedTimeUpload), created) .formatAsCustomMetric()); for (int i = 0; i <= StorageSharedBenchmarkingUtils.DEFAULT_NUMBER_OF_READS; i++) { @@ -84,7 +84,7 @@ public String call() throws Exception { generateCloudMonitoringResult( "READ[" + i + "]", StorageSharedBenchmarkingUtils.calculateThroughput( - created.getSize().longValue(), elapsedTimeDownload), + created.getSize().doubleValue(), elapsedTimeDownload), created) .formatAsCustomMetric()); }