Reputation: 13986
I have a really simple nodeJS app. For some reason, the response times of the server vary greatly.
Here's my app.js:
var express = require('express');
var http = require('http');
var path = require('path');
var Models = require('./schema/schema.js');
var app = express();
// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.json());
app.use(express.urlencoded());
app.use(express.static(path.join(__dirname, 'public')));
app.use(function(req, res, next) {
var start = Date.now();
res.on('header', function() {
var duration = Date.now() - start;
var time = Date.now() - req.start;
fs.appendFile("times.txt", time+"\n", function (err) {});
});
next();
});
app.use(app.router);
app.get("/tags", function(req, res) {
var query = Models.Tag.find({}).sort({'popularity': -1}).limit(200);
query.exec(function(err, tags) {
res.status(200);
res.send(tags);
});
}
The data is always returned correctly, but here are my response times, as measured by the 'header' function:
19
11
13
6
10
10
8
9
2
62449
57862
24919
9975
11
17
21116
10
3
2
2
13
Most are less than 10 ms, but frequently there are some more than a minute. What is going on?
Schema:
var tagSchema = new mongoose.Schema({
name : {
type: String,
trim: true
},
popularity :{
type:Number, default:0
},
created_date: {
type:Date, default:Date.now
},
last_update: {
type:Date, default:Date.now
}
});
Upvotes: 7
Views: 583
Reputation: 1780
Have you tried using a hosted mongo server, like mongohq, just to see if it's a local IO latency issue? A database that small shouldn't have ANY problems, unless you're doing something crazy, which you're clearly not.
Upvotes: 1