Skip to content

Commit

Permalink
Small rework of the processes groups
Browse files Browse the repository at this point in the history
Better use types to tag the processes.
When creating a proc group, push also the min/max for procs auto-scaling
  • Loading branch information
bogdan-iancu committed Feb 3, 2019
1 parent 30a42d7 commit d13e7a7
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 22 deletions.
4 changes: 2 additions & 2 deletions net/net_tcp.c
Expand Up @@ -1853,7 +1853,7 @@ int tcp_start_processes(int *chd_rank, int *startup_done)
}

(*chd_rank)++;
pid=internal_fork("SIP receiver TCP", 0, GROUP_TCP);
pid=internal_fork("SIP receiver TCP", 0, TYPE_TCP);
if (pid<0){
LM_ERR("fork failed\n");
goto error;
Expand Down Expand Up @@ -1916,7 +1916,7 @@ int tcp_start_listener(void)
return 0;

/* start the TCP manager process */
if ( (pid=internal_fork( "TCP main", 0, GROUP_NONE))<0 ) {
if ( (pid=internal_fork( "TCP main", 0, TYPE_NONE))<0 ) {
LM_CRIT("cannot fork tcp main process\n");
goto error;
}else if (pid==0){
Expand Down
5 changes: 3 additions & 2 deletions net/net_udp.c
Expand Up @@ -343,14 +343,15 @@ int udp_start_processes(int *chd_rank, int *startup_done)
for(si=protos[p].listeners; si ; si=si->next ) {

if (enable_dynamic_workers &&
register_process_group( GROUP_UDP, si, NULL)!=0)
create_process_group( TYPE_UDP, si, si->workers_min,
si->workers_max, NULL)!=0)
LM_ERR("failed to create group of UDP processes for <%.*s>, "
"auto forking will not be possible\n",
si->name.len, si->name.s);

for (i=0;i<si->workers;i++) {
(*chd_rank)++;
if ( (pid=internal_fork( "UDP receiver", 0, GROUP_UDP))<0 ) {
if ( (pid=internal_fork( "UDP receiver", 0, TYPE_UDP))<0 ) {
LM_CRIT("cannot fork UDP process\n");
goto error;
} else if (pid==0) {
Expand Down
21 changes: 15 additions & 6 deletions pt.c
Expand Up @@ -170,7 +170,7 @@ static int register_process_stats(int process_no)
/* This function is to be called only by the main process!
* */
pid_t internal_fork(char *proc_desc, unsigned int flags,
enum processes_group group)
enum process_type type)
{
#define CHILD_COUNTER_STOP 656565656
static int process_counter = 1;
Expand Down Expand Up @@ -224,7 +224,7 @@ pid_t internal_fork(char *proc_desc, unsigned int flags,
process_no = process_counter;
pt[process_no].pid = getpid();
pt[process_no].flags = flags;
pt[process_no].group = group;
pt[process_no].type = type;
process_counter = CHILD_COUNTER_STOP;
/* each children need a unique seed */
seed_child(seed);
Expand Down Expand Up @@ -285,16 +285,20 @@ int count_init_children(int flags)


struct process_group {
enum processes_group group;
enum process_type type;
struct socket_info *si_filter;
fork_new_process_f *fork_func;
unsigned int max_procs;
unsigned int min_procs;
struct process_group *next;
};

struct process_group *pg_head = NULL;

int register_process_group(enum processes_group group,
struct socket_info *si_filter, fork_new_process_f *f)
int create_process_group(enum process_type type,
struct socket_info *si_filter,
unsigned int min_procs, unsigned int max_procs,
fork_new_process_f *f)
{
struct process_group *pg, *it;

Expand All @@ -304,8 +308,13 @@ int register_process_group(enum processes_group group,
return -1;
}

pg->group = group;
LM_DBG("registering group of processes type %d, socket filter %p, "
"process range [%d,%d]\n", type, si_filter, min_procs, max_procs );

pg->type = type;
pg->si_filter = si_filter;
pg->max_procs = max_procs;
pg->min_procs = min_procs;
pg->fork_func = f;
pg->next = NULL;

Expand Down
16 changes: 9 additions & 7 deletions pt.h
Expand Up @@ -36,14 +36,14 @@

#define MAX_PT_DESC 128

enum processes_group { GROUP_NONE=0, GROUP_UDP, GROUP_TCP,
GROUP_TIMER, GROUP_MODULE};
enum process_type { TYPE_NONE=0, TYPE_UDP, TYPE_TCP,
TYPE_TIMER, TYPE_MODULE};

struct process_table {
/* the UNIX pid of this process */
int pid;
/* the group this proc is part of - optional, used by dynamic forking */
enum processes_group group;
/* the type/group of this process - optional, used by dynamic forking */
enum process_type type;
/* name/description of the process (null terminated) */
char desc[MAX_PT_DESC];
/* various flags describing properties of this process */
Expand Down Expand Up @@ -86,7 +86,7 @@ int count_init_children(int flags);
#define counted_processes (counted_processes_p?*counted_processes_p:0)

pid_t internal_fork(char *proc_desc, unsigned int flags,
enum processes_group group);
enum process_type type);

/* return processes pid */
inline static int my_pid(void)
Expand All @@ -110,8 +110,10 @@ inline static int get_process_ID_by_PID(pid_t pid)

typedef int (fork_new_process_f)(void *);

int register_process_group(enum processes_group group,
struct socket_info *si_filter, fork_new_process_f *f);
int create_process_group(enum process_type type,
struct socket_info *si_filter,
unsigned int min_procs, unsigned int max_procs,
fork_new_process_f *f);


#endif
2 changes: 1 addition & 1 deletion sr_module.c
Expand Up @@ -769,7 +769,7 @@ int start_module_procs(void)
m->exports->procs[n].name, l, m->exports->name);
x = internal_fork( m->exports->procs[n].name,
((m->exports->procs[n].flags&PROC_FLAG_HAS_IPC) ?
0 : OSS_FORK_NO_IPC)|OSS_FORK_IS_EXTRA, GROUP_MODULE );
0 : OSS_FORK_NO_IPC)|OSS_FORK_IS_EXTRA, TYPE_MODULE );
if (x<0) {
LM_ERR("failed to fork process \"%s\"/%d for module %s\n",
m->exports->procs[n].name, l, m->exports->name);
Expand Down
8 changes: 4 additions & 4 deletions timer.c
Expand Up @@ -586,7 +586,7 @@ int start_timer_processes(void)
*/

if ( (pid=internal_fork("time_keeper",
OSS_FORK_NO_IPC|OSS_FORK_NO_LOAD, GROUP_NONE))<0 ) {
OSS_FORK_NO_IPC|OSS_FORK_NO_LOAD, TYPE_NONE))<0 ) {
LM_CRIT("cannot fork time keeper process\n");
goto error;
} else if (pid==0) {
Expand All @@ -599,7 +599,7 @@ int start_timer_processes(void)

/* fork a timer-trigger process */
if ( (pid=internal_fork("timer", OSS_FORK_NO_IPC|OSS_FORK_NO_LOAD,
GROUP_NONE))<0 ) {
TYPE_NONE))<0 ) {
LM_CRIT("cannot fork timer process\n");
goto error;
} else if (pid==0) {
Expand Down Expand Up @@ -678,12 +678,12 @@ int start_timer_extra_processes(int *chd_rank)
pid_t pid;

if (enable_dynamic_workers &&
register_process_group( GROUP_TIMER, NULL, NULL)!=0)
create_process_group( TYPE_TIMER, NULL, 0, 0,NULL)!=0)
LM_ERR("failed to create group of TIMER processes, "
"auto forking will not be possible\n");

(*chd_rank)++;
if ( (pid=internal_fork( "Timer handler", 0, GROUP_TIMER))<0 ) {
if ( (pid=internal_fork( "Timer handler", 0, TYPE_TIMER))<0 ) {
LM_CRIT("cannot fork Timer handler process\n");
return -1;
} else if (pid==0) {
Expand Down

0 comments on commit d13e7a7

Please sign in to comment.