kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 548068d2a050cf3f0a9c7674657beda7b9d03930
parent c55036bfec36273d1b86e45ab24a84e40ceaacd5
Author: Joris Vink <joris@coders.se>
Date:   Wed, 14 Mar 2018 13:41:17 +0100

Add http_request_ms configuration option.

This option allows a user to finetune the number of milliseconds
a worker process will max spend inside the http_process() loop.

By default this is 10ms.

Diffstat:
conf/kore.conf.example | 9+++++++--
includes/http.h | 5++++-
src/config.c | 16++++++++++++++++
src/http.c | 13++++++++-----
4 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/conf/kore.conf.example b/conf/kore.conf.example @@ -92,13 +92,18 @@ workers 4 # all responses. Parameter is the age. # (Set to 0 to disable sending this header). # -# http_request_limit Limit the number of requests Kore processes -# in a single event loop. +# http_request_limit Limit the number of HTTP requests workers +# can queue up. +# +# http_request_ms The number of milliseconds workers can max +# spend inside the HTTP processing loop. +# #http_header_max 4096 #http_body_max 1024000 #http_keepalive_time 0 #http_hsts_enable 31536000 #http_request_limit 1000 +#http_request_ms 10 #http_body_disk_offload 0 #http_body_disk_path tmp_files diff --git a/includes/http.h b/includes/http.h @@ -43,6 +43,7 @@ extern "C" { #define HTTP_COOKIE_BUFSIZE 1024 #define HTTP_DATE_MAXSIZE 255 #define HTTP_REQUEST_LIMIT 1000 +#define HTTP_REQUEST_MS 10 #define HTTP_BODY_DISK_PATH "tmp_files" #define HTTP_BODY_DISK_OFFLOAD 0 #define HTTP_BODY_PATH_MAX 256 @@ -194,6 +195,7 @@ struct http_request { u_int8_t fsm_state; u_int16_t flags; u_int16_t status; + u_int64_t ms; u_int64_t start; u_int64_t end; u_int64_t total; @@ -235,8 +237,9 @@ struct http_state { int (*cb)(struct http_request *); }; -extern u_int16_t http_header_max; extern size_t http_body_max; +extern u_int16_t http_header_max; +extern u_int32_t http_request_ms; extern u_int64_t http_hsts_enable; extern u_int16_t http_keepalive_time; extern u_int32_t http_request_limit; diff --git a/src/config.c b/src/config.c @@ -82,6 +82,7 @@ static int configure_http_header_max(char *); static int configure_http_body_max(char *); static int configure_http_hsts_enable(char *); static int configure_http_keepalive_time(char *); +static int configure_http_request_ms(char *); static int configure_http_request_limit(char *); static int configure_http_body_disk_offload(char *); static int configure_http_body_disk_path(char *); @@ -152,6 +153,7 @@ static struct { { "http_body_max", configure_http_body_max }, { "http_hsts_enable", configure_http_hsts_enable }, { "http_keepalive_time", configure_http_keepalive_time }, + { "http_request_ms", configure_http_request_ms }, { "http_request_limit", configure_http_request_limit }, { "http_body_disk_offload", configure_http_body_disk_offload }, { "http_body_disk_path", configure_http_body_disk_path }, @@ -688,6 +690,20 @@ configure_http_keepalive_time(char *option) } static int +configure_http_request_ms(char *option) +{ + int err; + + http_request_ms = kore_strtonum(option, 10, 0, UINT_MAX, &err); + if (err != KORE_RESULT_OK) { + printf("bad http_request_ms value: %s\n", option); + return (KORE_RESULT_ERROR); + } + + return (KORE_RESULT_OK); +} + +static int configure_http_request_limit(char *option) { int err; diff --git a/src/http.c b/src/http.c @@ -73,6 +73,7 @@ static struct kore_pool http_cookie_pool; static struct kore_pool http_body_path; u_int32_t http_request_count = 0; +u_int32_t http_request_ms = HTTP_REQUEST_MS; u_int32_t http_request_limit = HTTP_REQUEST_LIMIT; u_int64_t http_hsts_enable = HTTP_HSTS_ENABLE; u_int16_t http_header_max = HTTP_HEADER_MAX_LEN; @@ -170,12 +171,13 @@ http_request_wakeup(struct http_request *req) void http_process(void) { - u_int32_t count; + u_int64_t total; struct http_request *req, *next; - count = 0; + total = 0; + for (req = TAILQ_FIRST(&http_requests); req != NULL; req = next) { - if (count >= http_request_limit) + if (total >= http_request_ms) break; next = TAILQ_NEXT(req, list); @@ -191,8 +193,8 @@ http_process(void) if (!(req->flags & HTTP_REQUEST_COMPLETE)) continue; - count++; http_process_request(req); + total += req->ms; } } @@ -230,7 +232,8 @@ http_process_request(struct http_request *req) fatal("kore_auth() returned unknown %d", r); } req->end = kore_time_ms(); - req->total += req->end - req->start; + req->ms = req->end - req->start; + req->total += req->ms; switch (r) { case KORE_RESULT_OK: