[英]Production Elixir/Phoenix app hogs CPU
I have an Elixir/Phoenix running in production and after a while one of the beam.smp processes goes to 100% CPU load (sometimes more than one process). 我有一个Elixir / Phoenix在生产中运行,一段时间后,其中一个beam.smp进程进入100%CPU负载(有时多于一个进程)。 I'm not aware of any trigger causing this.
我不知道任何引发这种情况的触发器。 How can I find out what's happening?
我怎样才能知道发生了什么?
EDIT: 编辑:
I ran iex on the server and connected to the Phoenix node. 我在服务器上运行iex并连接到Phoenix节点。 Than I ran etop and got this output:
比我运行etop并获得此输出:
Load: cpu 100 Memory: total 69429 binary 10568
procs 303 processes 16656 code 20194
runq 1 atom 727 ets 7205
Pid Name or Initial Func Time Reds Memory MsgQ Current Function
----------------------------------------------------------------------------------------
<19947.645.0> cowboy_protocol:init '-'90164000 88736 0 'Elixir.MyApp.Error
<19947.902.0> cowboy_protocol:init '-'88696000 88744 0 'Elixir.MyApp.Error
<19947.242.0> 'Elixir.Redix.Connec '-' 11697 24704 0 gen_server:loop/6
<19947.240.0> Elixir.Exq '-' 10284 24664 0 gen_server:loop/6
<19947.236.0> Elixir.Exq.Redis.Cli '-' 9597 34520 0 gen_server:loop/6
<19947.1695.0> etop_txt:init/1 '-' 6258 230504 0 etop:update/1
<19947.245.0> Elixir.Exq.Scheduler '-' 4831 24664 0 gen_server:loop/6
<19947.241.0> 'Elixir.Redix.Connec '-' 2339 8856 0 gen_server:loop/6
<19947.426.0> Elixir.MyApp.Presen '-' 262 143160 0 gen_server:loop/6
<19947.238.0> Elixir.Exq.Stats '-' 105 42344 0 gen_server:loop/6
========================================================================================
Those two cowboy_protocol:init
entries causing the problem. 那两个
cowboy_protocol:init
条目导致了这个问题。 But why ... and how can I stop/prevent/debug it? 但为什么......以及如何停止/预防/调试它?
Processes started with cowboy_protocol:init
are the processes that handle HTTP requests. 从
cowboy_protocol:init
开始的进程cowboy_protocol:init
是处理HTTP请求的进程。 The high reduction count would suggests they are stuck in some kind of infinite loop - both processes seem to be executing the same function - there's extremely high chance this function is faulty. 高减少计数表明它们陷入某种无限循环 - 两个进程似乎都在执行相同的功能 - 这个函数出错的可能性极高。
An infinite loop in tail position doesn't consume any additional memory - only CPU. 尾部位置的无限循环不消耗任何额外的内存 - 仅CPU。 This is very much a feature - and exactly how a GenServer works - an infinite loop in tail position, so the compiler (or runtime) have no way of distinguishing between faulty and correct code that uses this pattern.
这是一个非常重要的功能 - 以及GenServer的工作方式 - 尾部位置的无限循环,因此编译器(或运行时)无法区分使用此模式的错误代码和正确代码。
This is also very much a tribute to the praised "fault tolerance" of Erlang/Elixir - even though there exists an infinite loop in one branch of the program, the rest functions completely normally, timely responding to requests. 这也是对Erlang / Elixir称赞的“容错”的致敬 - 即使在程序的一个分支中存在无限循环,其余功能完全正常,及时响应请求。 Very few platforms are able to do that.
很少有平台能够做到这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.