Nodejs performance optimization

回眸只為那壹抹淺笑 提交于 2019-12-10 23:28:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!