mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Avoid resetting Websocket idle_timeout timer too often
`perf` has shown that Cowboy spends a lot of time cancelling and starting this timer. Instead of resetting for every data received, we now only reset a field in the state. Before it was working like this: - start idle timeout timer - on trigger, close the connection - on data, cancel and start again Now it's working like this: - start idle timeout timer for a tenth of its duration, with tick number = 0 - on trigger, if tick number != 10 - start the timer again, again for a tenth of its duration - increment tick number - on trigger, if tick number = 10 - close the connection - on data, set tick number to 0
This commit is contained in:
parent
643b335ba8
commit
086f60cca4
3 changed files with 45 additions and 15 deletions
|
@ -37,6 +37,14 @@ groups() ->
|
|||
{japanese, [], SubGroups}
|
||||
].
|
||||
|
||||
init_per_suite(Config) ->
|
||||
%% Optionally enable `perf` for the current node.
|
||||
% spawn(fun() -> ct:pal(os:cmd("perf record -g -F 9999 -o /tmp/ws_perf.data -p " ++ os:getpid() ++ " -- sleep 11")) end),
|
||||
Config.
|
||||
|
||||
end_per_suite(_Config) ->
|
||||
ok.
|
||||
|
||||
init_per_group(Name=http, Config) ->
|
||||
ct:pal("Websocket over cleartext HTTP/1.1 (~s)",
|
||||
[init_data_info(Config)]),
|
||||
|
@ -185,6 +193,8 @@ do_full(Config, What, Num, FrameSize) ->
|
|||
text -> do_text_data(Config, FrameSize);
|
||||
binary -> rand:bytes(FrameSize)
|
||||
end,
|
||||
%% Heat up the processes before doing the real run.
|
||||
% do_full1(ConnPid, StreamRef, Num, FrameType, FrameData),
|
||||
{Time, _} = timer:tc(?MODULE, do_full1, [ConnPid, StreamRef, Num, FrameType, FrameData]),
|
||||
do_log("~-6s ~-6s ~6s: ~8bµs", [What, FrameType, do_format_size(FrameSize), Time]),
|
||||
gun:ws_send(ConnPid, StreamRef, close),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue