Skip to content

Commit 299e768

Browse files
committed
Added configurable number of timer procs to start with.
Added "timer_workers = N [use_auto_scaling_profile xxxxx]" Dropped "auto_scaling_timer_profile" Added dynamic counting for the timer processes
1 parent 848f5ea commit 299e768

File tree

5 files changed

+72
-46
lines changed

5 files changed

+72
-46
lines changed

cfg.lex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ DB_MAX_ASYNC_CONNECTIONS "db_max_async_connections"
341341
DISABLE_503_TRANSLATION "disable_503_translation"
342342
AUTO_SCALING_PROFILE "auto_scaling_profile"
343343
AUTO_SCALING_CYCLE "auto_scaling_cycle"
344-
AUTO_SCALING_TIMER_PROFILE "auto_scaling_timer_profile"
344+
TIMER_WORKERS "timer_workers"
345345

346346
MPATH mpath
347347
LOADMODULE loadmodule
@@ -642,8 +642,8 @@ IMPORTFILE "import_file"
642642
return AUTO_SCALING_PROFILE; }
643643
<INITIAL>{AUTO_SCALING_CYCLE} { count(); yylval.strval=yytext;
644644
return AUTO_SCALING_CYCLE; }
645-
<INITIAL>{AUTO_SCALING_TIMER_PROFILE} { count(); yylval.strval=yytext;
646-
return AUTO_SCALING_TIMER_PROFILE; }
645+
<INITIAL>{TIMER_WORKERS} { count(); yylval.strval=yytext;
646+
return TIMER_WORKERS; }
647647

648648
<INITIAL>{MPATH} { count(); yylval.strval=yytext; return MPATH; }
649649
<INITIAL>{LOADMODULE} { count(); yylval.strval=yytext; return LOADMODULE; }

cfg.y

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ static struct multi_str *tmp_mod;
400400
%token LAUNCH_TOKEN
401401
%token AUTO_SCALING_PROFILE
402402
%token AUTO_SCALING_CYCLE
403-
%token AUTO_SCALING_TIMER_PROFILE
403+
%token TIMER_WORKERS
404404

405405

406406

@@ -794,6 +794,13 @@ assign_stm: DEBUG EQUAL snumber
794794
| CHILDREN EQUAL error { yyerror("number expected"); }
795795
| UDP_WORKERS EQUAL NUMBER { udp_workers_no=$3; }
796796
| UDP_WORKERS EQUAL error { yyerror("number expected"); }
797+
| TIMER_WORKERS EQUAL NUMBER {
798+
timer_workers_no=$3;
799+
}
800+
| TIMER_WORKERS EQUAL NUMBER USE_AUTO_SCALING_PROFILE ID{
801+
timer_workers_no=$3;
802+
timer_auto_scaling_profile=$5;
803+
}
797804
| CHECK_VIA EQUAL NUMBER { check_via=$3; }
798805
| CHECK_VIA EQUAL error { yyerror("boolean value expected"); }
799806
| SHM_HASH_SPLIT_PERCENTAGE EQUAL NUMBER {
@@ -1239,11 +1246,6 @@ assign_stm: DEBUG EQUAL snumber
12391246
| AUTO_SCALING_CYCLE EQUAL error {
12401247
yyerror("integer value expected");
12411248
}
1242-
| AUTO_SCALING_TIMER_PROFILE EQUAL ID { auto_scaling_timer_profile=$3;}
1243-
| AUTO_SCALING_TIMER_PROFILE EQUAL error {
1244-
yyerror("ID value expected");
1245-
}
1246-
12471249
| error EQUAL { yyerror("unknown config variable"); }
12481250
;
12491251

pt.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,23 @@ int init_multi_proc_support(void)
7272
/* UDP based listeners */
7373
proc_no += udp_count_processes( &extra );
7474
proc_extra_no += extra;
75+
7576
/* TCP based listeners */
7677
proc_no += tcp_count_processes( &extra );
7778
proc_extra_no += extra;
78-
/* attendent */
79-
proc_no++;
8079

81-
/* info packet UDP receivers */
80+
/* Timer related processes */
81+
proc_no += timer_count_processes( &extra );
82+
proc_extra_no += extra;
8283

83-
/* timer processes */
84-
proc_no += 3 /* timer keeper + timer trigger + dedicated */;
85-
proc_extra_no += 0; /* the dedicated proc may turn into multiple */;
84+
/* attendent */
85+
proc_no++;
8686

8787
/* count the processes requested by modules */
8888
proc_no += count_module_procs(0);
8989

9090
counted_max_processes = proc_no + proc_extra_no;
9191

92-
9392
/* allocate the PID table to accomodate the maximum possible number of
9493
* process we may have during runtime (covering extra procs created
9594
* due auto-scaling) */
@@ -351,13 +350,11 @@ int count_init_child_processes(void)
351350
/* listening children to be create at startup */
352351
ret += udp_count_processes(NULL);
353352
ret += tcp_count_processes(NULL);
353+
ret += timer_count_processes(NULL) - 2/*for keeper & trigger*/;
354354

355355
/* attendent */
356356
ret++;
357357

358-
/* dedicated timer */
359-
ret++;
360-
361358
/* count number of module procs going to be initialised */
362359
ret += count_module_procs(PROC_FLAG_INITCHILD);
363360

timer.c

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,25 @@ static int timer_pipe[2];
7272
static struct scaling_profile *s_profile=NULL;
7373

7474
int timer_fd_out = -1 ;
75-
char *auto_scaling_timer_profile = NULL;
75+
char *timer_auto_scaling_profile = NULL;
76+
int timer_workers_no = 1;
77+
78+
79+
80+
/* counts the number of timer processes to start with; this number may
81+
* change during runtime due auto-scaling */
82+
int timer_count_processes(unsigned int *extra)
83+
{
84+
if (extra) *extra = 0;
85+
86+
if (s_profile && extra) {
87+
/* how many can be forked over th number of procs to start with ?*/
88+
if (s_profile->max_procs > timer_workers_no)
89+
*extra = s_profile->max_procs - timer_workers_no;
90+
}
91+
92+
return 2/*keeper & trigger*/ + timer_workers_no /*workers to start with*/;
93+
}
7694

7795

7896
/* ret 0 on success, <0 on error*/
@@ -122,11 +140,11 @@ int init_timer(void)
122140
/* make visible the "read" part of the pipe */
123141
timer_fd_out = timer_pipe[0];
124142

125-
if (auto_scaling_timer_profile) {
126-
s_profile = get_scaling_profile(auto_scaling_timer_profile);
143+
if (timer_auto_scaling_profile) {
144+
s_profile = get_scaling_profile(timer_auto_scaling_profile);
127145
if ( s_profile==NULL) {
128146
LM_ERR("undefined auto-scaling profile <%s> for timers\n",
129-
auto_scaling_timer_profile);
147+
timer_auto_scaling_profile);
130148
return E_UNSPEC;
131149
}
132150
auto_scaling_enabled = 1;
@@ -762,37 +780,42 @@ static void timer_process_graceful_terminate(int sender, void *param)
762780

763781
int start_timer_extra_processes(int *chd_rank)
764782
{
765-
int p_id;
783+
int i, p_id;
766784

767785
if (auto_scaling_enabled && s_profile &&
768786
create_process_group( TYPE_TIMER, NULL, s_profile ,
769787
fork_dynamic_timer_process, timer_process_graceful_terminate)!=0)
770788
LM_ERR("failed to create group of TIMER processes, "
771789
"auto forking will not be possible\n");
772790

773-
(*chd_rank)++;
774-
if ( (p_id=internal_fork( "Timer handler", 0, TYPE_TIMER))<0 ) {
775-
LM_CRIT("cannot fork Timer handler process\n");
776-
return -1;
777-
} else if (p_id==0) {
778-
/* new Timer process */
779-
/* set a more detailed description */
780-
set_proc_attrs("Timer handler");
781-
if (timer_proc_reactor_init() < 0 ||
782-
init_child(*chd_rank) < 0) {
783-
report_failure_status();
784-
goto error;
785-
}
786-
787-
report_conditional_status( 1, 0);
788-
789-
/* launch the reactor */
790-
reactor_main_loop( 1/*timeout in sec*/, error , );
791-
destroy_worker_reactor();
791+
for( i=0 ; i<timer_workers_no ; i++ ) {
792+
793+
(*chd_rank)++;
794+
if ( (p_id=internal_fork( "Timer handler", 0, TYPE_TIMER))<0 ) {
795+
LM_CRIT("cannot fork Timer handler process\n");
796+
return -1;
797+
} else if (p_id==0) {
798+
/* new Timer process */
799+
/* set a more detailed description */
800+
set_proc_attrs("Timer handler");
801+
if (timer_proc_reactor_init() < 0 ||
802+
init_child(*chd_rank) < 0) {
803+
report_failure_status();
804+
goto error;
805+
}
806+
807+
report_conditional_status( 1, 0);
808+
809+
/* launch the reactor */
810+
reactor_main_loop( 1/*timeout in sec*/, error , );
811+
destroy_worker_reactor();
812+
813+
exit(-1);
814+
}
815+
/*parent*/
792816

793-
exit(-1);
794817
}
795-
/*parent*/
818+
796819
return 0;
797820

798821
/* only from child process */

timer.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ struct os_timer{
8585

8686
extern int timer_fd_out;
8787

88-
extern char *auto_scaling_timer_profile;
88+
extern char *timer_auto_scaling_profile;
89+
90+
extern int timer_workers_no;
91+
92+
int timer_count_processes(unsigned int *extra);
8993

9094
int init_timer(void);
9195

0 commit comments

Comments
 (0)