|
27 | 27 | import io.questdb.client.Sender; |
28 | 28 |
|
29 | 29 | import java.io.IOException; |
| 30 | +import java.sql.Connection; |
| 31 | +import java.sql.DriverManager; |
| 32 | +import java.sql.Statement; |
30 | 33 | import java.time.temporal.ChronoUnit; |
| 34 | +import java.util.Properties; |
31 | 35 | import java.util.concurrent.TimeUnit; |
32 | 36 |
|
33 | 37 | /** |
@@ -95,6 +99,7 @@ public class QwpAllocationTestClient { |
95 | 99 | "AAPL", "GOOGL", "MSFT", "AMZN", "META", "NVDA", "TSLA", "BRK.A", "JPM", "JNJ", |
96 | 100 | "V", "PG", "UNH", "HD", "MA", "DIS", "PYPL", "BAC", "ADBE", "CMCSA" |
97 | 101 | }; |
| 102 | + private static final String TABLE_NAME = "ilp_alloc_test"; |
98 | 103 |
|
99 | 104 | public static void main(String[] args) { |
100 | 105 | // Parse command-line options |
@@ -173,6 +178,7 @@ public static void main(String[] args) { |
173 | 178 | System.out.println(); |
174 | 179 |
|
175 | 180 | try { |
| 181 | + recreateTable(host); |
176 | 182 | runTest(protocol, host, port, totalRows, batchSize, flushBytes, flushIntervalMs, |
177 | 183 | inFlightWindow, maxDatagramSize, warmupRows, reportInterval, targetThroughput); |
178 | 184 | } catch (Exception e) { |
@@ -286,6 +292,35 @@ private static void printUsage() { |
286 | 292 | System.out.println(" QwpAllocationTestClient --protocol=ilp-tcp --rows=100000 --no-warmup"); |
287 | 293 | } |
288 | 294 |
|
| 295 | + private static void recreateTable(String host) throws Exception { |
| 296 | + Properties properties = new Properties(); |
| 297 | + properties.setProperty("user", "admin"); |
| 298 | + properties.setProperty("password", "quest"); |
| 299 | + properties.setProperty("sslmode", "disable"); |
| 300 | + String url = "jdbc:postgresql://" + host + ":8812/qdb"; |
| 301 | + try (Connection conn = DriverManager.getConnection(url, properties); |
| 302 | + Statement st = conn.createStatement() |
| 303 | + ) { |
| 304 | + st.execute("DROP TABLE IF EXISTS " + TABLE_NAME); |
| 305 | + st.execute("CREATE TABLE " + TABLE_NAME + " (" |
| 306 | + + " timestamp TIMESTAMP," |
| 307 | + + " exchange SYMBOL," |
| 308 | + + " currency SYMBOL," |
| 309 | + + " trade_id LONG," |
| 310 | + + " volume LONG," |
| 311 | + + " price DOUBLE," |
| 312 | + + " bid DOUBLE," |
| 313 | + + " ask DOUBLE," |
| 314 | + + " sequence LONG," |
| 315 | + + " spread DOUBLE," |
| 316 | + + " venue VARCHAR," |
| 317 | + + " is_buy BOOLEAN," |
| 318 | + + " event_time TIMESTAMP" |
| 319 | + + ") TIMESTAMP(timestamp) PARTITION BY DAY WAL"); |
| 320 | + } |
| 321 | + System.out.println("Recreated table " + TABLE_NAME); |
| 322 | + } |
| 323 | + |
289 | 324 | private static void runTest(String protocol, String host, int port, int totalRows, |
290 | 325 | int batchSize, int flushBytes, long flushIntervalMs, |
291 | 326 | int inFlightWindow, int maxDatagramSize, |
@@ -345,9 +380,9 @@ private static void runTest(String protocol, String host, int port, int totalRow |
345 | 380 | long now = System.nanoTime(); |
346 | 381 | long elapsedSinceReport = now - lastReportTime; |
347 | 382 | int rowsSinceReport = (i + 1) - lastReportRows; |
348 | | - double rowsPerSec = rowsSinceReport / (elapsedSinceReport / 1_000_000_000.0); |
| 383 | + int rowsPerSec = (int) (rowsSinceReport / (elapsedSinceReport / 1_000_000_000.0)); |
349 | 384 |
|
350 | | - System.out.printf("Progress: %,d / %,d rows (%.1f%%) - %.0f rows/sec%n", |
| 385 | + System.out.printf("Progress: %,d / %,d rows (%.1f%%) - %,d rows/sec%n", |
351 | 386 | i + 1, totalRows, |
352 | 387 | (i + 1) * 100.0 / totalRows, |
353 | 388 | rowsPerSec); |
@@ -386,7 +421,7 @@ private static void sendRow(Sender sender, int rowIndex) { |
386 | 421 | long baseTimestamp = 1704067200000000L; // 2024-01-01 00:00:00 UTC in micros |
387 | 422 | long timestamp = baseTimestamp + (rowIndex * 1000L) + (rowIndex % 100); |
388 | 423 |
|
389 | | - sender.table("ilp_alloc_test") |
| 424 | + sender.table(TABLE_NAME) |
390 | 425 | // Symbol columns |
391 | 426 | .symbol("exchange", SYMBOLS[rowIndex % SYMBOLS.length]) |
392 | 427 | .symbol("currency", rowIndex % 2 == 0 ? "USD" : "EUR") |
|
0 commit comments