forked from benoitc/hackney
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_multiple.erl
More file actions
executable file
·51 lines (45 loc) · 1.16 KB
/
Copy pathtest_multiple.erl
File metadata and controls
executable file
·51 lines (45 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env escript
%% -*- erlang -*-
%%! -pa ./ebin -pa ./deps/mimetypes/ebin
%%
%%
%%
%%
-define(MAX, 100).
wait_request() ->
receive
start -> ok
end.
request(WaitPid) ->
wait_request(),
Method = get,
Url = <<"https://friendpaste.com">>,
Headers = [{<<"Connection">>, <<"keep-alive">>}],
Options = [{pool, default}],
{ok, _, _Headers, Ref} = hackney:request(Method, Url, Headers, <<>>, Options),
{ok, _} = hackney:body(Ref),
WaitPid ! ack.
wait(100) ->
io:format("~n", []),
ok;
wait(N) ->
receive
ack ->
io:format(".", []),
wait(N+1)
after 15000 ->
PoolSize = hackney_pool:count(default),
io:format("~ntimeout ~p/~p done. ~p in the pool.~n",
[N, ?MAX, PoolSize])
end.
main(_) ->
hackney:start(),
hackney_pool:start_pool(default, []),
io:format("processing ", []),
Self = self(),
Pids = lists:foldr(fun(_, Acc) ->
Pid = spawn(fun() -> timer:sleep(100), request(Self) end),
[Pid | Acc]
end, [], lists:seq(1, ?MAX)),
[Pid ! start || Pid <- Pids],
wait(0).