Massive CPU usage after a certain point
mzealey opened this issue · 0 comments
mzealey commented
Once you pass a certain point (about 150k connections) in our tests, the CPU system percentage goes through the roof. This is because the kernel has to switch to some different port allocation algorithm which uses O(n) searching rather than efficient searching. Apologies this is a bit vague but I can't fully remember from a month or two back when we were doing this. However this all gets resolved by adding the IP_BIND_ADDRESS_NO_PORT
option to socket creation, then we can scale to a million tcp/xmpp connections per tsung box.
Rough patches as follows, although we did not fully test the SSL one:
diff --git a/src/tsung/ts_tcp.erl b/src/tsung/ts_tcp.erl
index 02ac470..37ac624 100644
--- a/src/tsung/ts_tcp.erl
+++ b/src/tsung/ts_tcp.erl
@@ -47,6 +48,7 @@ protocol_options(#proto_opts{tcp_rcv_size = Rcv, tcp_snd_size = Snd,
{reuseaddr, Reuseaddr},
{recbuf, Rcv},
{sndbuf, Snd},
+ {raw, 0, 24, <<1:32/native>>}, % IP_BIND_ADDRESS_NO_PORT - allow much better connection scaling to multiple remote IPs
{keepalive, true} %% FIXME: should be an option
].
%% -> {ok, Socket}
diff --git a/src/tsung/ts_ssl.erl b/src/tsung/ts_ssl.erl
index a0a7bde..0362168 100644
--- a/src/tsung/ts_ssl.erl
+++ b/src/tsung/ts_ssl.erl
@@ -42,7 +42,7 @@ connect(Socket, Opts) ->
connect(Socket, Opts, infinity).
-opts_to_tcp_opts(Opts) -> Opts.
+opts_to_tcp_opts(Opts) -> Opts ++ [{raw, 0, 24, <<1:32/native>>}].