Browse code

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

Daniel-Constantin Mierla authored on 06/01/2012 11:06:02
Showing 4 changed files
... ...
@@ -339,6 +339,7 @@ AVP_PREF	(([ft][rud]?)|g)\.
339 339
 /* config vars. */
340 340
 DEBUG	debug
341 341
 FORK	fork
342
+FORK_DELAY	fork_delay
342 343
 LOGSTDERROR	log_stderror
343 344
 LOGFACILITY	log_facility
344 345
 LOGNAME		log_name
... ...
@@ -702,6 +703,7 @@ IMPORTFILE      "import_file"
702 702
 
703 703
 <INITIAL>{DEBUG}	{ count(); yylval.strval=yytext; return DEBUG_V; }
704 704
 <INITIAL>{FORK}		{ count(); yylval.strval=yytext; return FORK; }
705
+<INITIAL>{FORK_DELAY}	{ count(); yylval.strval=yytext; return FORK_DELAY; }
705 706
 <INITIAL>{LOGSTDERROR}	{ yylval.strval=yytext; return LOGSTDERROR; }
706 707
 <INITIAL>{LOGFACILITY}	{ yylval.strval=yytext; return LOGFACILITY; }
707 708
 <INITIAL>{LOGNAME}	{ yylval.strval=yytext; return LOGNAME; }
... ...
@@ -394,6 +394,7 @@ extern char *finame;
394 394
 /* config vars. */
395 395
 %token DEBUG_V
396 396
 %token FORK
397
+%token FORK_DELAY
397 398
 %token LOGSTDERROR
398 399
 %token LOGFACILITY
399 400
 %token LOGNAME
... ...
@@ -828,6 +829,8 @@ assign_stm:
828 828
 	| DEBUG_V EQUAL error  { yyerror("number  expected"); }
829 829
 	| FORK  EQUAL NUMBER { dont_fork= ! $3; }
830 830
 	| FORK  EQUAL error  { yyerror("boolean value expected"); }
831
+	| FORK_DELAY  EQUAL NUMBER { set_fork_delay($3); }
832
+	| FORK_DELAY  EQUAL error  { yyerror("number expected"); }
831 833
 	| LOGSTDERROR EQUAL NUMBER { if (!config_check) log_stderr=$3; }
832 834
 	| LOGSTDERROR EQUAL error { yyerror("boolean value expected"); }
833 835
 	| LOGFACILITY EQUAL ID {
... ...
@@ -68,6 +68,16 @@
68 68
 static int estimated_proc_no=0;
69 69
 static int estimated_fds_no=0;
70 70
 
71
+/* number of usec to wait before forking a process */
72
+static unsigned int fork_delay = 0;
73
+
74
+unsigned int set_fork_delay(unsigned int v)
75
+{
76
+	unsigned int r;
77
+	r =  fork_delay;
78
+	fork_delay = v;
79
+	return r;
80
+}
71 81
 
72 82
 /* number of known "common" used fds */
73 83
 static int calc_common_open_fds_no()
... ...
@@ -258,6 +268,9 @@ int fork_process(int child_id, char *desc, int make_sock)
258 258
 	int sockfd[2];
259 259
 #endif
260 260
 
261
+	if(unlikely(fork_delay>0))
262
+		sleep_us(fork_delay);
263
+
261 264
 	ret=-1;
262 265
 	#ifdef USE_TCP
263 266
 		sockfd[0]=sockfd[1]=-1;
... ...
@@ -103,4 +103,6 @@ void mem_dump_pkg_cb(str *gname, str *name);
103 103
 int mem_dump_shm_fixup(void *handle, str *gname, str *name, void **val);
104 104
 #endif
105 105
 
106
+unsigned int set_fork_delay(unsigned int v);
107
+
106 108
 #endif