[erlang-questions] Cowboy , Concurrency , Tuning

90 views
Skip to first unread message

AD

unread,
Oct 9, 2012, 10:02:53 PM10/9/12
to erlang-q...@erlang.org
hello,

 I currently have a SockJS websocket implementation sitting on top of cowboy.  We have been going through some tuning/concurrency testing and we have improved our results drastically by increasing 

ERL_MAX_PORTS to 64000 
+P parameter to a very high number , around 128000 
Kernel tuning 

 With this config on a medium VM we have been able to successfully get to around 60,000 connections, up from 4096 so we are headed in the right direction :-)

 MY next question is with Cowboy tuning.  I notice that the default max_connections parameter on the TCP transport is 1024 if not set, but I am not hitting this issue.  What is the right way to tune NBAcceptor pool and the the max_connections setting for the acceptor ?

 Right now my start_listener is simply 

cowboy:start_listener(my_http_listener, 200,
     cowboy_tcp_transport, [{port, ?COWBOY_HTTP_PORT}],
     cowboy_http_protocol, [{dispatch, Routes}]
    ).

but i have seen some examples with 

cowboy:start_listener(my_http_listener, 200,
     cowboy_tcp_transport, [{port, ?COWBOY_HTTP_PORT}, {max_connections, infinity} ],
     cowboy_http_protocol, [{dispatch, Routes}]
    ).

Cowboy tuning seems like the last place i need to look, any thoughts/feedback here on best practices ?

Thanks
-AD

Paul Peregud

unread,
Oct 10, 2012, 2:41:23 AM10/10/12
to AD, erlang-q...@erlang.org
It seems that you are using old Cowboy. I was using it too and I hit a bottleneck in cowboy_listener add_pid/remove_pid mechanism. New Cowboy/Ranch handles that part better.

_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions




--
Best regards,
Paul Peregud
+48602112091

Loïc Hoguin

unread,
Oct 10, 2012, 4:36:17 AM10/10/12
to AD, erlang-q...@erlang.org
On 10/10/2012 04:02 AM, AD wrote:
> hello,

Hey,

> I currently have a SockJS websocket implementation sitting on top of
> cowboy. We have been going through some tuning/concurrency testing and
> we have improved our results drastically by increasing
>
> ERL_MAX_PORTS to 64000
> +P parameter to a very high number , around 128000
> Kernel tuning
>
> With this config on a medium VM we have been able to successfully get
> to around 60,000 connections, up from 4096 so we are headed in the right
> direction :-)

Well then with the above configuration you're at about the maximum
concurrent connections you can get. If you increase ERL_MAX_PORTS and +P
even more Cowboy shouldn't have any trouble giving you even better results.

> MY next question is with Cowboy tuning. I notice that the default
> max_connections parameter on the TCP transport is 1024 if not set, but I
> am not hitting this issue. What is the right way to tune NBAcceptor
> pool and the the max_connections setting for the acceptor ?

NBAcceptor shouldn't be too low but shouldn't be too high either. I
found 100 to be a good values but it really depends on how many
connections come at once, how many cores you have, how many concurrent
connections you expect, and so on.

> Right now my start_listener is simply
>
> cowboy:start_listener(my_http_listener, 200,
> cowboy_tcp_transport, [{port, ?COWBOY_HTTP_PORT}],
> cowboy_http_protocol, [{dispatch, Routes}]
> ).
>
> but i have seen some examples with
>
> cowboy:start_listener(my_http_listener, 200,
> cowboy_tcp_transport, [{port, ?COWBOY_HTTP_PORT},
> */{max_connections, infinity}/* ],
> cowboy_http_protocol, [{dispatch, Routes}]
> ).

If you're using Cowboy 0.6.1 or below and looking for performance, you
should set max_connections to infinity. If you're using master, you can
let it at the default value.

Websocket connections are not counted in that number. All HTTP
connections are though, so you might want to look at cowboy_listener to
see how to remove the connection from the count (varies depending on
your version).

--
Loïc Hoguin
Erlang Cowboy
Nine Nines
http://ninenines.eu

AD

unread,
Oct 10, 2012, 6:32:42 AM10/10/12
to Loïc Hoguin, erlang-q...@erlang.org
Thanks Loic.  Any reason why websocket connections are not counted ?  is there a separate pool for max_connections for websockets?



--
Loďc Hoguin

Loïc Hoguin

unread,
Oct 10, 2012, 7:51:36 AM10/10/12
to AD, erlang-q...@erlang.org
In 0.6.1 there is a separate pool for websockets but it was never fully
implemented (never requested) so you can't easily set the limit.

Instead in master this was removed, they just aren't counted, and the
application can just decide how to handle it.

The point is that we want to limit connections which are going to use
CPU but not the ones that are going to spend most of their time in a
receive loop, probably hibernating.

> cowboy:start_listener(my_http___listener, 200,


> cowboy_tcp_transport, [{port, ?COWBOY_HTTP_PORT}],
> cowboy_http_protocol, [{dispatch, Routes}]
> ).
>
> but i have seen some examples with
>

> cowboy:start_listener(my_http___listener, 200,


> cowboy_tcp_transport, [{port, ?COWBOY_HTTP_PORT},
> */{max_connections, infinity}/* ],
> cowboy_http_protocol, [{dispatch, Routes}]
> ).
>
>
> If you're using Cowboy 0.6.1 or below and looking for performance,
> you should set max_connections to infinity. If you're using master,
> you can let it at the default value.
>
> Websocket connections are not counted in that number. All HTTP
> connections are though, so you might want to look at cowboy_listener
> to see how to remove the connection from the count (varies depending
> on your version).
>
> --
> Loďc Hoguin
> Erlang Cowboy
> Nine Nines
> http://ninenines.eu
>
>


--
Loïc Hoguin


Erlang Cowboy
Nine Nines
http://ninenines.eu

Reply all
Reply to author
Forward
0 new messages