mirror of
https://github.com/jorisvink/kore
synced 2025-03-09 12:39:01 -04:00
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.
This commit is contained in:
parent
c55036bfec
commit
548068d2a0
@ -92,13 +92,18 @@ workers 4
|
|||||||
# all responses. Parameter is the age.
|
# all responses. Parameter is the age.
|
||||||
# (Set to 0 to disable sending this header).
|
# (Set to 0 to disable sending this header).
|
||||||
#
|
#
|
||||||
# http_request_limit Limit the number of requests Kore processes
|
# http_request_limit Limit the number of HTTP requests workers
|
||||||
# in a single event loop.
|
# can queue up.
|
||||||
|
#
|
||||||
|
# http_request_ms The number of milliseconds workers can max
|
||||||
|
# spend inside the HTTP processing loop.
|
||||||
|
#
|
||||||
#http_header_max 4096
|
#http_header_max 4096
|
||||||
#http_body_max 1024000
|
#http_body_max 1024000
|
||||||
#http_keepalive_time 0
|
#http_keepalive_time 0
|
||||||
#http_hsts_enable 31536000
|
#http_hsts_enable 31536000
|
||||||
#http_request_limit 1000
|
#http_request_limit 1000
|
||||||
|
#http_request_ms 10
|
||||||
#http_body_disk_offload 0
|
#http_body_disk_offload 0
|
||||||
#http_body_disk_path tmp_files
|
#http_body_disk_path tmp_files
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@ extern "C" {
|
|||||||
#define HTTP_COOKIE_BUFSIZE 1024
|
#define HTTP_COOKIE_BUFSIZE 1024
|
||||||
#define HTTP_DATE_MAXSIZE 255
|
#define HTTP_DATE_MAXSIZE 255
|
||||||
#define HTTP_REQUEST_LIMIT 1000
|
#define HTTP_REQUEST_LIMIT 1000
|
||||||
|
#define HTTP_REQUEST_MS 10
|
||||||
#define HTTP_BODY_DISK_PATH "tmp_files"
|
#define HTTP_BODY_DISK_PATH "tmp_files"
|
||||||
#define HTTP_BODY_DISK_OFFLOAD 0
|
#define HTTP_BODY_DISK_OFFLOAD 0
|
||||||
#define HTTP_BODY_PATH_MAX 256
|
#define HTTP_BODY_PATH_MAX 256
|
||||||
@ -194,6 +195,7 @@ struct http_request {
|
|||||||
u_int8_t fsm_state;
|
u_int8_t fsm_state;
|
||||||
u_int16_t flags;
|
u_int16_t flags;
|
||||||
u_int16_t status;
|
u_int16_t status;
|
||||||
|
u_int64_t ms;
|
||||||
u_int64_t start;
|
u_int64_t start;
|
||||||
u_int64_t end;
|
u_int64_t end;
|
||||||
u_int64_t total;
|
u_int64_t total;
|
||||||
@ -235,8 +237,9 @@ struct http_state {
|
|||||||
int (*cb)(struct http_request *);
|
int (*cb)(struct http_request *);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern u_int16_t http_header_max;
|
|
||||||
extern size_t http_body_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_int64_t http_hsts_enable;
|
||||||
extern u_int16_t http_keepalive_time;
|
extern u_int16_t http_keepalive_time;
|
||||||
extern u_int32_t http_request_limit;
|
extern u_int32_t http_request_limit;
|
||||||
|
16
src/config.c
16
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_body_max(char *);
|
||||||
static int configure_http_hsts_enable(char *);
|
static int configure_http_hsts_enable(char *);
|
||||||
static int configure_http_keepalive_time(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_request_limit(char *);
|
||||||
static int configure_http_body_disk_offload(char *);
|
static int configure_http_body_disk_offload(char *);
|
||||||
static int configure_http_body_disk_path(char *);
|
static int configure_http_body_disk_path(char *);
|
||||||
@ -152,6 +153,7 @@ static struct {
|
|||||||
{ "http_body_max", configure_http_body_max },
|
{ "http_body_max", configure_http_body_max },
|
||||||
{ "http_hsts_enable", configure_http_hsts_enable },
|
{ "http_hsts_enable", configure_http_hsts_enable },
|
||||||
{ "http_keepalive_time", configure_http_keepalive_time },
|
{ "http_keepalive_time", configure_http_keepalive_time },
|
||||||
|
{ "http_request_ms", configure_http_request_ms },
|
||||||
{ "http_request_limit", configure_http_request_limit },
|
{ "http_request_limit", configure_http_request_limit },
|
||||||
{ "http_body_disk_offload", configure_http_body_disk_offload },
|
{ "http_body_disk_offload", configure_http_body_disk_offload },
|
||||||
{ "http_body_disk_path", configure_http_body_disk_path },
|
{ "http_body_disk_path", configure_http_body_disk_path },
|
||||||
@ -687,6 +689,20 @@ configure_http_keepalive_time(char *option)
|
|||||||
return (KORE_RESULT_OK);
|
return (KORE_RESULT_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
static int
|
||||||
configure_http_request_limit(char *option)
|
configure_http_request_limit(char *option)
|
||||||
{
|
{
|
||||||
|
13
src/http.c
13
src/http.c
@ -73,6 +73,7 @@ static struct kore_pool http_cookie_pool;
|
|||||||
static struct kore_pool http_body_path;
|
static struct kore_pool http_body_path;
|
||||||
|
|
||||||
u_int32_t http_request_count = 0;
|
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_int32_t http_request_limit = HTTP_REQUEST_LIMIT;
|
||||||
u_int64_t http_hsts_enable = HTTP_HSTS_ENABLE;
|
u_int64_t http_hsts_enable = HTTP_HSTS_ENABLE;
|
||||||
u_int16_t http_header_max = HTTP_HEADER_MAX_LEN;
|
u_int16_t http_header_max = HTTP_HEADER_MAX_LEN;
|
||||||
@ -170,12 +171,13 @@ http_request_wakeup(struct http_request *req)
|
|||||||
void
|
void
|
||||||
http_process(void)
|
http_process(void)
|
||||||
{
|
{
|
||||||
u_int32_t count;
|
u_int64_t total;
|
||||||
struct http_request *req, *next;
|
struct http_request *req, *next;
|
||||||
|
|
||||||
count = 0;
|
total = 0;
|
||||||
|
|
||||||
for (req = TAILQ_FIRST(&http_requests); req != NULL; req = next) {
|
for (req = TAILQ_FIRST(&http_requests); req != NULL; req = next) {
|
||||||
if (count >= http_request_limit)
|
if (total >= http_request_ms)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
next = TAILQ_NEXT(req, list);
|
next = TAILQ_NEXT(req, list);
|
||||||
@ -191,8 +193,8 @@ http_process(void)
|
|||||||
if (!(req->flags & HTTP_REQUEST_COMPLETE))
|
if (!(req->flags & HTTP_REQUEST_COMPLETE))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
count++;
|
|
||||||
http_process_request(req);
|
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);
|
fatal("kore_auth() returned unknown %d", r);
|
||||||
}
|
}
|
||||||
req->end = kore_time_ms();
|
req->end = kore_time_ms();
|
||||||
req->total += req->end - req->start;
|
req->ms = req->end - req->start;
|
||||||
|
req->total += req->ms;
|
||||||
|
|
||||||
switch (r) {
|
switch (r) {
|
||||||
case KORE_RESULT_OK:
|
case KORE_RESULT_OK:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user