@Override public void clientCallback(ClientResponse response) throws Exception { // Track the result of the operation (Success, Failure, Payload traffic...) if (response.getStatus() == ClientResponse.SUCCESS) { final VoltTable pairData = response.getResults()[0]; // Cache miss (Key does not exist) if (pairData.getRowCount() == 0) { missedGets.incrementAndGet(); } else { final PayloadProcessor.Pair pair = processor.retrieveFromStore( pairData.fetchRow(0).getString(0), pairData.fetchRow(0).getVarbinary(1)); successfulGets.incrementAndGet(); if (rand < config.multisingleratio) successfulGetsMPT.incrementAndGet(); else successfulGetsMPF.incrementAndGet(); networkGetData.addAndGet(pair.getStoreValueLength()); rawGetData.addAndGet(pair.getRawValueLength()); } } else { failedGets.incrementAndGet(); } }
/** * Core benchmark code. Connect. Initialize. Run the loop. Cleanup. Print Results. * * @throws Exception if anything unexpected happens. */ public void runBenchmark() throws Exception { System.out.print(HORIZONTAL_RULE); System.out.println(" Setup & Initialization"); System.out.println(HORIZONTAL_RULE); // preload keys if requested System.out.println(); if (config.preload) { System.out.println("Preloading data store..."); for (int i = config.preloadLowKey; i < config.poolsize; i++) { client.callProcedure( new NullCallback(), "Put", String.format(processor.KeyFormat, i), processor.generateForStore().getStoreValue()); } client.drain(); System.out.println("Preloading complete.\n"); } if (!config.runbenchmark) { System.out.println("Benchmark run disabled by --runbenchmark option, exiting now"); System.exit(0); } System.out.print(HORIZONTAL_RULE); System.out.println("Starting Benchmark"); System.out.println(HORIZONTAL_RULE); // Run the benchmark loop for the requested warmup time // The throughput may be throttled depending on client configuration if (config.warmup > 0) { System.out.println("Warming up..."); final long warmupEndTime = System.currentTimeMillis() + (1000l * config.warmup); while (warmupEndTime > System.currentTimeMillis()) { // Decide whether to perform a GET or PUT operation if (rand.nextDouble() < config.getputratio) { // Get a key/value pair, asynchronously client.callProcedure( new NullCallback(), "Get", processor.generateRandomKeyForRetrieval()); } else { // Put a key/value pair, asynchronously final PayloadProcessor.Pair pair = processor.generateForStore(); client.callProcedure(new NullCallback(), "Put", pair.Key, pair.getStoreValue()); } } } // reset the stats after warmup fullStatsContext.fetchAndResetBaseline(); periodicStatsContext.fetchAndResetBaseline(); // print periodic statistics to the console benchmarkStartTS = System.currentTimeMillis(); schedulePeriodicStats(); if (totalConnections.get() == 1) // If Volt is running on one node only, no need to run this test on multi-partition config.multisingleratio = 0; // Run the benchmark loop for the requested duration // The throughput may be throttled depending on client configuration System.out.println("\nRunning benchmark..."); final long benchmarkEndTime = System.currentTimeMillis() + (1000l * config.duration); long currentTime = System.currentTimeMillis(); long diff = benchmarkEndTime - currentTime; int i = 1; double mpRand; String msg = ""; while (benchmarkEndTime > currentTime) { if (debug && diff != 0 && diff % 5000.00 == 0 && i % 5 == 0) { msg = "i = " + i + ", Time remaining in seconds: " + diff / 1000l + ", totalConnections = " + totalConnections.get(); prt(msg); i++; } if (totalConnections.get() < 1) { if (debug) { msg = "i = " + i + ", diff = '" + diff + ", totalConnections = " + totalConnections.get() + "\n"; } msg += "All connections are lost! VoltDB could be down!!"; prt(msg); } // Decide whether to perform a GET or PUT operation if (rand.nextDouble() < config.getputratio) { // Get a key/value pair, asynchronously mpRand = rand.nextDouble(); if (mpRand < config.multisingleratio) { if (totalConnections.get() > 1 && config.poolsize > 10000) { slow = true; debug = true; } else debug = false; client.callProcedure( new GetCallback(mpRand), "GetMp", processor.generateRandomKeyForRetrieval()); } else { client.callProcedure( new GetCallback(mpRand), "Get", processor.generateRandomKeyForRetrieval()); } } else { // Put a key/value pair, asynchronously final PayloadProcessor.Pair pair = processor.generateForStore(); mpRand = rand.nextDouble(); if (rand.nextDouble() < config.multisingleratio) { if (totalConnections.get() > 1 && config.poolsize > 10000) { slow = true; debug = true; } else debug = false; client.callProcedure( new PutCallback(pair, mpRand), "PutMp", pair.Key, pair.getStoreValue()); } else { client.callProcedure( new PutCallback(pair, mpRand), "Put", pair.Key, pair.getStoreValue()); } } currentTime = System.currentTimeMillis(); diff = benchmarkEndTime - currentTime; } timer.cancel(); }
PutCallback(PayloadProcessor.Pair pair, double rand) { storeValueLength = pair.getStoreValueLength(); rawValueLength = pair.getRawValueLength(); thisPair = pair; this.rand = rand; }