Nodejs性能优化 [英] Nodejs performance optimization
问题描述
我是性能优化的新手,虽然我认识到nodejs可能不是最适合初学者的地方,但这是手头的任务。
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.
观察:在没有负载且数据库中的用户少于10个的登台服务器上,简单的JSON API请求大约需要数百毫秒。特别是,对/ api / get_user的调用花费了大约300毫秒
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
来执行以下代码:
exports.get_user = function(req, res) {
return res.json(req.user)
}
(注意:我们将会话存储在Redis中)
(Note: we store our sessions in Redis)
堆栈:
- Nodejs
- Express
- Redis
- Mongo
- Nodejs
- Express
- Redis
- Mongo
我从哪里开始?
推荐答案
尽管对于这种小型方案而言,这可能是过大的选择,但您可能需要考虑进行概要分析。我发现nodetime.com服务非常有用。
While it might be an overkill for this small scenario, you might want to consider profiling. I found the nodetime.com service quite useful.
这篇关于Nodejs性能优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!