I have the following code snippet
var express = require('express'); var routes = require('./routes'); var http = require('http'); ... app.get('/a',function(){ Card.findCards(function(err, result){
I find that when I am on localhost / a, it takes about 2.3 seconds to complete. This is not surprising, since it extracts quite a lot of data from the database. However, I found that if I get / b at boot time / b, b will not be displayed. It is as if calling / a blocked the call to / b.
Is this how the express should work? I have always worked on the assumption that individual routes are asynchronous as they accept callbacks, but it seems that express can only process one request at a time. Prior to calling res.end (), no other request is processed. Am I missing any configuration I need to do?
For reference, here is how I connect to mongoose
mongoose.connect(dbConnectionString, {server:{poolSize:25}});
And this is my part of initializing the http server
http.globalAent.maxSockets = 20; // or whatever http.createServer(app).listen(app.get('port'), function(){ console.log('Express server listening on port ' + app.get('port')); });
EDIT: Here is the code for the map model and its associated circuits + functions
//Card.js var mongoose = require('mongoose') , Schema = mongoose.Schema; var CardSchema = new Schema({ _id : {type: String}, stores : [{ store: {type: Schema.Types.ObjectId, ref:'StoreModel', required: true} , points: {type: Number, required: true} }] }); exports.findCards = function(callback){ var query = Card.find({}, callback); }