Browse Source

MT#56374 add `poller-size` config var

Change-Id: Ibd6a42f5cc5b261ce95fe0231ec78e55bd66ac31
pull/1701/head
Richard Fuchs 2 years ago
parent
commit
0be5b73887
4 changed files with 24 additions and 4 deletions
  1. +7
    -0
      docs/rtpengine.md
  2. +4
    -0
      lib/auxlib.c
  3. +1
    -0
      lib/auxlib.h
  4. +12
    -4
      lib/poller.c

+ 7
- 0
docs/rtpengine.md View File

@ -370,6 +370,13 @@ call to inject-DTMF won't be sent to __\-\-dtmf-log-dest=__ or __\-\-listen-tcp-
So for example, if this option is set to 4, in total 8 threads will be So for example, if this option is set to 4, in total 8 threads will be
launched. launched.
- __\-\-poller-size=__*INT*
Set the maximum number of event items (file descriptors) to retrieve from
the underlying system poll mechanism per iteration. Defaults to 128. A
lower number can lead to improved load-balancing among a large number of
threads.
- __\-\-thread-stack=__*INT* - __\-\-thread-stack=__*INT*
Set the stack size of each thread to the value given in kB. Defaults to 2048 Set the stack size of each thread to the value given in kB. Defaults to 2048


+ 4
- 0
lib/auxlib.c View File

@ -13,6 +13,7 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <sys/resource.h> #include <sys/resource.h>
#include <sys/epoll.h>
#include "log.h" #include "log.h"
#include "loglib.h" #include "loglib.h"
@ -212,6 +213,7 @@ void config_load(int *argc, char ***argv, GOptionEntry *app_entries, const char
{ "pidfile", 'p', 0, G_OPTION_ARG_FILENAME, &rtpe_common_config_ptr->pidfile, "Write PID to file", "FILE" }, { "pidfile", 'p', 0, G_OPTION_ARG_FILENAME, &rtpe_common_config_ptr->pidfile, "Write PID to file", "FILE" },
{ "foreground", 'f', 0, G_OPTION_ARG_NONE, &rtpe_common_config_ptr->foreground, "Don't fork to background", NULL }, { "foreground", 'f', 0, G_OPTION_ARG_NONE, &rtpe_common_config_ptr->foreground, "Don't fork to background", NULL },
{ "thread-stack", 0,0, G_OPTION_ARG_INT, &rtpe_common_config_ptr->thread_stack, "Thread stack size in kB", "INT" }, { "thread-stack", 0,0, G_OPTION_ARG_INT, &rtpe_common_config_ptr->thread_stack, "Thread stack size in kB", "INT" },
{ "poller-size", 0,0, G_OPTION_ARG_INT, &rtpe_common_config_ptr->poller_size, "Max poller items per iteration", "INT" },
{ "evs-lib-path", 0,0, G_OPTION_ARG_FILENAME, &rtpe_common_config_ptr->evs_lib_path, "Location of .so for 3GPP EVS codec", "FILE" }, { "evs-lib-path", 0,0, G_OPTION_ARG_FILENAME, &rtpe_common_config_ptr->evs_lib_path, "Location of .so for 3GPP EVS codec", "FILE" },
{ NULL, } { NULL, }
}; };
@ -387,6 +389,8 @@ out:
if (rtpe_common_config_ptr->thread_stack == 0) if (rtpe_common_config_ptr->thread_stack == 0)
rtpe_common_config_ptr->thread_stack = 2048; rtpe_common_config_ptr->thread_stack = 2048;
if (rtpe_common_config_ptr->poller_size <= 0)
rtpe_common_config_ptr->poller_size = 128;
return; return;


+ 1
- 0
lib/auxlib.h View File

@ -31,6 +31,7 @@ struct rtpengine_common_config {
char *pidfile; char *pidfile;
int foreground; int foreground;
int thread_stack; int thread_stack;
int poller_size;
int max_log_line_length; int max_log_line_length;
char *evs_lib_path; char *evs_lib_path;
}; };


+ 12
- 4
lib/poller.c View File

@ -222,17 +222,17 @@ int poller_del_item(struct poller *p, int fd) {
} }
static int poller_poll(struct poller *p, int timeout) {
static int poller_poll(struct poller *p, int timeout, struct epoll_event *evs, int poller_size) {
int ret, i; int ret, i;
struct poller_item_int *it; struct poller_item_int *it;
struct epoll_event evs[128], *ev, e;
struct epoll_event *ev, e;
if (!p) if (!p)
return -1; return -1;
errno = 0; errno = 0;
thread_cancel_enable(); thread_cancel_enable();
ret = epoll_wait(p->fd, evs, sizeof(evs) / sizeof(*evs), timeout);
ret = epoll_wait(p->fd, evs, poller_size, timeout);
thread_cancel_disable(); thread_cancel_disable();
mutex_lock(&p->lock); mutex_lock(&p->lock);
@ -378,10 +378,18 @@ void poller_loop(void *d) {
void poller_loop2(void *d) { void poller_loop2(void *d) {
struct poller *p = d; struct poller *p = d;
int poller_size = rtpe_common_config_ptr->poller_size;
struct epoll_event *evs;
evs = g_malloc(sizeof(*evs) * poller_size);
thread_cleanup_push(g_free, evs);
while (!rtpe_shutdown) { while (!rtpe_shutdown) {
int ret = poller_poll(p, thread_sleep_time);
int ret = poller_poll(p, thread_sleep_time, evs, poller_size);
if (ret < 0) if (ret < 0)
usleep(20 * 1000); usleep(20 * 1000);
} }
thread_cleanup_pop(true);
} }

Loading…
Cancel
Save