Skip to content

Instantly share code, notes, and snippets.

@tareqabedrabbo
Created May 3, 2011 20:59
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save tareqabedrabbo/954224 to your computer and use it in GitHub Desktop.
Save tareqabedrabbo/954224 to your computer and use it in GitHub Desktop.
Redis Pipelines and Transactions
Pipeline pipeline = jedis.pipelined();
long start = System.currentTimeMillis();
for (int i = 0; i < 100000; i++) {
pipeline.set("" + i, "" + i);
}
List<Object> results = pipeline.execute();
long end = System.currentTimeMillis();
System.out.println("Pipelined SET: " + ((end - start)/1000.0) + " seconds");
long start = System.currentTimeMillis();
Pipeline pipeline = jedis.pipelined();
pipeline.multi();
for (int i = 0; i < 100000; i++) {
pipeline.set("" + i, "" + i);
}
pipeline.exec();
List<Object> results = pipeline.execute();
long end = System.currentTimeMillis();
System.out.println("Pipelined transaction: " + ((end - start)/1000.0) + " seconds");
long start = System.currentTimeMillis();
for (int i = 0; i < 100000; i++) {
String result = jedis.set("" + i, "" + i);
}
long end = System.currentTimeMillis();
System.out.println("Simple SET: " + ((end - start)/1000.0) + " seconds");
public void pipelinedVsSimpleTransactions() {
for (int i = 1; i <= 50; i++) {
runTest(i);
System.out.println();
}
}
private void runTest(int n) {
long startSimple = System.currentTimeMillis();
Transaction tx = jedis.multi();
for (int i = 0; i < n; i++) {
tx.set("" + i, "" + i);
}
List<Object> txResult = tx.exec();
long endSimple = System.currentTimeMillis();
long simpleDiff = endSimple - startSimple;
System.out.println(n + " Simple transactions: " + simpleDiff + " milli seconds");
long startPipelined = System.currentTimeMillis();
Pipeline pipeline = jedis.pipelined();
pipeline.multi();
for (int i = 0; i < n; i++) {
pipeline.set("" + i, "" + i);
}
pipeline.exec();
List<Object> pipelineResult = pipeline.execute();
long endPipelined = System.currentTimeMillis();
long pipelinedDiff = endPipelined - startPipelined;
System.out.println(n + " Pipelined transactions: " + pipelinedDiff + " milli seconds");
System.out.println("Simple - Pipelined = " + (simpleDiff - pipelinedDiff));
}
long start = System.currentTimeMillis();
Transaction tx = jedis.multi();
for (int i = 0; i < 100000; i++) {
tx.set("" + i, "" + i);
}
List<Object> results = tx.exec();
long end = System.currentTimeMillis();
System.out.println("Transaction SET: " + ((end - start)/1000.0) + " seconds");
@opit
Copy link

opit commented Jul 1, 2013

pipeline.execute() gave me a compile error with jedis 2.10
fork with some other modifications is here (added cleanup for deleting keys between tests):
https://gist.github.com/opit/5900187

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment