Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace WS and HTTP servers with a server that supports both WS and HTTP #863

Merged
merged 40 commits into from
Sep 13, 2022

Conversation

niklasad1
Copy link
Member

@niklasad1 niklasad1 commented Aug 26, 2022

Closes #821 and #869

@niklasad1 niklasad1 changed the title [WIP]: ws server support both WS and HTTP [WIP]: replace WS and HTTP servers with a server that supports both WS and HTTP Aug 27, 2022
@niklasad1 niklasad1 force-pushed the na-mixed-ws-http-server-poc branch 2 times, most recently from 2d4b34b to 4bbb81c Compare August 27, 2022 09:41
@niklasad1
Copy link
Member Author

benches

➜  benches git:(49f260e) ✗ critcmp master mixed-server
group                                              master                                   mixed-server
-----                                              ------                                   ------------
async/http_batch_requests/fast_call/10             1.67    87.8±15.05µs 111.3 KElem/sec     1.00    52.5±12.02µs 186.0 KElem/sec
async/http_batch_requests/fast_call/100            1.09   336.6±47.58µs 290.1 KElem/sec     1.00   310.1±37.80µs 314.9 KElem/sec
async/http_batch_requests/fast_call/2              1.00     47.2±8.54µs 41.4 KElem/sec      1.04    48.9±15.25µs 39.9 KElem/sec
async/http_batch_requests/fast_call/5              1.03    56.3±16.86µs 86.8 KElem/sec      1.00    54.9±21.48µs 89.0 KElem/sec
async/http_batch_requests/fast_call/50             1.12   218.7±20.76µs 223.3 KElem/sec     1.00   196.0±29.90µs 249.1 KElem/sec
async/http_batch_requests/memory_intense/10        1.00     19.0±1.65ms   527 Elem/sec      1.06     20.0±1.79ms   499 Elem/sec
async/http_batch_requests/memory_intense/100       1.03    177.3±6.24ms   564 Elem/sec      1.00    172.9±8.73ms   578 Elem/sec
async/http_batch_requests/memory_intense/2         1.16      4.6±0.35ms   437 Elem/sec      1.00      3.9±0.35ms   507 Elem/sec
async/http_batch_requests/memory_intense/5         1.08     10.8±0.86ms   461 Elem/sec      1.00     10.0±1.11ms   498 Elem/sec
async/http_batch_requests/memory_intense/50        1.01     88.8±6.61ms   563 Elem/sec      1.00     87.8±7.76ms   569 Elem/sec
async/http_batch_requests/slow_call/10             1.00     10.7±0.05ms   931 Elem/sec      1.00     10.7±0.03ms   930 Elem/sec
async/http_batch_requests/slow_call/100            1.00    105.8±0.18ms   945 Elem/sec      1.00    105.9±0.17ms   943 Elem/sec
async/http_batch_requests/slow_call/2              1.00      2.2±0.03ms   907 Elem/sec      1.00      2.2±0.01ms   912 Elem/sec
async/http_batch_requests/slow_call/5              1.00      5.4±0.03ms   919 Elem/sec      1.00      5.4±0.04ms   919 Elem/sec
async/http_batch_requests/slow_call/50             1.00     53.1±0.12ms   941 Elem/sec      1.00     53.1±0.10ms   942 Elem/sec
async/http_concurrent_conn_calls/fast_call/1024    1.00    42.8±35.56ms        ? ?/sec      1.26    53.8±24.50ms        ? ?/sec
async/http_concurrent_conn_calls/fast_call/128     1.00      5.6±4.65ms        ? ?/sec      1.28      7.1±3.25ms        ? ?/sec
async/http_concurrent_conn_calls/fast_call/16      1.00  739.2±868.59µs        ? ?/sec      1.28  945.3±661.00µs        ? ?/sec
async/http_concurrent_conn_calls/fast_call/2       1.17   161.7±23.91µs        ? ?/sec      1.00   138.1±35.89µs        ? ?/sec
async/http_concurrent_conn_calls/fast_call/256     1.00     10.3±9.10ms        ? ?/sec      1.40     14.4±6.76ms        ? ?/sec
async/http_concurrent_conn_calls/fast_call/32      1.00  1645.8±1346.72µs        ? ?/sec    1.11  1828.9±978.82µs        ? ?/sec
async/http_concurrent_conn_calls/fast_call/4       1.07  258.3±358.53µs        ? ?/sec      1.00  240.7±285.07µs        ? ?/sec
async/http_concurrent_conn_calls/fast_call/512     1.00    20.4±17.96ms        ? ?/sec      1.33    27.1±12.58ms        ? ?/sec
async/http_concurrent_conn_calls/fast_call/64      1.00      2.8±2.40ms        ? ?/sec      1.29      3.6±1.62ms        ? ?/sec
async/http_concurrent_conn_calls/fast_call/8       1.00  451.6±552.88µs        ? ?/sec      1.21  547.7±474.38µs        ? ?/sec
async/http_custom_headers_round_trip/0kb           1.00    43.6±13.18µs        ? ?/sec      1.41     61.4±8.52µs        ? ?/sec
async/http_custom_headers_round_trip/100kb         1.07   133.5±17.40µs        ? ?/sec      1.00   124.3±11.24µs        ? ?/sec
async/http_custom_headers_round_trip/1kb           1.00    43.8±15.25µs        ? ?/sec      1.19     52.2±5.49µs        ? ?/sec
async/http_custom_headers_round_trip/25kb          1.00    64.3±17.93µs        ? ?/sec      1.06     67.9±8.73µs        ? ?/sec
async/http_custom_headers_round_trip/5kb           1.00    45.2±13.83µs        ? ?/sec      1.41    64.0±10.12µs        ? ?/sec
async/http_round_trip/fast_call                    1.00    57.2±12.96µs        ? ?/sec      1.03     59.1±6.65µs        ? ?/sec
async/http_round_trip/memory_intense               1.18      2.1±0.17ms        ? ?/sec      1.00  1777.0±169.36µs        ? ?/sec
async/http_round_trip/slow_call                    1.00  1124.0±13.12µs        ? ?/sec      1.00  1129.6±10.83µs        ? ?/sec
async/ws_batch_requests/fast_call/10               1.00     37.8±1.66µs 258.2 KElem/sec     1.74    65.6±21.68µs 148.8 KElem/sec
async/ws_batch_requests/fast_call/100              1.00   282.4±35.20µs 345.8 KElem/sec     1.24   350.0±13.65µs 279.0 KElem/sec
async/ws_batch_requests/fast_call/2                1.66    40.2±10.39µs 48.6 KElem/sec      1.00     24.2±1.32µs 80.7 KElem/sec
async/ws_batch_requests/fast_call/5                1.32    41.5±13.24µs 117.7 KElem/sec     1.00     31.4±2.37µs 155.5 KElem/sec
async/ws_batch_requests/fast_call/50               1.00   169.5±30.48µs 288.1 KElem/sec     1.21    204.8±9.56µs 238.4 KElem/sec
async/ws_batch_requests/memory_intense/10          1.04     13.5±0.74ms   740 Elem/sec      1.00     13.0±1.82ms   770 Elem/sec
async/ws_batch_requests/memory_intense/100         1.12   215.8±10.55ms   463 Elem/sec      1.00    192.8±8.85ms   518 Elem/sec
async/ws_batch_requests/memory_intense/2           1.00      3.1±0.71ms   640 Elem/sec      1.17      3.6±0.84ms   549 Elem/sec
async/ws_batch_requests/memory_intense/5           1.03      8.3±1.84ms   604 Elem/sec      1.00      8.0±1.87ms   621 Elem/sec
async/ws_batch_requests/memory_intense/50          1.13    105.1±3.83ms   475 Elem/sec      1.00     93.4±3.43ms   535 Elem/sec
async/ws_batch_requests/slow_call/10               1.00     10.7±0.07ms   932 Elem/sec      1.00     10.7±0.05ms   934 Elem/sec
async/ws_batch_requests/slow_call/100              1.00    106.0±0.19ms   943 Elem/sec      1.00    106.0±0.21ms   943 Elem/sec
async/ws_batch_requests/slow_call/2                1.03      2.2±0.10ms   895 Elem/sec      1.00      2.2±0.01ms   919 Elem/sec
async/ws_batch_requests/slow_call/5                1.00      5.4±0.03ms   928 Elem/sec      1.00      5.4±0.02ms   927 Elem/sec
async/ws_batch_requests/slow_call/50               1.00     53.0±0.16ms   942 Elem/sec      1.00     53.1±0.21ms   942 Elem/sec
async/ws_concurrent_conn_calls/1024                1.24     19.1±2.68ms        ? ?/sec      1.00     15.4±2.89ms        ? ?/sec
async/ws_concurrent_conn_calls/128                 1.03      3.1±0.09ms        ? ?/sec      1.00      3.0±0.17ms        ? ?/sec
async/ws_concurrent_conn_calls/16                  1.10   314.8±27.64µs        ? ?/sec      1.00    285.5±9.96µs        ? ?/sec
async/ws_concurrent_conn_calls/2                   1.10   186.0±26.55µs        ? ?/sec      1.00   168.9±19.49µs        ? ?/sec
async/ws_concurrent_conn_calls/256                 1.07      5.8±0.30ms        ? ?/sec      1.00      5.5±0.50ms        ? ?/sec
async/ws_concurrent_conn_calls/32                  1.17   772.2±19.23µs        ? ?/sec      1.00   659.4±37.01µs        ? ?/sec
async/ws_concurrent_conn_calls/4                   1.15   210.0±25.03µs        ? ?/sec      1.00   182.9±22.75µs        ? ?/sec
async/ws_concurrent_conn_calls/512                 1.14     10.7±0.52ms        ? ?/sec      1.00      9.4±1.45ms        ? ?/sec
async/ws_concurrent_conn_calls/64                  1.04  1594.9±27.83µs        ? ?/sec      1.00  1529.9±65.81µs        ? ?/sec
async/ws_concurrent_conn_calls/8                   1.11   248.3±47.47µs        ? ?/sec      1.00   223.8±16.80µs        ? ?/sec
async/ws_concurrent_conn_subs/1024                 1.01     28.9±1.21ms        ? ?/sec      1.00     28.7±0.99ms        ? ?/sec
async/ws_concurrent_conn_subs/128                  1.00      3.7±0.08ms        ? ?/sec      1.00      3.7±0.12ms        ? ?/sec
async/ws_concurrent_conn_subs/16                   1.00    566.0±8.01µs        ? ?/sec      1.00   568.7±10.99µs        ? ?/sec
async/ws_concurrent_conn_subs/2                    1.02   287.4±29.11µs        ? ?/sec      1.00   281.4±30.68µs        ? ?/sec
async/ws_concurrent_conn_subs/256                  1.01      7.4±0.19ms        ? ?/sec      1.00      7.3±0.17ms        ? ?/sec
async/ws_concurrent_conn_subs/32                   1.00  1063.1±13.13µs        ? ?/sec      1.01  1077.2±19.62µs        ? ?/sec
async/ws_concurrent_conn_subs/4                    1.00   304.9±13.67µs        ? ?/sec      1.07   326.6±48.20µs        ? ?/sec
async/ws_concurrent_conn_subs/512                  1.02     15.1±0.47ms        ? ?/sec      1.00     14.8±0.31ms        ? ?/sec
async/ws_concurrent_conn_subs/64                   1.00  1974.0±30.67µs        ? ?/sec      1.00  1975.1±39.21µs        ? ?/sec
async/ws_concurrent_conn_subs/8                    1.01    355.8±5.56µs        ? ?/sec      1.00    351.8±4.39µs        ? ?/sec
async/ws_custom_headers_handshake/0kb              1.00     59.0±6.67µs        ? ?/sec      1.15     68.0±8.45µs        ? ?/sec
async/ws_custom_headers_handshake/1kb              1.00     66.7±4.94µs        ? ?/sec      1.37    91.6±19.34µs        ? ?/sec
async/ws_custom_headers_handshake/2kb              1.00     65.5±6.74µs        ? ?/sec      1.01     66.3±8.03µs        ? ?/sec
async/ws_custom_headers_handshake/4kb              1.00     67.2±6.15µs        ? ?/sec      1.13     75.7±8.94µs        ? ?/sec
async/ws_round_trip/fast_call                      1.00     21.1±2.14µs        ? ?/sec      1.98     41.9±4.90µs        ? ?/sec
async/ws_round_trip/memory_intense                 1.20  1325.6±300.97µs        ? ?/sec     1.00  1100.5±57.87µs        ? ?/sec
async/ws_round_trip/slow_call                      1.00   1112.1±5.30µs        ? ?/sec      1.00  1113.0±10.57µs        ? ?/sec
jsonrpsee_types_v2_array_ref                       1.00     89.7±0.68ns        ? ?/sec      1.03     92.4±3.66ns        ? ?/sec
jsonrpsee_types_v2_vec                             1.81    179.3±1.10ns        ? ?/sec      1.00     99.2±0.59ns        ? ?/sec
subscriptions/subscribe                            1.00     42.1±4.75µs        ? ?/sec      1.09     45.7±5.19µs        ? ?/sec
subscriptions/subscribe_response                   1.00  1524.3±561.14ns        ? ?/sec     1.08  1648.9±481.22ns        ? ?/sec
subscriptions/unsub                                1.94      2.4±0.59µs        ? ?/sec      1.00  1238.8±609.82ns        ? ?/sec
sync/http_batch_requests/fast_call/10              1.00    78.9±18.00µs 123.8 KElem/sec     1.01    79.5±19.03µs 122.9 KElem/sec
sync/http_batch_requests/fast_call/100             1.00   320.9±32.86µs 304.3 KElem/sec     1.02   328.7±22.71µs 297.1 KElem/sec
sync/http_batch_requests/fast_call/2               1.30    54.9±13.48µs 35.6 KElem/sec      1.00    42.3±12.47µs 46.2 KElem/sec
sync/http_batch_requests/fast_call/5               1.00    73.7±16.00µs 66.3 KElem/sec      1.03    75.8±16.34µs 64.4 KElem/sec
sync/http_batch_requests/fast_call/50              1.00   183.6±39.48µs 265.9 KElem/sec     1.07   196.2±22.67µs 248.9 KElem/sec
sync/http_batch_requests/memory_intense/10         1.00     21.7±0.98ms   460 Elem/sec      1.17     25.4±1.74ms   394 Elem/sec
sync/http_batch_requests/memory_intense/100        1.22   196.0±10.10ms   510 Elem/sec      1.00    160.3±7.51ms   623 Elem/sec
sync/http_batch_requests/memory_intense/2          1.00      3.4±0.19ms   591 Elem/sec      1.00      3.4±0.20ms   589 Elem/sec
sync/http_batch_requests/memory_intense/5          1.17     10.4±0.61ms   481 Elem/sec      1.00      8.9±0.22ms   564 Elem/sec
sync/http_batch_requests/memory_intense/50         1.16    106.8±5.44ms   468 Elem/sec      1.00     92.4±6.83ms   541 Elem/sec
sync/http_batch_requests/slow_call/10              1.01     10.8±0.03ms   928 Elem/sec      1.00     10.7±0.03ms   934 Elem/sec
sync/http_batch_requests/slow_call/100             1.00    106.0±0.14ms   943 Elem/sec      1.00    105.8±0.16ms   944 Elem/sec
sync/http_batch_requests/slow_call/2               1.01      2.2±0.01ms   908 Elem/sec      1.00      2.2±0.01ms   915 Elem/sec
sync/http_batch_requests/slow_call/5               1.00      5.4±0.02ms   921 Elem/sec      1.00      5.4±0.05ms   923 Elem/sec
sync/http_batch_requests/slow_call/50              1.00     53.0±0.09ms   942 Elem/sec      1.00     53.0±0.12ms   943 Elem/sec
sync/http_concurrent_conn_calls/fast_call/1024     1.00    41.9±35.87ms        ? ?/sec      1.35    56.5±25.15ms        ? ?/sec
sync/http_concurrent_conn_calls/fast_call/128      1.00      5.9±4.76ms        ? ?/sec      1.25      7.3±3.15ms        ? ?/sec
sync/http_concurrent_conn_calls/fast_call/16       1.00  756.1±874.72µs        ? ?/sec      1.23  931.1±601.76µs        ? ?/sec
sync/http_concurrent_conn_calls/fast_call/2        1.04   141.6±31.52µs        ? ?/sec      1.00   136.3±40.70µs        ? ?/sec
sync/http_concurrent_conn_calls/fast_call/256      1.00     11.0±9.29ms        ? ?/sec      1.33     14.7±6.36ms        ? ?/sec
sync/http_concurrent_conn_calls/fast_call/32       1.00  1479.6±1286.91µs        ? ?/sec    1.32  1952.9±1059.19µs        ? ?/sec
sync/http_concurrent_conn_calls/fast_call/4        1.12  267.3±357.89µs        ? ?/sec      1.00  238.2±263.87µs        ? ?/sec
sync/http_concurrent_conn_calls/fast_call/512      1.00    21.3±18.05ms        ? ?/sec      1.33    28.3±11.64ms        ? ?/sec
sync/http_concurrent_conn_calls/fast_call/64       1.00      2.9±2.44ms        ? ?/sec      1.23      3.6±1.59ms        ? ?/sec
sync/http_concurrent_conn_calls/fast_call/8        1.00  402.5±513.47µs        ? ?/sec      1.28  516.4±432.28µs        ? ?/sec
sync/http_custom_headers_round_trip/0kb            1.25    55.9±10.46µs        ? ?/sec      1.00    44.7±15.15µs        ? ?/sec
sync/http_custom_headers_round_trip/100kb          1.22   140.4±12.20µs        ? ?/sec      1.00   115.0±12.91µs        ? ?/sec
sync/http_custom_headers_round_trip/1kb            1.52    55.2±10.21µs        ? ?/sec      1.00     36.3±5.50µs        ? ?/sec
sync/http_custom_headers_round_trip/25kb           1.24    55.3±13.95µs        ? ?/sec      1.00     44.7±6.52µs        ? ?/sec
sync/http_custom_headers_round_trip/5kb            1.30    56.8±12.72µs        ? ?/sec      1.00     43.7±7.62µs        ? ?/sec
sync/http_round_trip/fast_call                     1.23    41.6±12.75µs        ? ?/sec      1.00     33.8±7.15µs        ? ?/sec
sync/http_round_trip/memory_intense                1.06      2.2±0.21ms        ? ?/sec      1.00      2.1±0.23ms        ? ?/sec
sync/http_round_trip/slow_call                     1.00  1130.5±11.68µs        ? ?/sec      1.01  1137.5±12.80µs        ? ?/sec
sync/ws_batch_requests/fast_call/10                2.05     79.7±6.07µs 122.6 KElem/sec     1.00     38.8±1.57µs 251.7 KElem/sec
sync/ws_batch_requests/fast_call/100               1.09   341.3±36.91µs 286.1 KElem/sec     1.00   314.4±46.23µs 310.7 KElem/sec
sync/ws_batch_requests/fast_call/2                 1.07    40.2±12.25µs 48.6 KElem/sec      1.00     37.7±7.85µs 51.8 KElem/sec
sync/ws_batch_requests/fast_call/5                 1.00    40.8±12.71µs 119.6 KElem/sec     1.16    47.2±16.03µs 103.4 KElem/sec
sync/ws_batch_requests/fast_call/50                1.19   200.7±24.66µs 243.3 KElem/sec     1.00   168.7±27.52µs 289.4 KElem/sec
sync/ws_batch_requests/memory_intense/10           1.03     14.2±1.96ms   704 Elem/sec      1.00     13.7±1.91ms   727 Elem/sec
sync/ws_batch_requests/memory_intense/100          1.04    195.1±8.64ms   512 Elem/sec      1.00    186.9±8.65ms   535 Elem/sec
sync/ws_batch_requests/memory_intense/2            1.00      3.2±0.94ms   624 Elem/sec      1.09      3.5±0.75ms   571 Elem/sec
sync/ws_batch_requests/memory_intense/5            1.23     10.8±1.23ms   461 Elem/sec      1.00      8.8±2.01ms   568 Elem/sec
sync/ws_batch_requests/memory_intense/50           1.20     99.6±4.33ms   502 Elem/sec      1.00     82.9±3.04ms   603 Elem/sec
sync/ws_batch_requests/slow_call/10                1.00     10.7±0.03ms   934 Elem/sec      1.00     10.7±0.03ms   936 Elem/sec
sync/ws_batch_requests/slow_call/100               1.00    106.0±0.14ms   943 Elem/sec      1.00    106.0±0.17ms   943 Elem/sec
sync/ws_batch_requests/slow_call/2                 1.05      2.3±0.12ms   880 Elem/sec      1.00      2.2±0.01ms   924 Elem/sec
sync/ws_batch_requests/slow_call/5                 1.01      5.4±0.06ms   921 Elem/sec      1.00      5.4±0.03ms   929 Elem/sec
sync/ws_batch_requests/slow_call/50                1.00     53.0±0.08ms   942 Elem/sec      1.00     53.1±0.10ms   942 Elem/sec
sync/ws_concurrent_conn_calls/1024                 1.43     21.8±2.40ms        ? ?/sec      1.00     15.3±2.63ms        ? ?/sec
sync/ws_concurrent_conn_calls/128                  1.04      3.1±0.08ms        ? ?/sec      1.00      3.0±0.18ms        ? ?/sec
sync/ws_concurrent_conn_calls/16                   1.18   352.4±31.58µs        ? ?/sec      1.00   297.9±26.04µs        ? ?/sec
sync/ws_concurrent_conn_calls/2                    1.07   192.1±30.08µs        ? ?/sec      1.00   178.9±23.71µs        ? ?/sec
sync/ws_concurrent_conn_calls/256                  1.05      5.9±0.21ms        ? ?/sec      1.00      5.6±0.54ms        ? ?/sec
sync/ws_concurrent_conn_calls/32                   1.23   821.7±16.57µs        ? ?/sec      1.00   667.7±36.12µs        ? ?/sec
sync/ws_concurrent_conn_calls/4                    1.00   181.9±20.05µs        ? ?/sec      1.15   208.3±44.17µs        ? ?/sec
sync/ws_concurrent_conn_calls/512                  1.13     10.8±0.47ms        ? ?/sec      1.00      9.6±1.12ms        ? ?/sec
sync/ws_concurrent_conn_calls/64                   1.06  1611.9±22.89µs        ? ?/sec      1.00  1521.6±66.67µs        ? ?/sec
sync/ws_concurrent_conn_calls/8                    1.00   217.5±20.91µs        ? ?/sec      1.09   236.3±28.10µs        ? ?/sec
sync/ws_concurrent_conn_subs/1024                  1.02     28.5±1.14ms        ? ?/sec      1.00     27.9±1.10ms        ? ?/sec
sync/ws_concurrent_conn_subs/128                   1.02      3.7±0.08ms        ? ?/sec      1.00      3.7±0.07ms        ? ?/sec
sync/ws_concurrent_conn_subs/16                    1.01   567.0±11.76µs        ? ?/sec      1.00    561.9±7.00µs        ? ?/sec
sync/ws_concurrent_conn_subs/2                     1.00   308.1±36.35µs        ? ?/sec      1.09   336.3±33.19µs        ? ?/sec
sync/ws_concurrent_conn_subs/256                   1.03      7.3±0.19ms        ? ?/sec      1.00      7.2±0.17ms        ? ?/sec
sync/ws_concurrent_conn_subs/32                    1.00  1065.5±16.05µs        ? ?/sec      1.00  1065.6±14.93µs        ? ?/sec
sync/ws_concurrent_conn_subs/4                     1.03   309.7±16.44µs        ? ?/sec      1.00   300.4±16.96µs        ? ?/sec
sync/ws_concurrent_conn_subs/512                   1.02     14.9±0.55ms        ? ?/sec      1.00     14.6±0.30ms        ? ?/sec
sync/ws_concurrent_conn_subs/64                    1.01  1974.4±36.27µs        ? ?/sec      1.00  1954.8±28.66µs        ? ?/sec
sync/ws_concurrent_conn_subs/8                     1.01    354.3±5.60µs        ? ?/sec      1.00    350.3±7.10µs        ? ?/sec
sync/ws_custom_headers_handshake/0kb               1.00     54.8±4.19µs        ? ?/sec      1.73    94.9±15.86µs        ? ?/sec
sync/ws_custom_headers_handshake/1kb               1.00     59.1±8.89µs        ? ?/sec      1.17     69.3±7.88µs        ? ?/sec
sync/ws_custom_headers_handshake/2kb               1.00     65.8±5.26µs        ? ?/sec      1.42    93.5±13.70µs        ? ?/sec
sync/ws_custom_headers_handshake/4kb               1.00     76.4±4.06µs        ? ?/sec      1.12     85.3±9.43µs        ? ?/sec
sync/ws_round_trip/fast_call                       1.06     26.2±7.87µs        ? ?/sec      1.00     24.6±5.06µs        ? ?/sec
sync/ws_round_trip/memory_intense                  1.47      2.1±0.10ms        ? ?/sec      1.00  1436.9±341.20µs        ? ?/sec
sync/ws_round_trip/slow_call                       1.00   1099.7±8.55µs        ? ?/sec      1.00   1102.7±7.17µs        ? ?/sec

server/src/transport/http.rs Outdated Show resolved Hide resolved
///
/// Returns `(MethodResponse, None)` on every call that isn't a subscription
/// Otherwise `(MethodResponse, Some(PendingSubscriptionCallTx)`.
pub(crate) async fn execute_call<L: WsLogger>(c: Call<'_, L>) -> MethodResult {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How much similarity is there between these methods and the same in http.rs; is it worth trying to reuse more functionality from within them or are the yactually fairly distinct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah those are super similar but WS stuff has some extra stuff such as subscriptions but I think we could rework that in a follow-up PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me; definitely no rush, just something I pondered when I saw it!

@niklasad1 niklasad1 changed the title [WIP]: replace WS and HTTP servers with a server that supports both WS and HTTP replace WS and HTTP servers with a server that supports both WS and HTTP Aug 31, 2022
@niklasad1 niklasad1 marked this pull request as ready for review August 31, 2022 16:12
@niklasad1 niklasad1 requested a review from a team as a code owner August 31, 2022 16:12
@@ -0,0 +1,6 @@
//! Host filtering.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the idea that in a followup PR we might be able to move this stuff into a tower middleware?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, if it will become cleaner

it's so little code now so I'm okay keeping it here as well.

examples/examples/logger.rs Outdated Show resolved Hide resolved
Comment on lines +57 to +75
// WebSocket.
{
let client = WsClientBuilder::default().build(format!("ws://{}", addr)).await?;
let response: String = client.request("say_hello", rpc_params![]).await?;
println!("[main]: ws response: {:?}", response);
let _response: Result<String, _> = client.request("unknown_method", rpc_params![]).await;
let _ = client.request::<String, _>("say_hello", rpc_params![]).await?;
}

let client = HttpClientBuilder::default().build(&url)?;
let response: String = client.request("say_hello", rpc_params![]).await?;
println!("[main]: response: {:?}", response);
let _response: Result<String, _> = client.request("unknown_method", rpc_params![]).await;
let _: String = client.request("say_hello", rpc_params![]).await?;
tokio::time::sleep(std::time::Duration::from_secs(1)).await;

// HTTP.
{
let client = HttpClientBuilder::default().build(format!("http://{}", addr))?;
let response: String = client.request("say_hello", rpc_params![]).await?;
println!("[main]: http response: {:?}", response);
let _response: Result<String, _> = client.request("unknown_method", rpc_params![]).await;
let _ = client.request::<String, _>("say_hello", rpc_params![]).await?;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I wonder whether it's worth having a separate http_and_ws.rs example to show that you can do this, since this example is, I guess, focused on middleware!

Doesn't need doing in this PR though; just a thought :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh actually I see what you're getting at here; middleware works for either http or ws. Let's leave it be :)

// NOTE: this task will finish after the HTTP request have been finished.
//
// Thus, if it was a Websocket Upgrade request the background task will be spawned separately.
let mut stop_handle2 = stop_handle.clone();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: does it need cloning? it's not being used anywhere elseby the looks of it :)

Is the comment saying that the async block below finishes when the http request is read and handled but that ws will lead to task being spawned?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's in a loop so the clone is needed :(

it was just a side-note to previous behavior i.e, the task would live as long as the ws connection task was alive but now "this task" finished once the HTTP request is finished but I removed the comment.

this is because the hyper callback just a spawns the task directly without access to FutureDriver

@jsdw
Copy link
Collaborator

jsdw commented Sep 12, 2022

Looks great! Just to document; me and Niklas chatted about having a method on ServerHandle which just calls closed() on the watch thing and returns that future. Then we don't need to impl Future on it and don't need #873 (the slightly nicer ergonomics of ServerHandle being a future don't feel like they pull their weight) :)

Asdie from that I'm good to tick this PR; it looks awesome!

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let mut shutdown_waiter = ShutdownWaiter(self.0.clone());
/// Wait for the server to stopped..
pub async fn stopped(self) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could call this wait or something not sure :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like stopped offhand just because it is consistent with stopped and stop!

tokio::select! {
res = &mut conn => {
match res {
Ok(_) => tracing::info!("Accepting new connection {}/{}", curr_conns, max_conns),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we log the peer addr here as well? I reckon that it might be useful

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like a good idea, we can always come with another PR
Wondering if we should incorporate the peer addr or connection address to uniquely identify which logs are coming from which connections?
It might help us group errors and warnings that have a common root cause

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it was one thing missing from the logs when I tried to debug these Transport(i/o error: unexpected end of file) errors that we have seen plenty of

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's do it in another PR

server/src/server.rs Outdated Show resolved Hide resolved
examples/examples/logger.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@jsdw jsdw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks amazing; great job!

server/src/future.rs Outdated Show resolved Hide resolved
server/src/future.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@lexnv lexnv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGMT! 👍 Nice job unifying ws/http!

niklasad1 and others added 2 commits September 13, 2022 17:35
Co-authored-by: Alexandru Vasile <60601340+lexnv@users.noreply.github.com>
Co-authored-by: Alexandru Vasile <60601340+lexnv@users.noreply.github.com>
@niklasad1 niklasad1 merged commit bf73876 into master Sep 13, 2022
@niklasad1 niklasad1 deleted the na-mixed-ws-http-server-poc branch September 13, 2022 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mixed HTTP/WebSocket server?
3 participants