Module: sip-router Branch: treimann/master_tm-extend-callbacks DELETED Commit: 8033b34c31e5b71a6b0ba2fa6f62d27d8710c716 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=8033b34c...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Timo Reimann sr@foo-lounge.de Date: Fri Jan 6 12:06:02 2012 +0100
core: new cfg parameter fork_delay
- number of usecs to wait before forking a process - default is 0, don't wait - useful in case there are some throttling policies for the system running the sip server (e.g., number of new db connections per second) -- you can introduce delays so that worker processes are not forked at once
---
cfg.lex | 2 ++ cfg.y | 3 +++ pt.c | 13 +++++++++++++ pt.h | 2 ++ 4 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/cfg.lex b/cfg.lex index 0f1be4c..9c96261 100644 --- a/cfg.lex +++ b/cfg.lex @@ -339,6 +339,7 @@ AVP_PREF (([ft][rud]?)|g). /* config vars. */ DEBUG debug FORK fork +FORK_DELAY fork_delay LOGSTDERROR log_stderror LOGFACILITY log_facility LOGNAME log_name @@ -702,6 +703,7 @@ IMPORTFILE "import_file"
<INITIAL>{DEBUG} { count(); yylval.strval=yytext; return DEBUG_V; } <INITIAL>{FORK} { count(); yylval.strval=yytext; return FORK; } +<INITIAL>{FORK_DELAY} { count(); yylval.strval=yytext; return FORK_DELAY; } <INITIAL>{LOGSTDERROR} { yylval.strval=yytext; return LOGSTDERROR; } <INITIAL>{LOGFACILITY} { yylval.strval=yytext; return LOGFACILITY; } <INITIAL>{LOGNAME} { yylval.strval=yytext; return LOGNAME; } diff --git a/cfg.y b/cfg.y index fb494ea..223d7ba 100644 --- a/cfg.y +++ b/cfg.y @@ -394,6 +394,7 @@ extern char *finame; /* config vars. */ %token DEBUG_V %token FORK +%token FORK_DELAY %token LOGSTDERROR %token LOGFACILITY %token LOGNAME @@ -828,6 +829,8 @@ assign_stm: | DEBUG_V EQUAL error { yyerror("number expected"); } | FORK EQUAL NUMBER { dont_fork= ! $3; } | FORK EQUAL error { yyerror("boolean value expected"); } + | FORK_DELAY EQUAL NUMBER { set_fork_delay($3); } + | FORK_DELAY EQUAL error { yyerror("number expected"); } | LOGSTDERROR EQUAL NUMBER { if (!config_check) log_stderr=$3; } | LOGSTDERROR EQUAL error { yyerror("boolean value expected"); } | LOGFACILITY EQUAL ID { diff --git a/pt.c b/pt.c index 68842e6..7764a94 100644 --- a/pt.c +++ b/pt.c @@ -68,6 +68,16 @@ static int estimated_proc_no=0; static int estimated_fds_no=0;
+/* number of usec to wait before forking a process */ +static unsigned int fork_delay = 0; + +unsigned int set_fork_delay(unsigned int v) +{ + unsigned int r; + r = fork_delay; + fork_delay = v; + return r; +}
/* number of known "common" used fds */ static int calc_common_open_fds_no() @@ -258,6 +268,9 @@ int fork_process(int child_id, char *desc, int make_sock) int sockfd[2]; #endif
+ if(unlikely(fork_delay>0)) + sleep_us(fork_delay); + ret=-1; #ifdef USE_TCP sockfd[0]=sockfd[1]=-1; diff --git a/pt.h b/pt.h index d2af6ac..c3bd901 100644 --- a/pt.h +++ b/pt.h @@ -103,4 +103,6 @@ void mem_dump_pkg_cb(str *gname, str *name); int mem_dump_shm_fixup(void *handle, str *gname, str *name, void **val); #endif
+unsigned int set_fork_delay(unsigned int v); + #endif