Skip to content

Instantly share code, notes, and snippets.

@saidinesh5
Created February 19, 2012 23:29
Show Gist options
  • Save saidinesh5/1866475 to your computer and use it in GitHub Desktop.
Save saidinesh5/1866475 to your computer and use it in GitHub Desktop.
A simple benchmark for node-mongoskin
mongoskin = require 'mongoskin'
server = 'localhost'
db = 'foobar'
timeElapsed = 0
timeLimit = 10 #total time the benchmark should run in seconds
docsRetrieved = { 0 : 0 }
ids = []
console.log ''
console.log "============================================================== "
console.log " Mongoskin Benchmark"
console.log "_________________~~~~~~~~~~~~~~~~~~~~~~~______________________ "
console.log ''
db = mongoskin.db("#{server}/#{db}")
db.collection('apps').find {}, (err, docs) ->
# collecting all the valid ids that one can request from the db
if docs
docs.toArray (err, docList)->
if not err? and docList?
i = 0
n_adunits = docList.length
for doc in docList
ids.push(doc._id)
setTimeout(checkPoint,1000)
process.nextTick(randomRequest)
else
console.log err, "Error Processing Results"
else
console.log err,"No results"
randomRequest = ()->
db.collection('apps').findOne {"_id":ids[Math.floor(Math.random()*ids.length)]}, (err,docs) ->
docsRetrieved[timeElapsed]++
process.nextTick(randomRequest)
checkPoint = ()->
console.log "Documents Retrieved from #{timeElapsed}s - #{timeElapsed+1}s = ",docsRetrieved[timeElapsed]
if(timeElapsed + 1 < timeLimit)
timeElapsed += 1
docsRetrieved[timeElapsed] = 0
setTimeout(checkPoint,1000)
else
totalDocs = 0
for key,value of docsRetrieved
totalDocs += value
console.log "============================================================== "
console.log " Total docs retrieved in #{timeLimit}s = #{totalDocs}"
console.log "______________________________________________________________ "
console.log ''
process.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment