Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is using Erlang's gen_tcp a scalable way to construct a high traffic socket server

I am trying to learn Erlang to do some simple but scalable network programming. I basically want to write a program that does what servers on the backbone of the internet do--but on a smaller scale. I want to try to set up an intranet with web accessible servers which would act as gateways to the intranet [sic] and route data to connected clients and/or other gateways.

The high traffic would come from the fact that data would not only flow from client to gateway to client, but might have to bounce around a few gateways to get to the destination (like how data travels on the internet). This means that the gateways would have to not only handle traffic from their clients, but traffic from other gateways' clients.

I figured this would lead to unusually high levels of traffic, even for a medium number of clients and gateways.

Coming from a background in Python and, to a lesser extent, other scripting languages, I am used to digging for a customized module to solve my problems. I understand Erlang is designed for high traffic network programming, but all I could find in terms of libraries/modules for this kind of thing was gen_tcp.

Does this mean that Erlang is already so optimized for this kind of thing that you can fire it up with its most basic modules and expect it to scale nicely?

like image 958
Alex Eftimiades Avatar asked Sep 28 '12 19:09

Alex Eftimiades


1 Answers

You can expect gen_tcp to perform extremely well, even under conditions of massive load. If you are just going to pass around data and not process it much, then my guess is you will be able to scale quite nicely - effectively you will just be passing around pointers.

All of the known scalable solutions written in Erlang uses gen_tcp:

  • Cowboy, Mochiweb, Yaws, ...
  • Riak
  • Etorrent
  • RabbitMQ

and so on. When using it, there is a hint worth mentioning though: Make sure you run erl as erl +K true so you get access to the kernel polling. That is, epoll() on Linux, kqueue()/kevent() on BSD and /dev/poll on Solaris. Also note that you can give commands to TCP ports to set their options w.r.t. buffer size and so on. Finally, for certain types of packets, you can have the C-layer parse the packet for you, see erl -man inet and the setopts/2 call. An example would be {packet, 4} which is quite popular.

In general, Erlang has a quite fast I/O sublayer. You can expect it to perform really quickly, even for large complex interactions.

like image 80
I GIVE CRAP ANSWERS Avatar answered Sep 21 '22 14:09

I GIVE CRAP ANSWERS