I'm a real newbie to Erlang (started 1 week ago) and I'm trying to learn this language by creating a small but effective chat server. (When I say "effective", I mean that I have 5 servers that used stress to test hundreds of thousands of connected clients - a million would be great!)
I have some lessons that do this, the only thing that every tutorial I found is an IRC. If one user sends a message, all users except the sender will receive it. I would like to change this a bit and use an individual discussion.
What will be the most effective client pool for finding a connected user? I was thinking about registering the process because it seems to do everything I need, but I really don't think this is the best way to do this. (Or the most beautiful way to do it anyway).
Does anyone have any suggestions to do this?
EDIT:
Each connected client depends on the identifier.
When a user is connected, he first sends a login command to give him an identifier. When a user wants to send a message to another, the message is as follows:
[ID-NUMBER][Message] %% ID-NUMBER IS A FIXED LENGTH
When I ask for the โmost efficient client poolโ, Iโm actually looking for the fastest way to get / add / remove one client from the list of connected clients, which could potentially be large (hundreds of thousands - maybe millions)
EDIT 2:
To answer some questions:
- I am using Raw Socket (using telnet right now to communicate with the server) - most likely, we will switch to ssl later ...
- This is my own protocol.
- Every customer is a Pid generated
- Each client Pid is connected to it by its own monitor (mainly due to debugging - if the client is disconnected, it must reconnect to it using its own launch from scratch)
- I read a couple of books before starting coding, so I wonโt learn all aspects of Erlang, but I donโt know about it, I will read more about it when necessary. I think so.
- What I'm really looking for is the best way to store and search for POS requests to send a message directly from a process to a process.
Should I write my own Client Client function using lists?
or should i use ets?
Or even use register / 2 unregister / 1 and whereis / 1 to maintain my list of clients using its unique identifier as an atom, this is probably the easiest way to do this, I really don't know if it is efficient, but I'm sure what is this ugly solution ;-)?