What is the best, most efficient, Client pool technique with Erlang

后端 未结 3 1879
一向
一向 2021-02-15 15:34

I\'m a real Erlang newbie (started 1 week ago), and I\'m trying to learn this language by creating a small but efficient chat server. (When I say efficient I mean I have 5 serve

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-15 16:27

    I'm doing something similar to your chat program using gproc as a pubsub (similar to the demo on that page). Each client registers as it's id. To find a particular client, you do a lookup on that client id. To subscribe to a client, you add a property to that process of the client id being subscribed to. To publish, you call gproc:send(ClientId,Message). This covers your use case, the more general room based chat as well, and can handle distributed masterless registry of processes.

    I haven't tested to see if it scales to millions, but it uses ets to do the storage and gproc is rock solid code by Ulf Wiger. I wouldn't count on being able to write a better implementation.

提交回复
热议问题