Created
September 22, 2012 12:34
-
-
Save simong/3766057 to your computer and use it in GitHub Desktop.
Helenus test
This file contains hidden or 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
| var helenus = require('helenus'), | |
| pool = new helenus.ConnectionPool({ | |
| hosts : ['localhost:9160'], | |
| keyspace : 'oae', | |
| user : '', | |
| password : '', | |
| timeout : 3000 | |
| }); | |
| pool.on('error', function(err){ | |
| console.error(err.name, err.message); | |
| }); | |
| /** | |
| * 1/3 of the queries will be WRITE. | |
| */ | |
| var doSomething = function() { | |
| if (queries % 3 === 0) { | |
| pool.cql("UPDATE Principals SET firstName = ? WHERE principal_id = ?", ['Johnny Bravo', 'beefcake'], function(err, rows) { | |
| trackSomething(err); | |
| }); | |
| } else { | |
| pool.cql("SELECT firstName FROM Principals WHERE principal_id = ?", ['beefcake'], function(err, rows) { | |
| trackSomething(err); | |
| }); | |
| } | |
| }; | |
| var trackSomething = function(err) { | |
| queries++; | |
| if (err) { | |
| console.log(err); | |
| badQueries++; | |
| } | |
| if (queries === TOTAL_QUERIES) { | |
| console.timeEnd('connections'); | |
| console.log('Total queries: %d of which %d were bad.', queries, badQueries); | |
| } | |
| }; | |
| var TOTAL_QUERIES = 100000; | |
| var queries = 0; | |
| var badQueries = 0; | |
| pool.connect(function(err, keyspace) { | |
| if (err) { | |
| throw(err); | |
| } else { | |
| console.time('connections'); | |
| for (var i = 0; i < TOTAL_QUERIES; i++) { | |
| doSomething(); | |
| } | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment