<span style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">Hi All,</span><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
<br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">Sorry that I'm an Erlang newbie and may make stupid question. But please help me to solve the issue.</div>
<div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif"><br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
I have written an Erlang server to replace the one I'm using with Node.js, which ate all my memory and I'm praying that Erlang could be a way out.</div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
The server works properly under unit test and internal testing, but face a high CPU usage in stress test.</div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
<br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">After trimming down, I found that the CPU burst was due to the TCP receive from clients.</div><blockquote style="color:rgb(34,34,34);font-size:13px;margin:0px 0px 0px 40px;font-family:arial,sans-serif;padding:0px;border:none">
<div><i>receiveClientPacket(Sock) -></i></div><div><i> inet:setopts(Sock, [{active, once}, {buffer, ?CLIENTHEARTBEATSIZE}]),</i></div><div><i> receive</i></div><div><i> {tcp, Sock, Data} -></i></div><div><i> {ok, Data}</i><i>;</i></div>
<div><i> {tcp_closed, Sock} -></i></div><div><i> {error, closed}</i></div><div><i> after ?CLIENTRECCEIVETIMEOUT -></i></div><div><i> {error, timeout}</i></div><div><i> end.</i></div></blockquote><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
<br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">I tried making the process sleep for 10 hours at the beginning of the function (to prevent it from calling receive), the CPU didn't burst at all.</div>
<div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">Therefore I conclude that the burst of CPU is due to TCP receive. (Please correct me if I made any mistake)</div>
<div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif"><br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
Here are information about my stress test:</div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif"><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
</blockquote><ol><li style="margin-left:15px">start the Erlang server with:</li><ol><li style="margin-left:15px">erl +zdbbl 2097151 -K true +A 128 +P 5000000</li></ol><li style="margin-left:15px">connect 5000 clients to the Erlang server</li>
<li style="margin-left:15px">each connected client sends a 2 byte data to the server every 1 min</li><li style="margin-left:15px">after all the connections is done, (i.e. only the 2 byte data per min are performing), the CPU burst to ~30%sy (from "top")</li>
</ol><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"></blockquote></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif"><br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
I'm using an Amazon Linux AMI (large instance, 64-bit) for the Erlang server. Is the burst due to the linux? As I have no idea how the system will use up the CPU. Or is it my poor code's problem? (I believe so...)</div>
<div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif"><br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
In real situation, our servers don't only receive ping pong, but also messages, which is a lot more loading... This is only the first step...</div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
<br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">Millions of thanks to anyone who can save me.</div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
<br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">Anita~*</div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
<br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">~~~~~~~~~~~~~~~~~~~~~~~</div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
<br></div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">Information about large instance (for reference):</div><div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
<span style="line-height:18px;font-size:12px;font-family:verdana,arial,helvetica,clean,sans-serif">7.5 GB memory</span><br style="line-height:18px;font-size:12px;font-family:verdana,arial,helvetica,clean,sans-serif"><span style="line-height:18px;font-size:12px;font-family:verdana,arial,helvetica,clean,sans-serif">4 EC2 Compute Units (2 virtual cores with 2 EC2 Compute Units each)</span><br style="line-height:18px;font-size:12px;font-family:verdana,arial,helvetica,clean,sans-serif">
<span style="line-height:18px;font-size:12px;font-family:verdana,arial,helvetica,clean,sans-serif">850 GB instance storage</span><br style="line-height:18px;font-size:12px;font-family:verdana,arial,helvetica,clean,sans-serif">
<span style="line-height:18px;font-size:12px;font-family:verdana,arial,helvetica,clean,sans-serif">64-bit platform</span><br style="line-height:18px;font-size:12px;font-family:verdana,arial,helvetica,clean,sans-serif"><span style="line-height:18px;font-size:12px;font-family:verdana,arial,helvetica,clean,sans-serif">I/O Performance: High</span></div>