4

Perhaps the Question isnt that simple to answer... but what is your opinion? Should i either use Non-Blocking approaches (libevent for exampe) or use erlang light weight processes to:

  1. Achieve as much connections as possible at a given amount of RAM
  2. Achieve as much throughput as possible at a given amount of CPU

The background is, that i am planing to code a pub/sub-Server and i cannot decide which approach i should use.

Filipe Santos
  • 1,629
  • 3
  • 18
  • 27

2 Answers2

2

Under the hood, the Erlang VM uses non-blocking IO. If you Erlang light weight process blocks, the VM does not really do a kernel level thread context switch. Most of the time, it will just wake up another LWP on the same OS thread (thus, its not "blocking" in the right sense of the word).

You can even start the vm using the +A argument and specify how many IO event loop threads you would like to allocate (AFAIK, Node.js is still single-threaded and if a callback function hangs, ur VM is done for)

arun_suresh
  • 2,875
  • 20
  • 20
2

One article about making A Million-user Comet Application with Mochiweb you can read there. But I think stability, flexibility and maintainability will be more important most of time. Keeping this in mind I would not think about anything other than Erlang even there will be some better performing solution.

Hynek -Pichi- Vychodil
  • 26,174
  • 5
  • 52
  • 73
  • I already know this article and its really amazing what he achieved. I also know the advantages of Erlang (Hot Exchange, Scalability, etc.) But my highest priority is Performance and Ram per Connection and my "feeling" say to me, that using one single event loop (libevent) which handles all the connections is better instead of spawning Erlang Processes for each connection? – Filipe Santos May 12 '11 at 12:44
  • If you spawn a process each time you receive an event to process it, then what is the point of having single event loop? If you don't, then you have single-threaded application (well, almost, system processes are still multi-threaded), performance will probably suffer on multi-core machines. – Victor Moroz May 12 '11 at 14:57
  • 1
    @Filipe Santos: Even if you use single event loop you will have to keep some sort of state of each connection. Amount of RAM used by this state will be comparable (surely not order of magnitude less) to memory consumed by one Erlang process. But you will gain multicore support, faster development and so and so. I would make Erlang POC, then measure, then optimise, then rewrite parts to NIF, then measure again, then rewrite to own event loop, then ... I bet you will be happy with Erlang POC and concentrate your effort to features. – Hynek -Pichi- Vychodil May 13 '11 at 07:53