Created
February 19, 2014 18:28
-
-
Save pcmanus/9098347 to your computer and use it in GitHub Desktop.
Simplistic benchmark for CASSANDRA-6737
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package batchInsertTest; | |
import com.datastax.driver.core.*; | |
public class BatchInsertTest { | |
public static void main(String[] args) throws Exception { | |
int RUN = 20; | |
int PER_BATCH_INSERTS = 10000; | |
Cluster c = Cluster.builder().addContactPoint("127.0.0.1").build(); | |
Session s = c.connect(); | |
s.execute("CREATE KEYSPACE IF NOT EXISTS ks WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }"); | |
s.execute("CREATE TABLE IF NOT EXISTS ks.test (p int, k int, v int, PRIMARY KEY (p, k))"); | |
PreparedStatement insertion = s.prepare("INSERT INTO ks.test (p, k, v) VALUES (?, ?, ?)"); | |
long[] runs = new long[RUN]; | |
long begin = System.nanoTime(); | |
for (int p = 0; p < RUN; p++) { | |
BatchStatement batch = new BatchStatement(); | |
for (int i = 0; i < PER_BATCH_INSERTS; i++) | |
batch.add(insertion.bind(p, i, i)); | |
long start = System.nanoTime(); | |
s.execute(batch); | |
runs[p] = System.nanoTime() - start; | |
} | |
long full = System.nanoTime() - begin; | |
System.out.println("Total time: " + format(full)); | |
System.out.println(); | |
for (int k = 0; k < RUN; k++) | |
System.out.printf("Run %d : %s\n", k, format(runs[k])); | |
c.shutdown(); | |
} | |
private static String format(long duration) { | |
return String.format("%16.1fms", ((double)duration / (1000d * 1000d))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment