diff options
author | Loïc Hoguin <[email protected]> | 2021-01-11 15:14:49 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2021-02-07 17:31:38 +0100 |
commit | 36fdf30fcf09a8ffe20c3498ac0b58de0971fd7d (patch) | |
tree | af08ff8a8416594946f22749103d2912d6d54221 /test/handlers/pool_ws_handler.erl | |
parent | 3a3e56fb66edaaa1a7093744a0fd8303b993b3c8 (diff) | |
download | gun-36fdf30fcf09a8ffe20c3498ac0b58de0971fd7d.tar.gz gun-36fdf30fcf09a8ffe20c3498ac0b58de0971fd7d.tar.bz2 gun-36fdf30fcf09a8ffe20c3498ac0b58de0971fd7d.zip |
Initial commit for Gun pools
The approach taken here is very similar to what browsers are
doing. A separate pool is created for each host/port/scope.
The authority (host header) is used to determine which pool
will execute requests. A connection process is semi-randomly
chosen, from the connections that have capacity. Maximum
capacity is determined by the protocol (the HTTP/2 setting
set by the server is used, for example). Multiple processes
can process requests/responses on the same connection
concurrently. There is no need to "give back" the response
to the pool, the number of ongoing streams is maintained via
an event handler.
The implementation is currently not strict, there may be
more attempts to create requests than there is capacity.
I'm not sure if it should be made strict or if Gun should
just wait before sending requests (it only matters in the
HTTP/2 case at the moment).
When there is no connection with capacity available in the
pool (because they have too many streams, or are reconnecting,
or any other reason), checking out fails. There is no timeout
to wait for a connection to be available. On the other hand
the checkout_retry option allows setting multiple timeouts
to retry checking out a connection. Each retry attempt's
wait time can have a different value.
The initial implementation of this work was sponsored by
Kobil and made at the suggestion of Ilya Khaprov.
Diffstat (limited to 'test/handlers/pool_ws_handler.erl')
-rw-r--r-- | test/handlers/pool_ws_handler.erl | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/test/handlers/pool_ws_handler.erl b/test/handlers/pool_ws_handler.erl new file mode 100644 index 0000000..5475e88 --- /dev/null +++ b/test/handlers/pool_ws_handler.erl @@ -0,0 +1,13 @@ +%% Feel free to use, reuse and abuse the code in this file. + +-module(pool_ws_handler). + +-export([init/4]). +-export([handle/2]). + +init(_, _, _, #{user_opts := ReplyTo}) -> + {ok, ReplyTo}. + +handle(Frame, ReplyTo) -> + ReplyTo ! Frame, + {ok, 0, ReplyTo}. |