Browse Source

Add two options + status2str function

Add a -t --timeout and a -f --fast-spawn option for further commit
Yann Weber 4 years ago
parent
commit
5ad51d95fb
2 changed files with 95 additions and 7 deletions
  1. 28
    5
      include/conf.h
  2. 67
    2
      src/conf.c

+ 28
- 5
include/conf.h View File

@@ -44,7 +44,11 @@
44 44
 
45 45
 /**@defgroup ret_status Function & process return status
46 46
  */
47
+/**@ingroup ret_status */
48
+#define EXIT_PYERR 4
49
+/**@ingroup ret_status */
47 50
 #define PYFCGI_TIMEOUT 8
51
+/**@ingroup ret_status */
48 52
 #define PYFCGI_ERR 16
49 53
 /**@ingroup ret_status */
50 54
 #define PYFCGI_WORKER_FAIL 32
@@ -53,11 +57,9 @@
53 57
 /**@ingroup ret_status */
54 58
 #define PYFCGI_FATAL 128
55 59
 
56
-#define EXIT_PYERR 42
57
-
58 60
 #define PYFCGI_NAME "spawn-fcgi [OPTIONS] -- pyfcgi"
59 61
 
60
-#define PYFCGI_SHORT_OPT "Ce:E:Aw:W:m:L:SvVh"
62
+#define PYFCGI_SHORT_OPT "Ce:E:Aw:W:m:ft:L:SvVh"
61 63
 
62 64
 #define PYFCGI_LONG_OPT { \
63 65
 	{"config", required_argument, 0, 'C'},\
@@ -67,6 +69,8 @@
67 69
 	{"min-worker", required_argument, 0, 'w'},\
68 70
 	{"max-worker", required_argument, 0, 'W'},\
69 71
 	{"max-request", required_argument, 0, 'm'},\
72
+	{"fast-spawn", no_argument, 0, 'f'},\
73
+	{"timeout", required_argument, 0, 't'},\
70 74
 	{"log", required_argument, 0, 'L'},\
71 75
 	{"syslog", no_argument, 0, 'S'},\
72 76
 	{"pid-file", required_argument, 0, 'P'},\
@@ -84,6 +88,8 @@
84 88
 	{"Minimum worker in the pool", "INT"},\
85 89
 	{"Maximum worker in the pool", "INT"},\
86 90
 	{"Request count after wich the worker is restarted (if 0 never restart)", "INT"},\
91
+	{"If not given there is at least 1s between 2 child creation, else childs may be spawned in small burst", NULL},\
92
+	{"Request timeout (before worker restarts)", "SECONDS"},\
87 93
 	{"Add a logfile using syntax : 'LOGFILE[;FILT][;FMT]'", "LOGGER_SPEC"},\
88 94
 	{"Use syslog for logging", NULL},\
89 95
 	{"Create a PID file", "FILENAME"},\
@@ -181,15 +187,26 @@ struct pyfcgi_conf_s
181 187
 	 * @ingroup conf_glob */
182 188
 	int max_reqs;
183 189
 
190
+	//Pool handling conf
191
+	/**@brief Idle timeout : starts GC workers after Xs idle */
192
+	time_t worker_gc_timeout;
193
+	/**@brief Fast spawn : if 1 spawn more childs faster
194
+	 *
195
+	 * When not activated there is at least 1s between 2 child creation,
196
+	 * else child are created in small burst ( ~2 childs burst)
197
+	 */
198
+	short worker_fast_spawn;
199
+
200
+
201
+	//watchdogs config
184 202
 	/**@brief Worker timeout in seconds (if 0 no timeout)*/
185 203
 	time_t worker_timeout;
186
-
187 204
 	/**@brief Pool timeout in seconds (if 0 no timeout)*/
188 205
 	time_t pool_timeout;
189 206
 
207
+	// logger config
190 208
 	/**@brief 0 is silent 1 means logs to stderr */
191 209
 	short verbosity;
192
-
193 210
 	/**@brief Logger configuration
194 211
 	 * @ingroupe conf_glob */
195 212
 	pyfcgi_conf_logger_t logs;
@@ -233,4 +250,10 @@ int pyfcgi_wd_stop();
233 250
 /**@brief Watchdog default signal handler */
234 251
 void pyfcgi_wd_default_sighandler(int signum);
235 252
 
253
+/**@brief Return a string representing a status
254
+ * @param int status
255
+ * @return a char* that should be freed
256
+ */
257
+char *status2str(int);
258
+
236 259
 #endif

+ 67
- 2
src/conf.c View File

@@ -24,7 +24,7 @@ void usage()
24 24
 			default: //no_argument
25 25
 				dprintf(2, "\n");
26 26
 		}
27
-		printf("\t\t%s\n\n", help[i][0]);
27
+		dprintf(2, "\t\t%s\n", help[i][0]);
28 28
 		i++;
29 29
 	}
30 30
 	dprintf(2, "%s", PYFCGI_HELP_TEXT);
@@ -48,6 +48,7 @@ void default_conf()
48 48
 	PyFCGI_conf.verbosity = 0;
49 49
 	PyFCGI_conf.pool_timeout = 5;
50 50
 	PyFCGI_conf.worker_timeout = 3;
51
+	PyFCGI_conf.worker_gc_timeout = 5;
51 52
 }
52 53
 
53 54
 int parse_args(int argc, char *argv[])
@@ -96,6 +97,16 @@ int parse_args(int argc, char *argv[])
96 97
 					PyFCGI_conf.max_reqs = 0;
97 98
 				}
98 99
 				break;
100
+			case 'f':
101
+				PyFCGI_conf.worker_fast_spawn = 1;
102
+				break;
103
+			case 't':
104
+				PyFCGI_conf.worker_timeout = atoi(optarg);
105
+				if(PyFCGI_conf.worker_timeout < 0)
106
+				{
107
+					PyFCGI_conf.worker_timeout = 0;
108
+				}
109
+				break;
99 110
 			case 'L':
100 111
 				if(parse_optlog(optarg))
101 112
 				{
@@ -281,7 +292,7 @@ int pyfcgi_wd_arm()
281 292
 	}
282 293
 
283 294
 	timeout.it_value.tv_sec = (time_t)(timeout.it_value.tv_sec * 1.5);
284
-	timeout.it_value.tv_nsec = (long)(timeout.it_value.tv_nsec * 1.5);
295
+	timeout.it_value.tv_nsec = 500000000;
285 296
 	timeout.it_interval = timeout.it_value;
286 297
 
287 298
 	if(timer_settime(context->wd_timerkill, 0, &timeout, NULL) < 0)
@@ -368,3 +379,57 @@ void pyfcgi_wd_default_sighandler(int signum)
368 379
 	exit(PYFCGI_TIMEOUT);
369 380
 }
370 381
 
382
+char *status2str(int status)
383
+{
384
+	char buff[1024], *buffptr;
385
+	size_t left = 1024, ret;
386
+	short reason;
387
+
388
+	reason = 0;
389
+	buffptr = buff;
390
+	
391
+	if(status & (PYFCGI_WORKER_FAIL | PYFCGI_MASTER_FAIL))
392
+	{
393
+		buffptr += ret = snprintf(buffptr, left, "%s ",
394
+			(status & PYFCGI_WORKER_FAIL)?"Worker":"Master");
395
+		left -= ret;
396
+		status &= ((0xFFFF) ^ (PYFCGI_WORKER_FAIL | PYFCGI_MASTER_FAIL));
397
+	}
398
+	if(status & PYFCGI_FATAL)
399
+	{
400
+		buffptr += ret = snprintf(buffptr, left, "fatal ");
401
+		left -= ret;
402
+		status ^= PYFCGI_FATAL;
403
+	}
404
+	if(status & EXIT_PYERR)
405
+	{
406
+		buffptr += ret = snprintf(buffptr, left, "Python");
407
+		left -= ret;
408
+		status ^= EXIT_PYERR;
409
+	}
410
+	if( status & PYFCGI_TIMEOUT)
411
+	{
412
+		buffptr += ret = snprintf(buffptr, left, "Timeout");
413
+		left -= ret;
414
+		reason = 1;
415
+		status ^= PYFCGI_TIMEOUT;
416
+	}
417
+	if(status & PYFCGI_ERR)
418
+	{
419
+		buffptr += ret = snprintf(buffptr, left, "Error");
420
+		left -= ret;
421
+		reason = 1;
422
+		status ^= PYFCGI_ERR;
423
+	}
424
+	if(!reason)
425
+	{
426
+		buffptr += ret = snprintf(buffptr, left, "Failure");
427
+		left -= ret;
428
+	}
429
+	if(status)
430
+	{
431
+		buffptr += ret = snprintf(buffptr, left, "%d", status);
432
+		left -= ret;
433
+	}
434
+	return strndup(buff, 1024);
435
+}

Loading…
Cancel
Save