什么是最好的,最有效的,客户端池技术与Erlang [英] What is the best, most efficient, Client pool technique with Erlang

查看:169
本文介绍了什么是最好的,最有效的,客户端池技术与Erlang的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个真正的Erlang新手(开始1周前),我想通过创建一个小而有效的聊天服务器学习这种语言。 (当我说高效我的意思是我有5个服务器用于压力测试这与成千上万的连接的客户端 - 一百万将是伟大的!)

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 servers used to stress test this with hundreds of thousands connected client - A million would be great !)

我找到一些教程这样做,唯一的事情是,每个教程我发现,是IRC喜欢。如果一个用户发送消息,除发件人之外的所有用户都将收到消息。
我想改变一点,并使用一对一的讨论。

I have find some tutorials doing so, the only thing is, that every tutorial i found, are IRC like. If one user send a message, all user except sender will receive it. I would like to change that a bit, and use one-to-one discussion.

什么是最有效的客户端池搜索连接的用户?
我考虑注册进程,因为它似乎做了我需要的一切,但我真的不认为这是更好的方法。

What would be the most effective client pool for searching a connected user ? I thought about registering the process, because it seems to do everything I need, but I really don't think this is the better way to do it. (Or most pretty way to do it anyway).

有没有人会有任何建议?

Does anyone would have any suggestions doing this ?

EDIT:

每个连接的客户端都受到ID的影响。

Every connected client is affected to an ID.

用户连接后,一个login命令给它的id。
当用户要向另一个发送消息时,消息如下所示

When the user is connected, it first send a login command to give it's id. When an user wants to send a message to another one the message looks like this

[ID-NUMBER] %ID-NUMBER是固定长度

当我要求最有效的客户端池时,在连接的客户端列表上检索/添加/删除一个可能很大(数十万 - 也许是百万)的客户端。

When I ask for "the most effective client pool", I'm actually looking for the fastest way to retrieve/add/delete one client on the connected client list which could potentially be large (hundred of thousands -- maybe millions)

编辑2: / strong>

EDIT 2 :

回答一些问题:



  • 这是我自己的协议

  • 每个客户端是一个生成的Pid

  • 每个客户端的Pid都链接到它自己的监视器(主要是为了调试原因 - 客户端如果断开连接,应该重新连接,它自己从头开始auth)

  • 在开始编码之前,我已经读过一本书,所以我并不掌握Erlang的每一个方面,但我不知道它,我会在需要的时候更多地了解它。

  • 我真正想要的是存储和搜索这些PID以便直接从进程发送消息的最佳方式。

  • I'm using Raw Socket (Using telnet right now to communicate with server) - will probably move to ssl later...
  • It is my own protocol
  • Every Client is a spawned Pid
  • Every Client's Pid is linked to it's own monitor (mostly for debugging reason - The client if disconnected should reconnect by it's own starting auth from scratch)
  • I have read a couple a book before starting coding, So I do not master yet every aspect of Erlang but I'm not unaware of it, I will read more about it when needed I guess.
  • What I'm really looking for is the best way to store and search thoses PIDs to send message directly from process to process.

我应该使用列表编写我自己的搜索客户端函数吗?

Should I write my own search Client function using lists ?

还是应该使用ets?

or should I use ets ?

或者甚至使用register / 2 unregister / 1和whereis / 1来维护我的客户端列表,使用它的唯一id作为atom,它似乎是最简单的方法所以,我真的不知道是否有效,但我很确定这是丑陋的解决方案;-)?

Or even use register/2 unregister/1 and whereis/1 to maintain my client list, using it's unique id as atom, it seems to be the simplest way to do so, I really don't know if it is efficient, but I'm pretty sure this is the ugly solution ;-) ?

推荐答案

我使用 gproc 作为pubsub来做类似于聊天程序的操作(类似于演示)在该页面)。每个客户端注册为它的ID。要查找特定的客户端,您需要对该客户端ID执行查找。要订阅客户端,您需要向订阅的客户端ID的进程添加一个属性。要发布,请调用gproc:send(ClientId,Message)。这涵盖了您的用例,更一般的基于房间的聊天,以及可以处理分布式的无主注册表的进程。

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.

我没有测试,看看它是否扩展数百万,但它使用ets做存储和gproc是岩石固体代码由Ulf Wiger。我不会指望能够编写一个更好的实现。

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.

这篇关于什么是最好的,最有效的,客户端池技术与Erlang的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆