Skip to content

Commit

Permalink
Rework perf tests to not re-run binary tests
Browse files Browse the repository at this point in the history
Also increase HTTP/2 max_frame_size_sent for better performance.
  • Loading branch information
essen committed Jan 8, 2025
1 parent f4e23b4 commit 593a6fb
Showing 1 changed file with 55 additions and 82 deletions.
137 changes: 55 additions & 82 deletions test/ws_perf_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
%% ct.

all() ->
[{group, ascii}, {group, mixed}, {group, japanese}].
[{group, binary}, {group, ascii}, {group, mixed}, {group, japanese}].

groups() ->
CommonGroups = cowboy_test:common_groups(ct_helper:all(?MODULE), no_parallel),
SubGroups = [G || G = {GN, _, _} <- CommonGroups,
GN =:= http orelse GN =:= h2c],
[
{binary, [], SubGroups},
{ascii, [], SubGroups},
{mixed, [], SubGroups},
{japanese, [], SubGroups}
Expand All @@ -46,18 +47,18 @@ end_per_suite(_Config) ->

init_per_group(Name=http, Config) ->
ct:pal("Websocket over cleartext HTTP/1.1 (~s)",
[config(text_data_filename, Config)]),
[init_data_info(Config)]),
cowboy_test:init_http(Name, #{
env => #{dispatch => init_dispatch(Config)}
}, [{flavor, vanilla}|Config]);
init_per_group(Name=h2c, Config) ->
ct:pal("Websocket over cleartext HTTP/2 (~s)",
[config(text_data_filename, Config)]),
[init_data_info(Config)]),
Config1 = cowboy_test:init_http(Name, #{
connection_window_margin_size => 64*1024,
enable_connect_protocol => true,
env => #{dispatch => init_dispatch(Config)},
max_frame_size_sent => 8*1024,
max_frame_size_sent => 64*1024,
max_frame_size_received => 16384 * 1024 - 1,
stream_window_data_threshold => 1024,
stream_window_margin_size => 64*1024
Expand All @@ -68,11 +69,23 @@ init_per_group(ascii, Config) ->
init_per_group(mixed, Config) ->
init_text_data("grok_segond.txt", Config);
init_per_group(japanese, Config) ->
init_text_data("japanese.txt", Config).
init_text_data("japanese.txt", Config);
init_per_group(binary, Config) ->
[{frame_type, binary}|Config].

init_data_info(Config) ->
case config(frame_type, Config) of
text -> config(text_data_filename, Config);
binary -> binary
end.

init_text_data(Filename, Config) ->
{ok, Text} = file:read_file(filename:join(config(data_dir, Config), Filename)),
[{text_data, Text}, {text_data_filename, Filename}|Config].
[
{frame_type, text},
{text_data, Text},
{text_data_filename, Filename}
|Config].

end_per_group(Name, _Config) ->
cowboy_test:stop_group(Name).
Expand All @@ -91,7 +104,7 @@ init_dispatch(_Config) ->
do_gun_open_ws(Config) ->
ConnPid = gun_open(Config, #{http2_opts => #{
connection_window_margin_size => 64*1024,
max_frame_size_sent => 8*1024,
max_frame_size_sent => 64*1024,
max_frame_size_received => 16384 * 1024 - 1,
notify_settings_changed => true,
stream_window_data_threshold => 1024,
Expand Down Expand Up @@ -125,94 +138,54 @@ receive_ws(ConnPid, StreamRef) ->

%% Tests.

one_binary_00064KiB(Config) ->
doc("Send and receive a 64KiB binary frame."),
do_full(Config, one, 1, binary, 64 * 1024).
one_00064KiB(Config) ->
doc("Send and receive a 64KiB frame."),
do_full(Config, one, 1, 64 * 1024).

one_binary_00256KiB(Config) ->
doc("Send and receive a 256KiB binary frame."),
do_full(Config, one, 1, binary, 256 * 1024).
one_00256KiB(Config) ->
doc("Send and receive a 256KiB frame."),
do_full(Config, one, 1, 256 * 1024).

one_binary_01024KiB(Config) ->
doc("Send and receive a 1024KiB binary frame."),
do_full(Config, one, 1, binary, 1024 * 1024).
one_01024KiB(Config) ->
doc("Send and receive a 1024KiB frame."),
do_full(Config, one, 1, 1024 * 1024).

one_binary_04096KiB(Config) ->
doc("Send and receive a 4096KiB binary frame."),
do_full(Config, one, 1, binary, 4096 * 1024).
one_04096KiB(Config) ->
doc("Send and receive a 4096KiB frame."),
do_full(Config, one, 1, 4096 * 1024).

%% Minus one because frames can only get so big.
one_binary_16384KiB(Config) ->
doc("Send and receive a 16384KiB - 1 binary frame."),
do_full(Config, one, 1, binary, 16384 * 1024 - 1).

one_text_00064KiB(Config) ->
doc("Send and receive a 64KiB text frame."),
do_full(Config, one, 1, text, 64 * 1024).

one_text_00256KiB(Config) ->
doc("Send and receive a 256KiB text frame."),
do_full(Config, one, 1, text, 256 * 1024).

one_text_01024KiB(Config) ->
doc("Send and receive a 1024KiB text frame."),
do_full(Config, one, 1, text, 1024 * 1024).

one_text_04096KiB(Config) ->
doc("Send and receive a 4096KiB text frame."),
do_full(Config, one, 1, text, 4096 * 1024).

%% Minus one because frames can only get so big.
one_text_16384KiB(Config) ->
doc("Send and receive a 16384KiB - 1 text frame."),
do_full(Config, one, 1, text, 16384 * 1024 - 1).

repeat_binary_00000B(Config) ->
doc("Send and receive a 0B binary frame 1000 times."),
do_full(Config, repeat, 1000, binary, 0).

repeat_binary_00256B(Config) ->
doc("Send and receive a 256B binary frame 1000 times."),
do_full(Config, repeat, 1000, binary, 256).

repeat_binary_01024B(Config) ->
doc("Send and receive a 1024B binary frame 1000 times."),
do_full(Config, repeat, 1000, binary, 1024).

repeat_binary_04096B(Config) ->
doc("Send and receive a 4096B binary frame 1000 times."),
do_full(Config, repeat, 1000, binary, 4096).

repeat_binary_16384B(Config) ->
doc("Send and receive a 16384B binary frame 1000 times."),
do_full(Config, repeat, 1000, binary, 16384).
one_16384KiB(Config) ->
doc("Send and receive a 16384KiB - 1 frame."),
do_full(Config, one, 1, 16384 * 1024 - 1).

repeat_text_00000B(Config) ->
doc("Send and receive a 0B text frame 1000 times."),
do_full(Config, repeat, 1000, text, 0).
repeat_00000B(Config) ->
doc("Send and receive a 0B frame 1000 times."),
do_full(Config, repeat, 1000, 0).

repeat_text_00256B(Config) ->
doc("Send and receive a 256B text frame 1000 times."),
do_full(Config, repeat, 1000, text, 256).
repeat_00256B(Config) ->
doc("Send and receive a 256B frame 1000 times."),
do_full(Config, repeat, 1000, 256).

repeat_text_01024B(Config) ->
doc("Send and receive a 1024B text frame 1000 times."),
do_full(Config, repeat, 1000, text, 1024).
repeat_01024B(Config) ->
doc("Send and receive a 1024B frame 1000 times."),
do_full(Config, repeat, 1000, 1024).

repeat_text_04096B(Config) ->
doc("Send and receive a 4096B text frame 1000 times."),
do_full(Config, repeat, 1000, text, 4096).
repeat_04096B(Config) ->
doc("Send and receive a 4096B frame 1000 times."),
do_full(Config, repeat, 1000, 4096).

repeat_text_16384B(Config) ->
doc("Send and receive a 16384B text frame 1000 times."),
do_full(Config, repeat, 1000, text, 16384).
repeat_16384B(Config) ->
doc("Send and receive a 16384B frame 1000 times."),
do_full(Config, repeat, 1000, 16384).

%repeat_text_16384B_10K(Config) ->
% doc("Send and receive a 16384B text frame 10000 times."),
% do_full(Config, repeat, 10000, text, 16384).
%repeat_16384B_10K(Config) ->
% doc("Send and receive a 16384B frame 10000 times."),
% do_full(Config, repeat, 10000, 16384).

do_full(Config, What, Num, FrameType, FrameSize) ->
do_full(Config, What, Num, FrameSize) ->
{ok, ConnPid, StreamRef} = do_gun_open_ws(Config),
FrameType = config(frame_type, Config),
FrameData = case FrameType of
text -> do_text_data(Config, FrameSize);
binary -> rand:bytes(FrameSize)
Expand Down

0 comments on commit 593a6fb

Please sign in to comment.