流星节点进程CPU使用率接近100% [英] Meteor Node Process CPU Usage Nears 100%

查看:75
本文介绍了流星节点进程CPU使用率接近100%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当Meteor应用达到峰值流量时,我遇到了麻烦(请注意,这没什么,每天访问1000次,也许一天有2500次网页浏览). CPU使用率会激增并且永远不会恢复,因此我开始使用Nodetime监视使用率,并且一直在重新加载进程(forever restart)以使一切恢复正常.

I'm having trouble with my Meteor app when it gets to its peak amount of traffic (peak for this is nothing, 1k visits, maybe 2,500 pageviews in a day). CPU usage spikes and never recovers, so I've taken to using Nodetime to monitor usage and I've been reloading the process (forever restart) to get things back to normal.

我对配置文件还很陌生,因此找到根本原因使我无所适从.我相当确定它与我的应用程序的服务器代码有关,但是性能分析似乎将Fibers模块指向热点",据我了解,它有助于使服务器代码同步.

I'm fairly new to profiling, so finding the underlying cause has me at a loss for where to start. I'm fairly certain it has to do with my app's server code, but the profiling seems to point to the Fibers module as a "hotspot" which I understand aids in making my server code synchronous.

以下是分析结果的摘要.我希望有人可以引导我朝着正确的方向进行故障排除!

Below is a snippet from the profiling results. I hope someone can guide me in the right direction in troubleshooting this!

推荐答案

虽然我对您的问题没有特定的答案,但是我有处理生产流星应用程序的CPU问题的经验,因此我可以给您一个列表要调查的事情.

While I don't have a specific answer to your question, I have experience dealing with CPU issues for our production meteor app for so I can give you a list of things to investigate.

  1. 升级到最新版本的流星和相应的节点版本(请参见

  1. Upgrade to the latest version of meteor and the appropriate node version (see the changelog). As of this writing that's meteor 0.8.2 and node 0.10.28.

阅读

Read this and this article. The latter makes a great point that you really should always try to delay activation of subscriptions until you need them. In particular you may not need to publish anything for users who are not logged in. In my experience, meteor CPU problems have everything to do with subscriptions.

请小心使用observeobserveChanges.这些都是昂贵,并且容易滥用.特别是:

Be careful with observe and observeChanges. These are expensive and are easy to abuse. In particular:

  • Make sure you are calling stop() on your handles when they are no longer needed (consider using a package like publish-with-relations so this is done for you).
  • Fetch only the collections and fields that you absolutely need. Observe works by continually diffing objects (requires lots of CPU). The fewer and smaller objects you have, the less there is to compute.

smart-collections 之前考虑使用 smart-collections href ="http://meteorhacks.com/retiring-smart-collections.html" rel ="noreferrer">已退休. 使用 oplog拖尾-这可以使一个晚上和应用中的性能和CPU使用情况之间的日差.

Consider using smart-collections before it is retired. Use oplog tailing - this can make for a night and day difference in performance and CPU usage in your app.

请考虑使某些事情不起作用(在以上文章中也提到过).对我们来说,这是一个巨大的胜利.我们有一个非常昂贵的联接,该联接在站点上两个经常访问的页面上使用.当达到大约每30分钟将CPU固定为100%的程度时,我放弃了该元素的反应性,只是在服务器上进行了连接,并通过方法调用将数据发送给了客户端.我还为这些结果创建了一个服务器端过期缓存,并按用户存储了它们(特别感谢Matt DeBergalis的建议).

Consider making some things not reactive (also mentioned in the articles above). For us that was a big win. We had one extremely expensive join that was used on two frequently accessed pages on the site. When it got to the point where the CPU was pegged at 100% about every 30 minutes I gave up on reactivity for that element and just did the join on the server and shipped the data to the client via a method call. I also created a server-side expiring cache for these results and stored them by user (special thanks to Matt DeBergalis for this suggestion).

每晚进行一次预防性重启.我有一份cron作业,告诉forever每天半夜重新启动我们的应用程序.这会使CPU从约10%下降到1%.这似乎是不可思议的事情,但是在重置后CPU使用率发生变化的事实使我相信这是个好主意.

Do a preventative nightly restart. I have a cron job that tells forever to restart our app once a day in the middle of the night. That brings the CPU down from ~10% to 1%. This seems like black magic, but the fact that the CPU usage changes after a reset leads me to believe this is a good idea.

更新后的想法(1/13/14)

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆