<div dir="ltr">Arshad --<div><br></div><div>A single gen_server instance is single-threaded, handling only one message at a time. Gen_servers are not necessarily network related; they have to work in conjunction with libraries like gen_udp and gen_tcp in order to arrange to send and receive messages on networks.</div><div><br></div><div>It's important to know that there are a few different kinds of socket: "listen" sockets, which bind to a port on your computer's network interface and wait for new connection attempts to get made, and "client" sockets, which are sockets that can be communicated over once the connection has been formed. You can think of "client" sockets as having been peeled off a "listen" socket.</div><div><br></div><div>Listen sockets can be shared by sending them as part of a message to another process, or by passing them as an argument to a process spawn function. In the case of tcp sockets, it's fairly natural to open a listen socket, spawn child processes, passing them the listen socket, and for each of the children to call accept(), which then returns to them a fresh new unique client socket, in order to concurrently handle many simultaneous connections. A worked example is here, in the documentation: <a href="http://erlang.org/doc/man/gen_tcp.html#Examples">http://erlang.org/doc/man/gen_tcp.html#Examples</a> .</div><div><br></div><div>Client sockets can also be shared and passed around, but since a client socket can only be read by the client socket's owning process, this is of limited utility.</div><div><br></div><div>There are a large number of tunable parameters on your network card, in your operating system, and in erlang that you can fiddle with to obtain optimum performance if you're worried about erlang's scalability; the documentation for gen_tcp is a good place to start. Fred's excellent 'Learn You Some Erlang' book also has a great chapter on all this: <a href="http://learnyousomeerlang.com/buckets-of-sockets">http://learnyousomeerlang.com/buckets-of-sockets</a>.</div><div><br></div><div>F.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Aug 27, 2016 at 11:12 AM, Ehsan Mohammadi <span dir="ltr"><<a href="mailto:ehsan.tck@gmail.com" target="_blank">ehsan.tck@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">i`m new to erlang but as far as i know you can`t share a socket in multiple process or threads<div>so you can accept and get raw data in single server and do processing in a server pool or something like that</div></div><br><div class="gmail_quote"><div><div class="h5"><div dir="ltr">On Sat, Aug 27, 2016 at 8:35 PM Arshad Ansari <<a href="mailto:arshadansari27@gmail.com" target="_blank">arshadansari27@gmail.com</a>> wrote:<br></div></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">Hello there,<div><br></div><div>This is a generic question that I have regarding the ability of gen_server to handle requests concurrently. Does gen_server create a separate process per request (even when for each request coming from same socket connection) or does it create separate process per socket connection? If it is latter then there will be a single process responsible for handling large number of messaging coming from single socket. In that case, how to make sure that that single process can handle a very high load coming from a single connection?</div><div><br></div><div>I hope my question is clear!</div><div><br></div><div>Regards,</div><div>Arshad</div></div></div></div>
______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a><br>
</blockquote></div>
<br>______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>