Skip to content

Instantly share code, notes, and snippets.

@pontiyaraja
Forked from tareqabedrabbo/Pipelined SET.java
Created September 30, 2016 06:59
Show Gist options
  • Save pontiyaraja/6ccbc4f4636187d21b1f09b4deea73d3 to your computer and use it in GitHub Desktop.
Save pontiyaraja/6ccbc4f4636187d21b1f09b4deea73d3 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");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment