use of org.voltdb.jdbc.IVoltDBConnection in project voltdb by VoltDB.
the class JDBCBenchmark method main.
// Application entry point
public static void main(String[] args) {
try {
// ---------------------------------------------------------------------------------------------------------------------------------------------------
// Use the AppHelper utility class to retrieve command line application parameters
// Define parameters and pull from command line
AppHelper apph = new AppHelper(JDBCBenchmark.class.getCanonicalName()).add("threads", "thread_count", "Number of concurrent threads attacking the database.", 1).add("displayinterval", "display_interval_in_seconds", "Interval for performance feedback, in seconds.", 10).add("duration", "run_duration_in_seconds", "Benchmark duration, in seconds.", 120).add("servers", "comma_separated_server_list", "List of VoltDB servers to connect to.", "localhost").add("port", "port_number", "Client port to connect to on cluster nodes.", 21212).add("poolsize", "pool_size", "Size of the record pool to operate on - larger sizes will cause a higher insert/update-delete rate.", 100000).add("procedure", "procedure_name", "Procedure to call.", "JiggleSinglePartition").add("wait", "wait_duration", "Wait duration (only when calling one of the Wait procedures), in milliseconds.", 0).setArguments(args);
// Retrieve parameters
final int threadCount = apph.intValue("threads");
final long displayInterval = apph.longValue("displayinterval");
final long duration = apph.longValue("duration");
final String servers = apph.stringValue("servers");
final int port = apph.intValue("port");
final int poolSize = apph.intValue("poolsize");
final String procedure = apph.stringValue("procedure");
final long wait = apph.intValue("wait");
final String csv = apph.stringValue("statsfile");
// Validate parameters
apph.validate("duration", (duration > 0)).validate("threads", (threadCount > 0)).validate("poolsize", (poolSize > 0)).validate("wait", (wait >= 0));
// Display actual parameters, for reference
apph.printActualUsage();
// ---------------------------------------------------------------------------------------------------------------------------------------------------
// We need only do this once, to "hot cache" the JDBC driver reference so the JVM may realize it's there.
Class.forName("org.voltdb.jdbc.Driver");
// Prepare the JDBC URL for the VoltDB driver
String url = "jdbc:voltdb://" + servers + ":" + port;
// Get a client connection - we retry for a while in case the server hasn't started yet
System.out.printf("Connecting to: %s\n", url);
int sleep = 1000;
while (true) {
try {
Con = DriverManager.getConnection(url, "", "");
break;
} catch (Exception e) {
System.err.printf("Connection failed - retrying in %d second(s).\n", sleep / 1000);
try {
Thread.sleep(sleep);
} catch (Exception tie) {
}
if (sleep < 8000)
sleep += sleep;
}
}
System.out.println("Connected. Starting benchmark.");
// ---------------------------------------------------------------------------------------------------------------------------------------------------
final ClientStatsContext fullStatsContext = ((IVoltDBConnection) Con).createStatsContext();
periodicStatsContext = ((IVoltDBConnection) Con).createStatsContext();
benchmarkStartTS = System.currentTimeMillis();
// Create a Timer task to display performance data on the procedure
Timer timer = new Timer();
TimerTask statsPrinting = new TimerTask() {
@Override
public void run() {
printStatistics();
}
};
timer.scheduleAtFixedRate(statsPrinting, displayInterval * 1000l, displayInterval * 1000l);
// ---------------------------------------------------------------------------------------------------------------------------------------------------
// Create multiple processing threads
ArrayList<Thread> threads = new ArrayList<Thread>();
for (int i = 0; i < threadCount; i++) threads.add(new Thread(new ClientThread(url, procedure, poolSize, wait, duration)));
// Start threads
for (Thread thread : threads) thread.start();
// Wait for threads to complete
for (Thread thread : threads) thread.join();
// ---------------------------------------------------------------------------------------------------------------------------------------------------
// We're done - stop the performance statistics display task
timer.cancel();
// ---------------------------------------------------------------------------------------------------------------------------------------------------
// Now print application results:
// 1. Tracking statistics
System.out.printf("-------------------------------------------------------------------------------------\n" + " Benchmark Results\n" + "-------------------------------------------------------------------------------------\n\n" + "A total of %d calls was received...\n" + " - %,9d Succeeded\n" + " - %,9d Failed (Transaction Error)\n" + "\n\n" + "-------------------------------------------------------------------------------------\n", TrackingResults.get(0) + TrackingResults.get(1), TrackingResults.get(0), TrackingResults.get(1));
// 3. Performance statistics (we only care about the procedure that we're benchmarking)
System.out.println("\n\n-------------------------------------------------------------------------------------\n" + " System Statistics\n" + "-------------------------------------------------------------------------------------\n\n");
try {
System.out.print(fullStatsContext.getStatsForProcedure(procedure).toString());
} catch (Exception e) {
e.printStackTrace();
}
// Dump statistics to a CSV file
Con.unwrap(IVoltDBConnection.class).saveStatistics(fullStatsContext.getStats(), csv);
Con.close();
// ---------------------------------------------------------------------------------------------------------------------------------------------------
} catch (Exception x) {
System.out.println("Exception: " + x);
x.printStackTrace();
}
}
use of org.voltdb.jdbc.IVoltDBConnection in project voltdb by VoltDB.
the class JDBCBenchmark method main.
// Application entry point
public static void main(String[] args) {
try {
KVConfig config = new KVConfig();
config.parse(JDBCBenchmark.class.getName(), args);
System.out.println(config.getConfigDumpString());
// ---------------------------------------------------------------------------------------------------------------------------------------------------
// We need only do this once, to "hot cache" the JDBC driver reference so the JVM may realize it's there.
Class.forName(DRIVER_NAME);
// Prepare the JDBC URL for the VoltDB driver
String url = "jdbc:voltdb://" + config.servers;
// Prepare the Datasource if choose to use a connection pool
if (config.externalConnectionPool.equalsIgnoreCase(C3P0_CONNECTIONPOOL)) {
useConnectionPool = true;
ComboPooledDataSource cpds = new ComboPooledDataSource();
//loads the jdbc driver
cpds.setDriverClass(DRIVER_NAME);
cpds.setJdbcUrl(url);
Ds = cpds;
} else if (config.externalConnectionPool.equalsIgnoreCase(TOMCAT_CONNECTIONPOOL)) {
useConnectionPool = true;
// read the config file for connection pool
String configName = "tomcat.properties";
boolean useDefaultConnectionPoolConfig = true;
Properties cpProperties = new Properties();
try {
FileInputStream fileInput = new FileInputStream(new File(configName));
cpProperties.load(fileInput);
fileInput.close();
useDefaultConnectionPoolConfig = false;
} catch (FileNotFoundException e) {
System.out.println("connection pool property file '" + configName + "' not found, use default settings");
}
PoolProperties p = new PoolProperties();
p.setUrl(url);
p.setDriverClassName(DRIVER_NAME);
if (useDefaultConnectionPoolConfig) {
p.setInitialSize(config.threads + 1);
} else {
p.setInitialSize(Integer.parseInt(cpProperties.getProperty("tomcat.initialSize", "40")));
}
org.apache.tomcat.jdbc.pool.DataSource tomcatDs = new org.apache.tomcat.jdbc.pool.DataSource();
tomcatDs.setPoolProperties(p);
Ds = tomcatDs;
} else if (config.externalConnectionPool.equalsIgnoreCase(BONECP_CONNECTIONPOOL)) {
useConnectionPool = true;
String configName = "bonecp.properties";
boolean useDefaultConnectionPoolConfig = true;
Properties cpProperties = new Properties();
try {
FileInputStream fileInput = new FileInputStream(new File(configName));
cpProperties.load(fileInput);
fileInput.close();
useDefaultConnectionPoolConfig = false;
} catch (FileNotFoundException e) {
System.out.println("connection pool property file '" + configName + "' not found, use default settings");
}
BoneCPConfig p;
if (useDefaultConnectionPoolConfig) {
p = new BoneCPConfig();
p.setDefaultReadOnly(false);
p.setPartitionCount(config.threads / 2);
p.setMaxConnectionsPerPartition(4);
} else {
p = new BoneCPConfig(cpProperties);
}
// set the JDBC url
p.setJdbcUrl(url + "?enableSetReadOnly=true");
BoneCPDataSource boneDs = new BoneCPDataSource(p);
Ds = boneDs;
} else if (config.externalConnectionPool.equalsIgnoreCase(HIKARI_CONNECTIONPOOL)) {
useConnectionPool = true;
HikariConfig p = new HikariConfig("hikari.properties");
p.setDriverClassName(DRIVER_NAME);
p.setJdbcUrl(url);
HikariDataSource hiDs = new HikariDataSource(p);
Ds = hiDs;
} else {
useConnectionPool = false;
Ds = null;
}
// Get a client connection - we retry for a while in case the server hasn't started yet
System.out.printf("Connecting to: %s\n", url);
int sleep = 1000;
while (true) {
try {
if (useConnectionPool) {
Ds.getConnection();
System.out.printf("Using Connection Pool: %s\n", config.externalConnectionPool);
}
Con = DriverManager.getConnection(url, "", "");
break;
} catch (Exception e) {
System.err.printf("Connection failed - retrying in %d second(s).\n " + e, sleep / 1000);
try {
Thread.sleep(sleep);
} catch (Exception tie) {
}
if (sleep < 8000)
sleep += sleep;
}
}
// Statistics manager objects from the connection, used to generate latency histogram
ClientStatsContext fullStatsContext = ((IVoltDBConnection) Con).createStatsContext();
periodicStatsContext = ((IVoltDBConnection) Con).createStatsContext();
System.out.println("Connected. Starting benchmark.");
// Get a payload generator to create random Key-Value pairs to store in the database and process (uncompress) pairs retrieved from the database.
final PayloadProcessor processor = new PayloadProcessor(config.keysize, config.minvaluesize, config.maxvaluesize, config.entropy, config.poolsize, config.usecompression);
// Initialize the store
if (config.preload) {
System.out.print("Initializing data store... ");
final PreparedStatement removeCS = Con.prepareStatement("DELETE FROM store;");
final CallableStatement putCS = Con.prepareCall("{call STORE.upsert(?,?)}");
for (int i = 0; i < config.poolsize; i++) {
if (i == 0) {
removeCS.execute();
}
putCS.setString(1, String.format(processor.KeyFormat, i));
putCS.setBytes(2, processor.generateForStore().getStoreValue());
putCS.execute();
}
System.out.println(" Done.");
}
// start the stats
fullStatsContext.fetchAndResetBaseline();
periodicStatsContext.fetchAndResetBaseline();
benchmarkStartTS = System.currentTimeMillis();
// ---------------------------------------------------------------------------------------------------------------------------------------------------
// Create a Timer task to display performance data on the operating procedures
Timer timer = new Timer();
TimerTask statsPrinting = new TimerTask() {
@Override
public void run() {
printStatistics();
}
};
timer.scheduleAtFixedRate(statsPrinting, config.displayinterval * 1000l, config.displayinterval * 1000l);
// ---------------------------------------------------------------------------------------------------------------------------------------------------
// Create multiple processing threads
ArrayList<Thread> threads = new ArrayList<Thread>();
for (int i = 0; i < config.threads; i++) threads.add(new Thread(new ClientThread(url, processor, config.duration, config.getputratio)));
// Start threads
for (Thread thread : threads) thread.start();
// Wait for threads to complete
for (Thread thread : threads) thread.join();
// ---------------------------------------------------------------------------------------------------------------------------------------------------
// We're done - stop the performance statistics display task
timer.cancel();
// ---------------------------------------------------------------------------------------------------------------------------------------------------
// Now print application results:
// stop and fetch the stats
ClientStats stats = fullStatsContext.fetch().getStats();
// 1. Store statistics as tracked by the application (ops counts, payload traffic)
System.out.printf("\n-------------------------------------------------------------------------------------\n" + " Store Results\n" + "-------------------------------------------------------------------------------------\n\n" + "A total of %,d operations was posted...\n" + " - GETs: %,9d Operations (%,9d Misses/Failures)\n" + " %,9d MB in compressed store data\n" + " %,9d MB in uncompressed application data\n" + " Network Throughput: %6.3f Gbps*\n\n" + " - PUTs: %,9d Operations (%,9d Failures)\n" + " %,9d MB in compressed store data\n" + " %,9d MB in uncompressed application data\n" + " Network Throughput: %6.3f Gbps*\n\n" + " - Total Network Throughput: %6.3f Gbps*\n\n" + "* Figure includes key & value traffic but not database protocol overhead.\n" + "\n" + "-------------------------------------------------------------------------------------\n", GetStoreResults.get(0) + GetStoreResults.get(1) + PutStoreResults.get(0) + PutStoreResults.get(1), GetStoreResults.get(0), GetStoreResults.get(1), GetCompressionResults.get(0) / 1048576l, GetCompressionResults.get(1) / 1048576l, ((double) GetCompressionResults.get(0) + (GetStoreResults.get(0) + GetStoreResults.get(1)) * config.keysize) / (134217728d * config.duration), PutStoreResults.get(0), PutStoreResults.get(1), PutCompressionResults.get(0) / 1048576l, PutCompressionResults.get(1) / 1048576l, ((double) PutCompressionResults.get(0) + (PutStoreResults.get(0) + PutStoreResults.get(1)) * config.keysize) / (134217728d * config.duration), ((double) GetCompressionResults.get(0) + (GetStoreResults.get(0) + GetStoreResults.get(1)) * config.keysize) / (134217728d * config.duration) + ((double) PutCompressionResults.get(0) + (PutStoreResults.get(0) + PutStoreResults.get(1)) * config.keysize) / (134217728d * config.duration));
System.out.println("\n\n-------------------------------------------------------------------------------------\n" + " Client Latency Statistics\n" + "-------------------------------------------------------------------------------------\n\n");
System.out.printf("Average latency: %,9.2f ms\n", stats.getAverageLatency());
System.out.printf("10th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.1));
System.out.printf("25th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.25));
System.out.printf("50th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.5));
System.out.printf("75th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.75));
System.out.printf("90th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.9));
System.out.printf("95th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.95));
System.out.printf("99th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.99));
System.out.printf("99.5th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.995));
System.out.printf("99.9th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.999));
System.out.println("\n\n" + stats.latencyHistoReport());
// Dump statistics to a CSV file
Con.unwrap(IVoltDBConnection.class).saveStatistics(stats, config.statsfile);
Con.close();
// ---------------------------------------------------------------------------------------------------------------------------------------------------
} catch (Exception x) {
System.out.println("Exception: " + x);
x.printStackTrace();
}
}
use of org.voltdb.jdbc.IVoltDBConnection in project voltdb by VoltDB.
the class JDBCBenchmark method printResults.
/**
* Prints the results of the voting simulation and statistics about
* performance.
*
* @throws Exception
* if anything unexpected happens.
*/
public synchronized void printResults() throws Exception {
ClientStats stats = fullStatsContext.fetch().getStats();
// 1. Voting Board statistics, Voting results and performance statistics
String display = "\n" + HORIZONTAL_RULE + " Voting Results\n" + HORIZONTAL_RULE + "\nA total of %d votes were received...\n" + " - %,9d Accepted\n" + " - %,9d Rejected (Invalid Contestant)\n" + " - %,9d Rejected (Maximum Vote Count Reached)\n" + " - %,9d Failed (Transaction Error)\n\n";
System.out.printf(display, stats.getInvocationsCompleted(), acceptedVotes.get(), badContestantVotes.get(), badVoteCountVotes.get(), failedVotes.get());
// 2. Voting results
final CallableStatement resultsCS = client.prepareCall("{call Results}");
ResultSet result = resultsCS.executeQuery();
String winner = "";
long winnerVoteCount = 0;
System.out.println("Contestant Name\t\tVotes Received");
while (result.next()) {
if (result.getLong(3) > winnerVoteCount) {
winnerVoteCount = result.getLong(3);
winner = result.getString(1);
}
System.out.printf("%s\t\t%,14d\n", result.getString(1), result.getLong(3));
}
System.out.printf("\nThe Winner is: %s\n\n", winner);
// 3. Performance statistics
System.out.print(HORIZONTAL_RULE);
System.out.println(" Client Workload Statistics");
System.out.println(HORIZONTAL_RULE);
System.out.printf("Average throughput: %,9d txns/sec\n", stats.getTxnThroughput());
System.out.printf("Average latency: %,9.2f ms\n", stats.getAverageLatency());
System.out.printf("95th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.95));
System.out.printf("99th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.99));
System.out.print("\n" + HORIZONTAL_RULE);
System.out.println(" System Server Statistics");
System.out.println(HORIZONTAL_RULE);
System.out.printf("Reported Internal Avg Latency: %,9.2f ms\n", stats.getAverageInternalLatency());
// 4. Write stats to file if requested
((IVoltDBConnection) client).writeSummaryCSV(stats, config.statsfile);
}
use of org.voltdb.jdbc.IVoltDBConnection in project voltdb by VoltDB.
the class JDBCBenchmark method main.
// Application entry point
public static void main(String[] args) {
try {
KVConfig config = new KVConfig();
config.parse(JDBCBenchmark.class.getName(), args);
System.out.println(config.getConfigDumpString());
// ---------------------------------------------------------------------------------------------------------------------------------------------------
// We need only do this once, to "hot cache" the JDBC driver reference so the JVM may realize it's there.
Class.forName("org.voltdb.jdbc.Driver");
// Prepare the JDBC URL for the VoltDB driver
String url = "jdbc:voltdb://" + config.servers;
// Get a client connection - we retry for a while in case the server hasn't started yet
System.out.printf("Connecting to: %s\n", url);
int sleep = 1000;
while (true) {
try {
Con = DriverManager.getConnection(url, "", "");
break;
} catch (Exception e) {
System.err.printf("Connection failed - retrying in %d second(s).\n", sleep / 1000);
try {
Thread.sleep(sleep);
} catch (Exception tie) {
}
if (sleep < 8000)
sleep += sleep;
}
}
// Statistics manager objects from the connection, used to generate latency histogram
ClientStatsContext fullStatsContext = ((IVoltDBConnection) Con).createStatsContext();
periodicStatsContext = ((IVoltDBConnection) Con).createStatsContext();
System.out.println("Connected. Starting benchmark.");
// Get a payload generator to create random Key-Value pairs to store in the database and process (uncompress) pairs retrieved from the database.
final PayloadProcessor processor = new PayloadProcessor(config.keysize, config.minvaluesize, config.maxvaluesize, config.entropy, config.poolsize, config.usecompression);
// Initialize the store
if (config.preload) {
System.out.print("Initializing data store... ");
final PreparedStatement removeCS = Con.prepareStatement("DELETE FROM store;");
final CallableStatement putCS = Con.prepareCall("{call STORE.upsert(?,?)}");
for (int i = 0; i < config.poolsize; i++) {
if (i == 0) {
removeCS.execute();
}
putCS.setString(1, String.format(processor.KeyFormat, i));
putCS.setBytes(2, processor.generateForStore().getStoreValue());
putCS.execute();
}
System.out.println(" Done.");
}
// start the stats
fullStatsContext.fetchAndResetBaseline();
periodicStatsContext.fetchAndResetBaseline();
benchmarkStartTS = System.currentTimeMillis();
// ---------------------------------------------------------------------------------------------------------------------------------------------------
// Create a Timer task to display performance data on the operating procedures
Timer timer = new Timer();
TimerTask statsPrinting = new TimerTask() {
@Override
public void run() {
printStatistics();
}
};
timer.scheduleAtFixedRate(statsPrinting, config.displayinterval * 1000l, config.displayinterval * 1000l);
// ---------------------------------------------------------------------------------------------------------------------------------------------------
// Create multiple processing threads
ArrayList<Thread> threads = new ArrayList<Thread>();
for (int i = 0; i < config.threads; i++) threads.add(new Thread(new ClientThread(url, processor, config.duration, config.getputratio)));
// Start threads
for (Thread thread : threads) thread.start();
// Wait for threads to complete
for (Thread thread : threads) thread.join();
// ---------------------------------------------------------------------------------------------------------------------------------------------------
// We're done - stop the performance statistics display task
timer.cancel();
// ---------------------------------------------------------------------------------------------------------------------------------------------------
// Now print application results:
// stop and fetch the stats
ClientStats stats = fullStatsContext.fetch().getStats();
// 1. Store statistics as tracked by the application (ops counts, payload traffic)
System.out.printf("\n-------------------------------------------------------------------------------------\n" + " Store Results\n" + "-------------------------------------------------------------------------------------\n\n" + "A total of %,d operations was posted...\n" + " - GETs: %,9d Operations (%,9d Misses/Failures)\n" + " %,9d MB in compressed store data\n" + " %,9d MB in uncompressed application data\n" + " Network Throughput: %6.3f Gbps*\n\n" + " - PUTs: %,9d Operations (%,9d Failures)\n" + " %,9d MB in compressed store data\n" + " %,9d MB in uncompressed application data\n" + " Network Throughput: %6.3f Gbps*\n\n" + " - Total Network Throughput: %6.3f Gbps*\n\n" + "* Figure includes key & value traffic but not database protocol overhead.\n" + "\n" + "-------------------------------------------------------------------------------------\n", GetStoreResults.get(0) + GetStoreResults.get(1) + PutStoreResults.get(0) + PutStoreResults.get(1), GetStoreResults.get(0), GetStoreResults.get(1), GetCompressionResults.get(0) / 1048576l, GetCompressionResults.get(1) / 1048576l, ((double) GetCompressionResults.get(0) + (GetStoreResults.get(0) + GetStoreResults.get(1)) * config.keysize) / (134217728d * config.duration), PutStoreResults.get(0), PutStoreResults.get(1), PutCompressionResults.get(0) / 1048576l, PutCompressionResults.get(1) / 1048576l, ((double) PutCompressionResults.get(0) + (PutStoreResults.get(0) + PutStoreResults.get(1)) * config.keysize) / (134217728d * config.duration), ((double) GetCompressionResults.get(0) + (GetStoreResults.get(0) + GetStoreResults.get(1)) * config.keysize) / (134217728d * config.duration) + ((double) PutCompressionResults.get(0) + (PutStoreResults.get(0) + PutStoreResults.get(1)) * config.keysize) / (134217728d * config.duration));
System.out.println("\n\n-------------------------------------------------------------------------------------\n" + " Client Latency Statistics\n" + "-------------------------------------------------------------------------------------\n\n");
System.out.printf("Average latency: %,9.2f ms\n", stats.getAverageLatency());
System.out.printf("10th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.1));
System.out.printf("25th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.25));
System.out.printf("50th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.5));
System.out.printf("75th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.75));
System.out.printf("90th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.9));
System.out.printf("95th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.95));
System.out.printf("99th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.99));
System.out.printf("99.5th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.995));
System.out.printf("99.9th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.999));
System.out.println("\n\n" + stats.latencyHistoReport());
// Dump statistics to a CSV file
Con.unwrap(IVoltDBConnection.class).saveStatistics(stats, config.statsfile);
Con.close();
// ---------------------------------------------------------------------------------------------------------------------------------------------------
} catch (Exception x) {
System.out.println("Exception: " + x);
x.printStackTrace();
}
}
Aggregations