Skip to content

Commit 938844f

Browse files
committed
compare mint.websocket to gun
1 parent c485e9c commit 938844f

File tree

6 files changed

+7160
-1
lines changed

6 files changed

+7160
-1
lines changed

coveralls.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
"terminal_options": {
77
"file_column_width": 60
88
},
9-
"skip_files": ["^deps"]
9+
"skip_files": ["^deps", "^test/compare/"]
1010
}

mix.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ defmodule MintWebSocket.MixProject do
1515
version: @version,
1616
elixir: "~> 1.8",
1717
elixirc_paths: elixirc_paths(Mix.env()),
18+
erlc_paths: erlc_paths(Mix.env()),
1819
start_permanent: Mix.env() == :prod,
1920
deps: deps(),
2021
test_coverage: [tool: ExCoveralls],
@@ -52,6 +53,7 @@ defmodule MintWebSocket.MixProject do
5253
{:castore, ">= 0.0.0", only: [:dev]},
5354
{:jason, ">= 0.0.0", only: [:dev, :test]},
5455
{:cowboy, "~> 2.9", only: [:test]},
56+
{:gun, "== 2.0.0-rc.2", only: [:test]},
5557
{:credo, "~> 1.0", only: [:test], runtime: false},
5658
{:excoveralls, "~> 0.14", only: [:test]},
5759
{:bless, "~> 1.0", only: [:test]}
@@ -61,6 +63,9 @@ defmodule MintWebSocket.MixProject do
6163
defp elixirc_paths(:test), do: ["lib", "test/fixtures"]
6264
defp elixirc_paths(_), do: ["lib"]
6365

66+
defp erlc_paths(:test), do: ["src", "test/compare"]
67+
defp erlc_paths(_), do: ["src"]
68+
6469
defp package do
6570
[
6671
name: "mint_web_socket",

mix.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"ex_doc": {:hex, :ex_doc, "0.24.2", "e4c26603830c1a2286dae45f4412a4d1980e1e89dc779fcd0181ed1d5a05c8d9", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "e134e1d9e821b8d9e4244687fb2ace58d479b67b282de5158333b0d57c6fb7da"},
1111
"excoveralls": {:hex, :excoveralls, "0.14.0", "4b562d2acd87def01a3d1621e40037fdbf99f495ed3a8570dfcf1ab24e15f76d", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "94f17478b0cca020bcd85ce7eafea82d2856f7ed022be777734a2f864d36091a"},
1212
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
13+
"gun": {:hex, :gun, "2.0.0-rc.2", "7c489a32dedccb77b6e82d1f3c5a7dadfbfa004ec14e322cdb5e579c438632d2", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}], "hexpm", "6b9d1eae146410d727140dbf8b404b9631302ecc2066d1d12f22097ad7d254fc"},
1314
"hackney": {:hex, :hackney, "1.17.4", "99da4674592504d3fb0cfef0db84c3ba02b4508bae2dff8c0108baa0d6e0977c", [:rebar3], [{:certifi, "~>2.6.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~>6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~>1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~>1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "de16ff4996556c8548d512f4dbe22dd58a587bf3332e7fd362430a7ef3986b16"},
1415
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
1516
"jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},

test/compare/README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
## Comparisons
2+
3+
This directory is for comparing other WebSocket clients to Mint.
4+
5+
### Gun
6+
7+
After the merging of
8+
[#17](https://github.com/NFIBrokerage/mint_web_socket/pull/17),
9+
Mint.WebSocket is pretty comparable performance and conformance-wise to
10+
[`ninenines/gun`](https://github.com/ninenines/gun).
11+
12+
Here are the timings for the section 9 (limits/performance) cases of the
13+
Autobahn|Testsuite:
14+
15+
| Case no. | Mint.WebSocket (ms) | Gun (ms) |
16+
|----------|---------------------|----------|
17+
| 9.1.1 | 2 | 2 |
18+
| 9.1.2 | 6 | 6 |
19+
| 9.1.3 | 23 | 21 |
20+
| 9.1.4 | 126 | 83 |
21+
| 9.1.5 | 228 | 198 |
22+
| 9.1.6 | 731 | 378 |
23+
| 9.2.1 | 3 | 2 |
24+
| 9.2.2 | 16 | 5 |
25+
| 9.2.3 | 17 | 15 |
26+
| 9.2.4 | 79 | 58 |
27+
| 9.2.5 | 224 | 133 |
28+
| 9.2.6 | 638 | 272 |
29+
| 9.3.1 | 158 | 216 |
30+
| 9.3.2 | 104 | 116 |
31+
| 9.3.3 | 87 | 101 |
32+
| 9.3.4 | 85 | 79 |
33+
| 9.3.5 | 116 | 74 |
34+
| 9.3.6 | 98 | 89 |
35+
| 9.3.7 | 129 | 70 |
36+
| 9.3.8 | 82 | 74 |
37+
| 9.3.9 | 98 | 69 |
38+
| 9.4.1 | 192 | 180 |
39+
| 9.4.2 | 101 | 84 |
40+
| 9.4.3 | 80 | 62 |
41+
| 9.4.4 | 100 | 58 |
42+
| 9.4.5 | 63 | 63 |
43+
| 9.4.6 | 62 | 50 |
44+
| 9.4.7 | 62 | 49 |
45+
| 9.4.8 | 69 | 49 |
46+
| 9.4.9 | 74 | 47 |
47+
| 9.5.1 | 226 | 279 |
48+
| 9.5.2 | 130 | 145 |
49+
| 9.5.3 | 71 | 65 |
50+
| 9.5.4 | 64 | 44 |
51+
| 9.5.5 | 61 | 26 |
52+
| 9.5.6 | 49 | 21 |
53+
| 9.6.1 | 211 | 199 |
54+
| 9.6.2 | 123 | 123 |
55+
| 9.6.3 | 99 | 74 |
56+
| 9.6.4 | 45 | 60 |
57+
| 9.6.5 | 30 | 28 |
58+
| 9.6.6 | 31 | 19 |
59+
| 9.7.1 | 131 | 210 |
60+
| 9.7.2 | 569 | 138 |
61+
| 9.7.3 | 113 | 76 |
62+
| 9.7.4 | 113 | 135 |
63+
| 9.7.5 | 147 | 102 |
64+
| 9.7.6 | 571 | 571 |
65+
| 9.8.1 | 105 | 107 |
66+
| 9.8.2 | 57 | 102 |
67+
| 9.8.3 | 95 | 80 |
68+
| 9.8.4 | 79 | 115 |
69+
| 9.8.5 | 299 | 86 |
70+
| 9.8.6 | 424 | 160 |
71+
72+
The gun implementation is included in the `./gun` subdirectory.

test/compare/gun/gun_autobahn.erl

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
%% Copyright (c) 2015-2020, Loïc Hoguin <[email protected]>
2+
%%
3+
%% Permission to use, copy, modify, and/or distribute this software for any
4+
%% purpose with or without fee is hereby granted, provided that the above
5+
%% copyright notice and this permission notice appear in all copies.
6+
%%
7+
%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8+
%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9+
%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10+
%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11+
%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12+
%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13+
%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14+
15+
-module(gun_autobahn).
16+
-compile(export_all).
17+
-compile(nowarn_export_all).
18+
19+
autobahn_fuzzingserver() ->
20+
N = get_case_count(),
21+
run_cases(0, N),
22+
terminate().
23+
24+
get_case_count() ->
25+
{Pid, MRef, StreamRef} = connect("/getCaseCount"),
26+
receive
27+
{gun_ws, Pid, StreamRef, {text, N}} ->
28+
close(Pid, MRef),
29+
binary_to_integer(N);
30+
_Msg ->
31+
terminate(),
32+
error(failed)
33+
end.
34+
35+
run_cases(Total, Total) ->
36+
ok;
37+
run_cases(N, Total) ->
38+
{Pid, MRef, StreamRef} = connect(["/runCase?case=", integer_to_binary(N + 1), "&agent=Gun"]),
39+
loop(Pid, MRef, StreamRef),
40+
update_reports(),
41+
run_cases(N + 1, Total).
42+
43+
loop(Pid, MRef, StreamRef) ->
44+
receive
45+
{gun_ws, Pid, StreamRef, close} ->
46+
gun:ws_send(Pid, StreamRef, close),
47+
loop(Pid, MRef, StreamRef);
48+
{gun_ws, Pid, StreamRef, {close, Code, _}} ->
49+
gun:ws_send(Pid, StreamRef, {close, Code, <<>>}),
50+
loop(Pid, MRef, StreamRef);
51+
{gun_ws, Pid, StreamRef, Frame} ->
52+
gun:ws_send(Pid, StreamRef, Frame),
53+
loop(Pid, MRef, StreamRef);
54+
{gun_down, Pid, ws, _, _} ->
55+
close(Pid, MRef);
56+
{'DOWN', MRef, process, Pid, normal} ->
57+
close(Pid, MRef);
58+
_Msg ->
59+
close(Pid, MRef)
60+
end.
61+
62+
update_reports() ->
63+
{Pid, MRef, StreamRef} = connect("/updateReports?agent=Gun"),
64+
receive
65+
{gun_ws, Pid, StreamRef, close} ->
66+
close(Pid, MRef)
67+
after 5000 ->
68+
error(failed)
69+
end.
70+
71+
connect(Path) ->
72+
{ok, Pid} = gun:open("fuzzingserver", 9001, #{retry => 0}),
73+
{ok, http} = gun:await_up(Pid),
74+
MRef = monitor(process, Pid),
75+
StreamRef = gun:ws_upgrade(Pid, Path, [], #{compress => true}),
76+
receive
77+
{gun_upgrade, Pid, StreamRef, [<<"websocket">>], _} ->
78+
ok;
79+
_Msg ->
80+
terminate(),
81+
error(failed)
82+
end,
83+
{Pid, MRef, StreamRef}.
84+
85+
close(Pid, MRef) ->
86+
demonitor(MRef),
87+
gun:close(Pid),
88+
gun:flush(Pid).
89+
90+
terminate() ->
91+
ok.

0 commit comments

Comments
 (0)