共享内存配置
修改/usr/local/opensips/etc/opensips/opensipsctlrc
增加STARTOPTIONS="-m 512",表示修改共享内存的大小为512M
OpenSIPS有自己的内存分配器,服务器内存分配及管理有以下几个特点:
1.限制最大使用的内存范围;
2.内存管理优于系统分配API;
3.通过编译选项,可以选择多个内存分配器。
OpenSIPS采用多进程应用设计方式,服务器通过共享内存屏蔽
进程间通信的复杂问题,对外给用户提供了用于内存管理的API,
系统在初始化时从系统申请最大的可用内存范围,在内部进行分配
和管理,其中OpenSIPS包括两类内存:
1.进程内使用的内存PKG,提供的三个API包括: -M
void *pkg_malloc(unsigned int size);
void pkg_free(void *buf);
void *pkg_realloc(void *buf, unsigned int size);
2.进程间使用的内存SHM -m
void *shm_malloc(unsigned int size);
void shm_free(void *buf);
void *shm_realloc(void *buf, unsigned int size)
进程个数配置
opensips的子进程个数=
+1 //attendent
+udp_children_no //--通过参数 -n 设置,默认8个,也可以通过opensips.cfg的children=4进行配置
+3 // timer process :timer keeper + timer trigger + dedicated
+tcp_children_no+1 --通过参数 -N 3设置,默认8个+TCP main
+count_module_procs 1
使用命令opensipsctl fifo ps可以具体查看各个子进程的Type
root@Develop01:/bin# opensipsctl fifo ps
Process:: ID=0 PID=28403 Type=attendant
Process:: ID=1 PID=28404 Type=MI FIFO
Process:: ID=2 PID=28405 Type=time_keeper
Process:: ID=3 PID=28406 Type=timer
Process:: ID=4 PID=28407 Type=SIP receiver udp:172.18.41.220:5070
Process:: ID=5 PID=28408 Type=SIP receiver udp:172.18.41.220:5070
Process:: ID=6 PID=28409 Type=SIP receiver udp:172.18.41.220:5070
Process:: ID=7 PID=28410 Type=SIP receiver udp:172.18.41.220:5070
Process:: ID=8 PID=28411 Type=TCP receiver
Process:: ID=9 PID=28412 Type=TCP receiver
Process:: ID=10 PID=28413 Type=TCP receiver
Process:: ID=11 PID=28414 Type=TCP receiver
Process:: ID=12 PID=28415 Type=TCP receiver
Process:: ID=13 PID=28416 Type=TCP receiver
Process:: ID=14 PID=28417 Type=TCP receiver
Process:: ID=15 PID=28418 Type=TCP receiver
Process:: ID=16 PID=28419 Type=Timer handler
Process:: ID=17 PID=28420 Type=TCP main
示例
修改配置文件/usr/local/opensips/etc/opensips/opensipsctlrc
STARTOPTIONS="-m 312 -N 3 -n 2"
重启opensips后,可以看到TCP receiver的进程个数减小为4,UDP进程个数减小为2
Process:: ID=0 PID=11768 Type=attendant
Process:: ID=1 PID=11777 Type=MI FIFO
Process:: ID=2 PID=11778 Type=time_keeper
Process:: ID=3 PID=11779 Type=timer
Process:: ID=4 PID=11780 Type=SIP receiver udp:172.18.41.220:5070
Process:: ID=5 PID=11781 Type=SIP receiver udp:172.18.41.220:5070
Process:: ID=6 PID=11782 Type=TCP receiver
Process:: ID=7 PID=11783 Type=TCP receiver
Process:: ID=8 PID=11785 Type=TCP receiver
Process:: ID=9 PID=11786 Type=Timer handler
Process:: ID=10 PID=11787 Type=TCP main
共享内存变总大小变为312M
root@Develop01:/usr/local/opensips/etc/opensips# opensipsctl fifo get_statistics shmem:
shmem:total_size:: 327155712
shmem:used_size:: 3544088
shmem:real_used_size:: 3688680
shmem:max_used_size:: 3939888
shmem:free_size:: 323467032
shmem:fragments:: 4439