Permalink
Browse files

Log addData timing more specifically

  • Loading branch information...
1 parent 95b41fc commit 574de21d7545b0d3dbf5ec2d0242b3b58643926b @temas temas committed Mar 19, 2013
Showing with 22 additions and 4 deletions.
  1. +22 −4 lib/ijod.js
View
@@ -464,16 +464,19 @@ IJOD.prototype.abortAddTransaction = function(cbDone) {
};
// takes arg of at least an id and data, callback(err) when done
-IJOD.prototype.addData = function(arg, callback) {
+IJOD.prototype.addData = function(timings, arg, callback) {
if (!arg || !arg.idr) return callback("invalid arg");
var tmpJson = JSON.stringify(arg);
var hash = arg.hash ? arg.hash : mmh.murmur128HexSync(tmpJson);
delete arg.hash;
+ var start = Date.now();
// ENTRY NORMALIZATION HAPPENS HERE
if (!arg.at) arg.at = Date.now();
arg.id = idr.id(arg.idr);
arg.idr = idr.toString(arg.idr);
var ll = dMap.get('ll',arg.data,arg.idr) || [null,null];
+ timings["add-dMap"] += Date.now() - start;
+ start = Date.now();
// build our participant matching binary string
var par = null;
var participants = parget(arg);
@@ -509,10 +512,16 @@ IJOD.prototype.addData = function(arg, callback) {
} else {
qsql += ', ?';
}
+ timings["add-friends"] += Date.now() - start;
+ start = Date.now();
var self = this;
this.startAddTransaction();
tmpJson = JSON.stringify(arg);
+ timings["add-json-stringify"] += Date.now() - start;
+ start = Date.now();
var gzdata = zlib.compress(new Buffer(tmpJson+"\n"));
+ timings["add-zlib"] += Date.now() - start;
+ start = Date.now();
self.transactionItems.push(gzdata);
var offset = self.len;
self.len += gzdata.length;
@@ -574,7 +583,10 @@ IJOD.prototype.addData = function(arg, callback) {
]});
cb();
- }, callback);
+ }, function(err) {
+ timings["add-sql"] += Date.now() - start;
+ callback(err);
+ });
};
/// Get a single entry from an IJOD, requested by specific IDR
@@ -767,7 +779,13 @@ exports.batchSmartAdd = function(entries, callback) {
var ij = new IJOD(pidPath);
logger.debug("Batch smart add", pidPath, entries.length);
- var timings = {};
+ var timings = {
+ "add-dMap" : 0,
+ "add-friends" : 0,
+ "add-json-stringify" : 0,
+ "add-zlib" : 0,
+ "add-sql" : 0
+ };
function handleError(msg) {
logger.error("Batch smart add error: %s", msg);
if (exports.debug) {
@@ -812,7 +830,7 @@ exports.batchSmartAdd = function(entries, callback) {
}
}
// XXX This might be able to convert to a regular forEach?
- ij.addData(entry, function() { process.nextTick(cb); });
+ ij.addData(timings, entry, function() { process.nextTick(cb); });
}, function(error) {
timings.addData = Date.now() - start;
if (error) {

0 comments on commit 574de21

Please sign in to comment.