From d1e18d82aa2c237678123b886e8b219876c2139f Mon Sep 17 00:00:00 2001 From: James Allen Date: Wed, 26 Feb 2014 17:35:10 +0000 Subject: [PATCH] Add simple benchmark script --- services/track-changes/benchmark.coffee | 56 +++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 services/track-changes/benchmark.coffee diff --git a/services/track-changes/benchmark.coffee b/services/track-changes/benchmark.coffee new file mode 100644 index 0000000000..7ed9cd81e7 --- /dev/null +++ b/services/track-changes/benchmark.coffee @@ -0,0 +1,56 @@ +request = require "request" +rclient = require("redis").createClient() +async = require "async" +{ObjectId} = require("./app/js/mongojs") + +NO_OF_DOCS = 100 +NO_OF_UPDATES = 200 + +user_id = ObjectId().toString() + +updates = for i in [1..NO_OF_UPDATES] + { + op: { i: "a", p: 0 } + v: i + meta: ts: new Date(), user_id: user_id + } +jsonUpdates = (JSON.stringify(u) for u in updates) + +doc_ids = (ObjectId().toString() for i in [1..NO_OF_DOCS]) + +populateRedis = (callback = (error) ->) -> + console.log "Populating Redis queues..." + + jobs = [] + for doc_id in doc_ids + do (doc_id) -> + jobs.push (callback) -> + rclient.rpush "UncompressedHistoryOps:#{doc_id}", jsonUpdates..., callback + async.series jobs, (error) -> + return callback(error) if error? + console.log "Done." + callback() + +flushDocs = (callback = (error) ->) -> + console.log "Flushing docs..." + inProgress = 0 + jobs = [] + for doc_id in doc_ids + do (doc_id) -> + jobs.push (callback) -> + inProgress = inProgress + 1 + request.post "http://localhost:3014/doc/#{doc_id}/flush", (error) -> + inProgress = inProgress - 1 + console.log Date.now(), "In progress: #{inProgress}" + callback(error) + async.parallel jobs, (error) -> + return callback(error) if error? + console.log "Done." + callback() + +populateRedis (error) -> + throw error if error? + flushDocs (error) -> + throw error if error? + process.exit(0) +