-
-
Save pontiyaraja/6ccbc4f4636187d21b1f09b4deea73d3 to your computer and use it in GitHub Desktop.
Redis Pipelines and Transactions
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
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"); |
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
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"); |
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
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"); |
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
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)); | |
} |
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
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