I need to write a server that will receive instructions from other modules and take actions depending on the instructions received. Efficiency is my main concern. So do I use gen_server
or do I write my own server. By "my own server" I mean something like:
-module(myserver).
-export([start/0, loop/0]).
start() ->
spawn(myserver, loop, []).
loop() ->
receive
{From, Msg} -> %Do some action here... ;
message2 -> %Do some action here...;
message3 -> %Do some action here...;
message4 -> %Do some action here...;
.
.
.
_-> ok
end,
loop().
So to use myserver
, I will probably register the process under a registered name while starting it, and then each client will send messages to the server using this pid.
So should I use this method, or instead implement the server using the gen_server
behaviour? Are there any advantages to using gen_server
? But will using gen_server
add any overhead, when compared to myserver
?