javascript - MongoDB query on node.js express becomes very slow under load testing -


i started doing load testing on node.js/express web app running mongodb. have particular page loaded hitting end point this:

app.get("/project/:pid", function(req, res) { // project.viewproject(db, req, res); project.viewprojectsimple(db, req, res); }); 

this in turn calls function show project page associated pid. have simplified as possible include single db query function still collapses under minor stress test.

here function renders project:

exports.viewprojectsimple = function(db, req, res) { console.time("project"); var pid = req.params["pid"]*1; console.time("1"); db.collection("projects").findone({pid:pid}, function(err, project) {     console.timeend("1");     if( !project )         res.send("no such project...");     else {         console.time("2");         project.user = {};         project.user.name = "test";         if( project.created )             project.nicecreateddate = utility.nicedate(project.created);         if( project.totaltime )             project.niceedittime = utility.nicetimedelta(project.totaltime);         console.timeend("2");         console.time("3");         if( !project.stats )             project.stats = getprojectstats(db, project);         var uid = req.user ? req.user.uid : -1;         if( project.description )             project.descriptionhtml = markdown.tohtml( project.description, 'gruber' );         console.timeend("3");         var renderproject = function() {             console.time("4");             var projectpath =  "public" + project.path;             var screenshotpath = projectpath + "/info/screenshot.png";             console.timeend("4");             console.timeend("project");             res.render("project", {                 title: "project: "+project.name,                 user: req.user,                 customscript: "projectpage.js",                 scripts: ['/js/bootstrap.min.js', '/js/bootbox.min.js'],                 stylesheets: [ '/js/bootstrap.min.css'],                 permissions: getpermissionshelper(req, project),                 project:project,                 message: req.flash("project")             });                      }             renderproject();             } });  } 

when running single user db query takes 10-15 seconds, here output timing calls:

1: 11ms 2: 0ms 3: 0ms 4: 0ms project: 12ms 

i have been running blaze meter stress test hits project page on , on 20 simulated users , when peaks @ 20 users performance collapses , takes 15 seconds complete query:

1: 14145ms 2: 0ms 3: 1ms 4: 0ms project: 14147ms 

the projects table has 31570 entries don't think issue. running on single amazon ec2 micro server single core , maxes out cpu during test.

can enlighten me going on here.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -