I have a really simple nodeJS application. For some reason, the server response time varies greatly.
Here is 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); }); }
Data is always returned correctly, but here is my response time 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 of them are less than 10 ms, but often they are more than a minute. What's happening?
Scheme:
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 } });
Jason
source share