近日研究了下mod_event_socket源码,发现socket用的是poll,并且接收到的时候没有用到缓冲,严重影响系统性能,有必要进行数据包的收发进行优化处理,保证通讯的畅通。本人通过一下方式优化,系统并发性能有着显著的提升。
一、数据报字段过滤功能
<configuration name="event_socket.conf" description="Socket Client">
<settings>
<param name="nat-map" value="false"/>
<param name="listen-ip" value="127.0.0.1"/>
<param name="listen-port" value="8021"/>
<param name="password" value="ClueCon"/>
<!--<param name="apply-inbound-acl" value="lan"/>-->
<param name="event-whitelists" value=""/> <!-- 事件白名单,全部字段写入 -->
<param name="valid-variant-prefixs" value=""/> <!-- 字段前缀匹配白名单,字段写入 -->
<param name="valid-variant-includes" value=""/> <!-- 字段包含匹配白名单,字段写入 -->
<param name="invalid-variant-prefixs" value=""/> <!-- 字段前缀匹配黑名单,字段去除 -->
<param name="invalid-variant-includes" value=""/> <!-- 字段包含匹配黑名单,字段去除 -->
</settings>
</configuration>
二、改poll为epoll收发数据包
源代码如下:
static switch_status_t read_packet(listener_t *listener, switch_event_t **event, uint32_t seconds)
{
char buf[65536] = "";
switch_status_t status = SWITCH_STATUS_SUCCESS;
int count = 0;
uint32_t elapsed = 0;
time_t start = 0;
uint8_t do_sleep = 1;
void *pop;
switch_size_t buf_len = sizeof(buf);
switch_channel_t *channel = NULL;
*event = NULL;
start = switch_epoch_time_now(NULL);
if (prefs.done) {
switch_goto_status(SWITCH_STATUS_FALSE, end);
}
if (listener->session) {
channel = switch_core_session_get_channel(listener->session);
}
while (listener->sock && !prefs.done) {
char *packet = NULL, *val = NULL;
switch_size_t len, packet_len, clen = 0, total_len = 0;
len = switch_buffer_ignore_space(listener->re

本文详细介绍了优化mod_event_socket模块性能的方法,包括使用epoll替代poll进行数据包收发,添加接收缓冲区以提高效率,以及实现数据报字段过滤功能。通过这些优化,系统并发性能得到显著提升。
最低0.47元/天 解锁文章
343





