Skip to content

Instantly share code, notes, and snippets.

@ermouth
Last active September 25, 2015 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ermouth/8b89c908496844cbb9ba to your computer and use it in GitHub Desktop.
Save ermouth/8b89c908496844cbb9ba to your computer and use it in GitHub Desktop.
CouchDB query server js call penalties
// Tests process switching penalties for calling
// CouchDB query server js functions.
// Requires jQuery
var passes = 50, host="https://cloudwall.cloudant.com/testr/";
function go (msg, url) {
var pi = $.Deferred(),
ctr = passes,
acc = [];
(function chain () {
var t=Date.now();
$.ajax({ url:host+url, dataType:"text", cache:false })
.always(function(){
acc.push(Date.now()-t);
if (--ctr) chain();
else {
console.log(msg, acc.reduce(function(a,b){return a+b},0) / acc.length);
pi.resolve();
}
});
})();
return pi.promise();
}
function cgo (msg, url) {return function(){return go(msg,url);}}
go ("Req to file", "_design/testr/testr.json")
.then(cgo("Req to view", "_design/testr/_view/testr"))
.then(cgo("View through list", "_design/testr/_list/testr/testr"))
.then(cgo("View through rewrite","_design/testr/_rewrite/x/testr"));
/*
//Run in parallel
go("Req to file", "_design/testr/testr.json");
go("Req to view", "_design/testr/_view/testr");
go("View through list", "_design/testr/_list/testr/testr");
go("View through rewrite", "_design/testr/_rewrite/x/testr");
*/
/*
Design document json:
{
"_id": "_design/testr",
"name": "Test _list switch penalties",
"lists": {
"testr": "function (head,req) {\n\t\tstart({\theaders: {'Content-Type': 'application/json'}});\n\t\tsend('{\"total_rows\":0,\"offset\":0,\"rows\":[\\n\\n]}\\n');\n\t}"
},
"views": {
"testr": {
"map": "function (doc) {\n\t\t\temit (doc._id, null);\n\t\t}"
}
},
"rewrites": [
{
"from": "/x/*",
"to": "../../_design/testr/_view/*"
}
],
"_attachments": {
"testr.json": {
"content_type": "application/json",
"data": "eyJ0b3RhbF9yb3dzIjowLCJvZmZzZXQiOjAsInJvd3MiOlsKCl19"
}
}
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment