Designing a chat server design pattern with erlang

452 Views Asked by At

I am trying to build a chat server for my social network and this is the design pattern currently I came up with.

look at the user_handler it is a worker process who creates several linked user process and save those process ids to ets table based on login request.

But my problem is if many concurrent request comes from my web server to my user_handler then the processing of those messages will be slow. right?

Like, right now if user id 2 sends message to 3 then i call. user_handler:send_message(SenderId = 2, SendTo = 3, Message) then my user handler grabs the process id of user with id 2 and calls user:send_message(Pid, SendTo = 3, Message). Where user:send_message/3 gets the process id of the user 3 and then check other conditions and finally sends the message to process id of user 3.

Well, I don't think this is a good architecture.

So any suggestion would be appreciable.

Thank you and Sorry for my bad english.

The pattern currently i have created

1

There are 1 best solutions below

3
Pouriya On

Don't save all session info in one process code, just save every session info in its init state and remove its session info in terminate state.

I dont know what are you using, but if you are working on TCP socket and if you worry about accepting new connections, i recommend to use Sockerl, in its server architecture you can have many acceptors accepting connections of one socket server which every acceptor has its own pool for connections that it accepts:

Sockerl