Hello fellow Erlangers :)
Just another Erlang enthusiast playing with the language here. I have a very simple YAWS app module which works fine when accessed by single clients. However, when I try to spawn multiple concurrent clients, some of those clients start receiving errors (even if the number of those clients is very low, say 10). Any idea what can be causing it?
Illustrating code:
App Module
out(Arg) ->
io:format("got something!\n"),
Method = extract_method(Arg),
handle(Method, Arg).
Client
client(SenderPID) ->
case httpc:request(
put,
{
"http://localhost:8080/storageunit",
[],
"application/x-www-form-urlencoded",
""
}, [], []) of
{ error, Reason } -> io:format("Server responded with an error: ~p.\n", [Reason]);
{ ok, _ } -> ok
end,
SenderPID ! 'FINISHED'.
client_spawner(_SenderPID, 0) -> io:format("Done.\n");
client_spawner(SenderPID, Times) ->
spawn(concurrent, client, [SenderPID]),
client_spawner(SenderPID, Times - 1).
The errors I'm getting:
Server responded with an error: socket_closed_remotely.
The last piece of info is:
- 10 concurrent clients - from 2 to 5 errors on average
- 100-100000 concurrent clients - 50% errors on average
I thought my handling code causes it, but in scenarios where the clients receive httpc errors, the server doesn't even react with a "got something!".
I'm sure I'm missing something trivial, can you help?
Regards, Piotr