Ver Fonte

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 há 13 anos atrás
pai
commit
c2429a58e6
4 ficheiros alterados com 20 adições e 0 exclusões
  1. 2 0
      cfg.lex
  2. 3 0
      cfg.y
  3. 13 0
      pt.c
  4. 2 0
      pt.h

+ 2 - 0
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; }

+ 3 - 0
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 {

+ 13 - 0
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;

+ 2 - 0
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