Skip to content

Instantly share code, notes, and snippets.

@simong
Created September 22, 2012 12:34
Show Gist options
  • Select an option

  • Save simong/3766057 to your computer and use it in GitHub Desktop.

Select an option

Save simong/3766057 to your computer and use it in GitHub Desktop.
Helenus test
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