播放框架的 CPU 负载

Posted

技术标签:

【中文标题】播放框架的 CPU 负载【英文标题】:CPU load with play framework 【发布时间】:2012-07-02 06:30:48 【问题描述】:

几天以来,在一个已经开发了大约一年的系统上,我一直在玩游戏的 CPU 负载!服务器。我有两台服务器,一台处于活动状态,一台作为热备件。过去,hot-spre 服务器显示没有负载,或者负载可以忽略不计。但现在它消耗恒定的 50-110% CPU(在 Linux 上使用 top)。

有没有简单的方法可以找出原因呢?调试时,我在 MacBook 上看不到这种行为(通常为 0.1-1%)。据我所知,这是最近几天才发生的。

这是热备件的状态打印。可以看出,除了计划任务(由于标志不在此服务器上执行,而是启动)之外,没有查询任何控制器:

~        _            _ 
~  _ __ | | __ _ _  _| |
~ | '_ \| |/ _' | || |_|
~ |  __/|_|\____|\__ (_)
~ |_|            |__/   
~
~ play! 1.2.4, http://www.playframework.org
~ framework ID is prod-frontend
~
~ Status from http://localhost:xxxx/@status,
~
Java:
~~~~~
Version: 1.6.0_26
Home: /usr/lib/jvm/java-6-sun-1.6.0.26/jre
Max memory: 64880640
Free memory: 11297896
Total memory: 29515776
Available processors: 2

Play framework:
~~~~~~~~~~~~~~~
Version: 1.2.4
Path: /opt/play
ID: prod-frontend
Mode: PROD
Tmp dir: /xxx/tmp

Application:
~~~~~~~~~~~~
Path: /xxx/server
Name: iDoms Server
Started at: 07/01/2012 12:05

Loaded modules:
~~~~~~~~~~~~~~
secure at /opt/play/modules/secure
paginate at /xxx/server/modules/paginate-0.14

Loaded plugins:
~~~~~~~~~~~~~~
0:play.CorePlugin [enabled]
100:play.data.parsing.TempFilePlugin [enabled]
200:play.data.validation.ValidationPlugin [enabled]
300:play.db.DBPlugin [enabled]
400:play.db.jpa.JPAPlugin [enabled]
450:play.db.Evolutions [enabled]
500:play.i18n.MessagesPlugin [enabled]
600:play.libs.WS [enabled]
700:play.jobs.JobsPlugin [enabled]
100000:play.plugins.ConfigurablePluginDisablingPlugin [enabled]

Threads:
~~~~~~~~
Thread[Reference Handler,10,system] WAITING
Thread[Finalizer,8,system] WAITING
Thread[Signal Dispatcher,9,system] RUNNABLE
Thread[net.sf.ehcache.CacheManager@449278d5,5,main] WAITING
Thread[Timer-0,5,main] TIMED_WAITING
Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0,5,main] TIMED_WAITING
Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1,5,main] TIMED_WAITING
Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,5,main] TIMED_WAITING
Thread[jobs-thread-1,5,main] TIMED_WAITING
Thread[jobs-thread-2,5,main] TIMED_WAITING
Thread[jobs-thread-3,5,main] TIMED_WAITING
Thread[New I/O server boss #1 ([id: 0x7065ec20, /0:0:0:0:0:0:0:0:9001]),5,main] RUNNABLE
Thread[DestroyJavaVM,5,main] RUNNABLE
Thread[New I/O server worker #1-3,5,main] RUNNABLE

Requests execution pool:
~~~~~~~~~~~~~~~~~~~~~~~~
Pool size: 0
Active count: 0
Scheduled task count: 0
Queue size: 0

Monitors:
~~~~~~~~
controllers.ReaderJob.doJob(), ms.         ->      114 hits;      4.1 avg;      0.0 min;    463.0 max;
controllers.MediaCoderProcess.doJob(), ms. ->     4572 hits;      0.1 avg;      0.0 min;    157.0 max;
controllers.Bootstrap.doJob(), ms.         ->        1 hits;      0.0 avg;      0.0 min;      0.0 max;

Datasource:
~~~~~~~~~~~
Jdbc url: jdbc:mysql://xxxx
Jdbc driver: com.mysql.jdbc.Driver
Jdbc user: xxxx
Jdbc password: xxxx
Min pool size: 1
Max pool size: 30
Initial pool size: 3
Checkout timeout: 5000

Jobs execution pool:
~~~~~~~~~~~~~~~~~~~
Pool size: 3
Active count: 0
Scheduled task count: 4689
Queue size: 3

Scheduled jobs (4):
~~~~~~~~~~~~~~~~~~~~~~~~~~
controllers.APNSFeedbackJob run every 24h. (has never run)
controllers.Bootstrap run at application start. (last run at 07/01/2012 12:05:32)
controllers.MediaCoderProcess run every 15s. (last run at 07/02/2012 07:10:46)
controllers.ReaderJob run every 600s. (last run at 07/02/2012 07:05:36)

Waiting jobs:
~~~~~~~~~~~~~~~~~~~~~~~~~~~
controllers.MediaCoderProcess will run in 2 seconds
controllers.APNSFeedbackJob will run in 17672 seconds
controllers.ReaderJob will run in 276 seconds

【问题讨论】:

你的服务器是Linux下的吗?您是否尝试重新启动服务器?因为你可能会被leap second linux 内核错误(it.slashdot.org/story/12/07/01/1920217/…)所击中 精准!重启后一切恢复正常。如果你愿意回答这个问题,那么我会接受这个答案。 【参考方案1】:

如果您的服务器在 Linux 下运行,您可能会被上周末出现的 Leap Second bug 击中。

这个 bug 会影响 Linux 内核(线程管理),所以使用线程的应用程序(如 JVM、mysql 等)可能会消耗大量 CPU。

【讨论】:

【参考方案2】:

如果您使用 jdk 1.7 应该很容易,因为他们添加了此功能,请查看我的其他相关答案 -> How to monitor the computer's cpu, memory, and disk usage in Java?

【讨论】:

以上是关于播放框架的 CPU 负载的主要内容,如果未能解决你的问题,请参考以下文章

转 Android视频播放软解与硬解的区别

播放框架@ValidateWithPayload

java cpu负载过高怎么解决

NAudio - 从 RTP 数据包播放音频有效负载

NEON、SSE 和交错负载与随机播放

没有声音播放时核心音频 CPU 使用率高