问题
I am new to performance optimization, and while I recognize nodejs may not be the most beginner friendly place to start, it's the task at hand.
The observation: simple JSON API requests take in the order of hundreds of milliseconds on a staging server with no load and <10 users in the database. Particularly, the call to /api/get_user is taking ~300ms
to execute this code:
exports.get_user = function(req, res) {
return res.json(req.user)
}
(Note: we store our sessions in Redis)
The stack:
- Nodejs
- Express
- Redis
- Mongo
Where do I start?
回答1:
While it might be an overkill for this small scenario, you might want to consider profiling. I found the nodetime.com service quite useful.
回答2:
Passing the –-nouse_idle_notification
flag will tell V8 to ignore idle notification calls from Node, which are requests to V8 asking it to run GC immediately, as the Node process is currently idle. Because Node is aggressive with these calls (efficiency breeds clean slates), an excess of GC may slow down your application. Note that using this flag does not disable GC; GC simply runs less often. In the right circumstances this technique can increase performance.
来源:https://stackoverflow.com/questions/20694573/nodejs-performance-optimization