手工实现proxy device模块,着重实现如下几个:
1. 启动:“device config.lua”,只识别一个参数,device运行的配置文件,配置文件格式使用lua方式
2. 1:N模型实现,入口一个端口,出口可为多个或一个
3. 所有内部网络节点,支持消息过滤(支持通配符)。如果入口设置了过滤,那么不符合条件的消息,将直接扔掉。出口设置过滤,只有符合消息进入的出口才有可能被发送
4. 符合消息进入的出口,可以使用权重(round_bin)进行合理分配
5. 所有的网络节点,可以通过对应的订阅者获取发布者socket的健康状态,如果健康状态异常,则把该网络节点设置为无效。如果该节点长时间无效,则关闭该节点的socket
6. 高并发、高效率:19个客户端,一个device,两个ser,可以做到每秒近万笔交易(使用zeromq的ipc模式,使用tcp方式略低)。
7. 内存控制:启动后内存占用率是0.1%,运行100万交易后,内存占用率是0.2%
8. 除了一些基本控制外,还提供了高水位、心跳时间、event最大轮训时间等可选配置
9. 可以无缝实现本地运行、分布式部署的需要
10.最大支持128个网络节点、zeromq最多支持分包64(宏定义,可随时修改,太大了,浪费额外内存)
11.所有模块、work可分布式部署,不必强制要求在一台服务器上
12.不申请使用系统信号量、共享内存、系统消息队列等资源。如果发现zeromq有问题,可以适当跟进查看问题所在,2W行的源程序做了如此好的封装,着实不易了。
13.proxy_device模块进行适当扩充,就又可以充当worker服务的主进程存在,收到交易报文后,配置业务动态库直接进行动态加载即可。在该平台上扩充任何新业务,都是开发对应的动态库即可!
遗留问题:
服务端工作者申请任务,默认使用的是load_balance算法,与抢占式相比,性能上可能略有不足,不过可以通过扩充多个ser来做到相对平衡。如果还不满意,就需要使用本地系统的消息队列做中转了。
下面是device设备启动是需要的配置文件样例。可惜优快云不支持LUA语言!
--DEVICE node config
--socket information
-- filter:the filter information
-- address:work socket address
-- sub_address:start or stop the work socket by this socket, its the health check.
-- pub_address:send the health status for myself every special time
-- weight:if two or more back sockets can accept one message, use this to choose which one will be seleted.
-- maxHWM:the max high water mark, the more message will be droped directly.
-- pub_interval:the pub thread send message interval(millisecond) default is 300
-- sub_interval:the sub thread recieve message interval(millisecond) default is 500
socket_infor={
--the first socket is the front socket
{filter=nil,address='L@ipc://12223',pub_address='L@ipc://12233',pub_interval=300},
--the other sockets is the back sockets
{filter=nil,address='L@ipc://12224',sub_address='C@ipc://12234',sub_interval=500,weight=4,maxHWM=1},
{filter=nil,address='L@ipc://12225',sub_address='C@ipc://12235',sub_interval=500,weight=4,maxHWM=1},
}
sysconfig={
log_level=1,
max_wait_time=10000,
}