Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do Erlang timers scale?

Tags:

erlang

timer

In my websocket server developed with Erlang, I would like to use a timer (start_timer/3), for each connection, to terminate the connection if the timeout elapses without receiving a "ping" from the client.

Do Erlang timers scale well, assuming I will have a large number of client connestions?

like image 881
Enrico Detoma Avatar asked Oct 20 '12 14:10

Enrico Detoma


People also ask

How do you sleep in Erlang?

call sleep(Time) -> ok to suspend the process calling this function for Time amount of milliseconds. Save this answer.

What are the functions of timer module?

The Timer module allows you to wait for something to happen, and to timeout (which throws an exception) if that something doesn't happen quickly enough.


1 Answers

What is a large number of connections? Erlangs VM uses a timer wheel internally to handle the timers so it scales pretty well up to some thousand connections. Then you might run into trouble.

Usually the trick is to group pids together on timers. This is also what kernels tend to do. If for instance you have a timer that has to awake in 200ms you schedule yourself ahead of time not on the next, but the next 200ms timer again. This means you will wait at least 200ms and perhaps 400ms, 300ms being typical. By approximating timers like this, you are able to run many more since you can have a single timer wake up large numbers of processes in one go. But depending on the timer frequency and amounts of timers a standard send_after/3 may be enough.

In any case, I would start by assuming it can scale and then handle the problem if it can't by doing approximate timing like envisioned above.

like image 142
I GIVE CRAP ANSWERS Avatar answered Sep 24 '22 17:09

I GIVE CRAP ANSWERS