|
| 1 | +/* |
| 2 | + * Copyright 2023 Greptime Team |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package io.greptime.bench; |
| 18 | + |
| 19 | +import io.greptime.common.util.Cpus; |
| 20 | +import io.greptime.common.util.SystemPropertyUtil; |
| 21 | +import io.greptime.models.TableSchema; |
| 22 | +import org.slf4j.Logger; |
| 23 | + |
| 24 | +/** |
| 25 | + * Utility class for printing benchmark results in a consistent format. |
| 26 | + */ |
| 27 | +public class BenchmarkResultPrinter { |
| 28 | + |
| 29 | + public static void printBenchmarkHeader(Logger log, String apiType) { |
| 30 | + log.info("=== GreptimeDB {} API Log Benchmark ===", apiType); |
| 31 | + log.info("Synthetic log data generation and {} API ingestion performance test", apiType.toLowerCase()); |
| 32 | + log.info(""); |
| 33 | + } |
| 34 | + |
| 35 | + public static void printConfiguration( |
| 36 | + Logger log, String apiType, boolean zstdCompression, int batchSize, int parallelismOrConcurrency) { |
| 37 | + printConfiguration(log, apiType, zstdCompression, batchSize, parallelismOrConcurrency, null); |
| 38 | + } |
| 39 | + |
| 40 | + public static void printConfiguration( |
| 41 | + Logger log, |
| 42 | + String apiType, |
| 43 | + boolean zstdCompression, |
| 44 | + int batchSize, |
| 45 | + int parallelismOrConcurrency, |
| 46 | + Integer maxPointsPerSecond) { |
| 47 | + log.info("=== {} API Benchmark Configuration ===", apiType); |
| 48 | + |
| 49 | + String endpointsStr = SystemPropertyUtil.get("db.endpoints"); |
| 50 | + if (endpointsStr == null) { |
| 51 | + endpointsStr = "localhost:4001"; |
| 52 | + } |
| 53 | + String database = SystemPropertyUtil.get("db.database"); |
| 54 | + if (database == null) { |
| 55 | + database = "public"; |
| 56 | + } |
| 57 | + |
| 58 | + log.info("Endpoint: {}", endpointsStr); |
| 59 | + log.info("Database: {}", database); |
| 60 | + log.info("Batch size: {}", batchSize); |
| 61 | + |
| 62 | + if (maxPointsPerSecond != null) { |
| 63 | + log.info( |
| 64 | + "Max points per second: {}", |
| 65 | + maxPointsPerSecond == Integer.MAX_VALUE ? "unlimited" : maxPointsPerSecond); |
| 66 | + } else if (apiType.equals("Bulk")) { |
| 67 | + log.info("Parallelism: {}", parallelismOrConcurrency); |
| 68 | + } else { |
| 69 | + log.info("Concurrency: {}", parallelismOrConcurrency); |
| 70 | + } |
| 71 | + |
| 72 | + log.info("Compression: {}", (zstdCompression ? "zstd" : "none")); |
| 73 | + log.info("CPU cores: {}", Cpus.cpus()); |
| 74 | + log.info("Build profile: release"); |
| 75 | + log.info(""); |
| 76 | + } |
| 77 | + |
| 78 | + public static void printBenchmarkStart( |
| 79 | + Logger log, |
| 80 | + String apiType, |
| 81 | + TableDataProvider provider, |
| 82 | + TableSchema schema, |
| 83 | + int batchSize, |
| 84 | + int parallelismOrConcurrency) { |
| 85 | + printBenchmarkStart(log, apiType, provider, schema, batchSize, parallelismOrConcurrency, null); |
| 86 | + } |
| 87 | + |
| 88 | + public static void printBenchmarkStart( |
| 89 | + Logger log, |
| 90 | + String apiType, |
| 91 | + TableDataProvider provider, |
| 92 | + TableSchema schema, |
| 93 | + int batchSize, |
| 94 | + int parallelismOrConcurrency, |
| 95 | + Integer maxPointsPerSecond) { |
| 96 | + log.info("=== Running {} API Log Data Benchmark ===", apiType); |
| 97 | + log.info("Setting up {} writer...", apiType.toLowerCase()); |
| 98 | + log.info( |
| 99 | + "Starting {} API benchmark: {}", |
| 100 | + apiType.toLowerCase(), |
| 101 | + provider.getClass().getSimpleName()); |
| 102 | + log.info( |
| 103 | + "Table: {} ({} columns)", |
| 104 | + schema.getTableName(), |
| 105 | + schema.getColumnNames().size()); |
| 106 | + log.info("Target rows: {}", provider.rowCount()); |
| 107 | + log.info("Batch size: {}", batchSize); |
| 108 | + |
| 109 | + if (maxPointsPerSecond != null) { |
| 110 | + log.info( |
| 111 | + "Max points per second: {}", |
| 112 | + maxPointsPerSecond == Integer.MAX_VALUE ? "unlimited" : maxPointsPerSecond); |
| 113 | + } else if (apiType.equals("Bulk")) { |
| 114 | + log.info("Parallelism: {}", parallelismOrConcurrency); |
| 115 | + } else { |
| 116 | + log.info("Concurrency: {}", parallelismOrConcurrency); |
| 117 | + } |
| 118 | + |
| 119 | + log.info(""); |
| 120 | + } |
| 121 | + |
| 122 | + public static void printBatchProgress(Logger log, long batch, long totalRows, long writeRatePerSecond) { |
| 123 | + log.info("→ Batch {}: {} rows processed ({} rows/sec)", batch, totalRows, writeRatePerSecond); |
| 124 | + |
| 125 | + if (batch % 10 == 0) { |
| 126 | + log.info("Flushed {} responses (total {} affected rows)", batch, totalRows); |
| 127 | + } |
| 128 | + } |
| 129 | + |
| 130 | + public static void printCompletionMessages(Logger log, String apiType) { |
| 131 | + log.info("Finishing {} writer and waiting for all responses...", apiType.toLowerCase()); |
| 132 | + log.info("All {} writes completed successfully", apiType.toLowerCase()); |
| 133 | + log.info("Cleaning up data provider..."); |
| 134 | + log.info("{} API benchmark completed successfully!", apiType); |
| 135 | + } |
| 136 | + |
| 137 | + public static void printBenchmarkSummary( |
| 138 | + Logger log, TableDataProvider provider, long totalRows, long durationMs, long throughput) { |
| 139 | + log.info("=== Benchmark Result ==="); |
| 140 | + log.info("Table: {}", provider.tableSchema().getTableName()); |
| 141 | + log.info(""); |
| 142 | + log.info("Provider Rows Duration(ms) Throughput Status"); |
| 143 | + log.info("--------------------------------------------------------------------------"); |
| 144 | + log.info(String.format( |
| 145 | + "%-30s %8d %12d %12d r/s SUCCESS", |
| 146 | + provider.getClass().getSimpleName(), totalRows, durationMs, throughput)); |
| 147 | + } |
| 148 | +} |
0 commit comments