What is the best, most efficient, client pool technology with Erlang

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 ;-)?

+6
source share
3 answers

I am doing something similar to your chat program using gproc as a pubsub (similar to the demo on this page). Each client is registered as an identifier. To find a specific customer, you look at that customer ID. To subscribe to a client, you add a property to this process that the client identifier is subscribed to. To publish, you call gproc: send (ClientId, Message). This covers your use case, a more general conversation-based chat, and can also handle a distributed task-free process registry.

I have not tested whether it estimates millions, but it uses ets to store data, and gproc is the strong Ulf Wiger code. I will not count on you being able to write a better implementation.

+1
source

I am also a little new to Erlang (a couple of months), so I hope this can lead you to the right path :)

First of all, since you are a "beginner", you should know about these sites:

Well, thinking about a fickle database, I would suggest the sets or gb_sets (documentation here ).

If you want perseverance, you should try dets (see the documentation above), but I canโ€™t say anything about effectiveness, so you should investigate this question a bit further.

Learn You Some Erlang has a chapter on structures that says sets better for systems with heavy reading, while gb_sets better for balanced use.

+2
source

Now messaging systems is what everyone wants to do when they come to Erlang, because they naturally mix. However, there are many things that you need to pay attention to before continuing. Messages mainly include the following things: User Registration , User Authentication , Sessions Management , Logging , Message Switching/routing etc

Now, to do all or most of them, you need to have a database, definitely IN-MEMORY, which brings me to Mnesia or ETS Tables . Since you are new to Erlang, I suppose you have not yet mastered working with them. At some point you will need to support Who is communicating with who , Who is available for Chat etc Therefore, you may have to look for things and write something elsewhere.

Another thing is that you did not tell us the Client. Will it be a web client (HTTP), is it a completely new protocol that you run on raw sockets? Whatever the way, you need to master something called: Concurrency in Erlang . If the user connects and is assigned an ID , if your design is A process Per User , then you will need to save the Pids of these processes or register them according to some criteria, but check them again if they die etc. This leads me to OTP and Supervision trees . However, they talk a lot about interacting with the client and server, do you need a network connection etc Or is it just a simple Erlang RPC project that you do for your own edition?



EDIT

Use ETS Tables or use Mnesia RAM tables . Do not think about registering these Pids or Storing them in a list, Array or set. See this solution that was given to this question

+1
source

Source: https://habr.com/ru/post/907399/


All Articles