mirror of https://git.kore.io/kore.git
Improve curl timeout handling.
In case libcurl instructs us to call the timeout function as soon as possible (timeout == 0 in curl_timeout), don't try to be clever with a timeout value of 10ms. Instead call the timeout function once we get back in the worker event loop. This makes things a lot snappier as we don't depend on epoll/kqueue waiting for io for 10ms (which actually isn't 10ms...).
This commit is contained in:
parent
574c9a7084
commit
4a64b4f07b
|
@ -67,6 +67,7 @@ extern u_int16_t kore_curl_timeout;
|
||||||
extern u_int64_t kore_curl_recv_max;
|
extern u_int64_t kore_curl_recv_max;
|
||||||
|
|
||||||
void kore_curl_sysinit(void);
|
void kore_curl_sysinit(void);
|
||||||
|
void kore_curl_do_timeout(void);
|
||||||
void kore_curl_run(struct kore_curl *);
|
void kore_curl_run(struct kore_curl *);
|
||||||
void kore_curl_cleanup(struct kore_curl *);
|
void kore_curl_cleanup(struct kore_curl *);
|
||||||
int kore_curl_success(struct kore_curl *);
|
int kore_curl_success(struct kore_curl *);
|
||||||
|
|
17
src/curl.c
17
src/curl.c
|
@ -33,6 +33,7 @@ struct fd_cache {
|
||||||
|
|
||||||
static void curl_process(void);
|
static void curl_process(void);
|
||||||
static void curl_event_handle(void *, int);
|
static void curl_event_handle(void *, int);
|
||||||
|
static void curl_timeout(void *, u_int64_t);
|
||||||
static int curl_timer(CURLM *, long, void *);
|
static int curl_timer(CURLM *, long, void *);
|
||||||
static int curl_socket(CURL *, curl_socket_t, int, void *, void *);
|
static int curl_socket(CURL *, curl_socket_t, int, void *, void *);
|
||||||
|
|
||||||
|
@ -43,6 +44,7 @@ static CURLM *multi = NULL;
|
||||||
static struct kore_timer *timer = NULL;
|
static struct kore_timer *timer = NULL;
|
||||||
static struct kore_pool fd_cache_pool;
|
static struct kore_pool fd_cache_pool;
|
||||||
static char user_agent[64];
|
static char user_agent[64];
|
||||||
|
static int timeout_immediate = 0;
|
||||||
static LIST_HEAD(, fd_cache) cache[FD_CACHE_BUCKETS];
|
static LIST_HEAD(, fd_cache) cache[FD_CACHE_BUCKETS];
|
||||||
|
|
||||||
u_int16_t kore_curl_timeout = KORE_CURL_TIMEOUT;
|
u_int16_t kore_curl_timeout = KORE_CURL_TIMEOUT;
|
||||||
|
@ -146,6 +148,13 @@ kore_curl_cleanup(struct kore_curl *client)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
kore_curl_do_timeout(void)
|
||||||
|
{
|
||||||
|
while (timeout_immediate)
|
||||||
|
curl_timeout(NULL, kore_time_ms());
|
||||||
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
kore_curl_tobuf(char *ptr, size_t size, size_t nmemb, void *udata)
|
kore_curl_tobuf(char *ptr, size_t size, size_t nmemb, void *udata)
|
||||||
{
|
{
|
||||||
|
@ -560,6 +569,8 @@ curl_timeout(void *uarg, u_int64_t now)
|
||||||
static int
|
static int
|
||||||
curl_timer(CURLM *mctx, long timeout, void *arg)
|
curl_timer(CURLM *mctx, long timeout, void *arg)
|
||||||
{
|
{
|
||||||
|
timeout_immediate = 0;
|
||||||
|
|
||||||
if (timeout < 0) {
|
if (timeout < 0) {
|
||||||
if (timer != NULL) {
|
if (timer != NULL) {
|
||||||
kore_timer_remove(timer);
|
kore_timer_remove(timer);
|
||||||
|
@ -573,8 +584,10 @@ curl_timer(CURLM *mctx, long timeout, void *arg)
|
||||||
timer = NULL;
|
timer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeout == 0)
|
if (timeout == 0) {
|
||||||
timeout = 10;
|
timeout_immediate = 1;
|
||||||
|
return (CURLM_OK);
|
||||||
|
}
|
||||||
|
|
||||||
timer = kore_timer_add(curl_timeout, timeout, mctx, KORE_TIMER_ONESHOT);
|
timer = kore_timer_add(curl_timeout, timeout, mctx, KORE_TIMER_ONESHOT);
|
||||||
|
|
||||||
|
|
12
src/worker.c
12
src/worker.c
|
@ -49,6 +49,10 @@
|
||||||
#include "python_api.h"
|
#include "python_api.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(KORE_USE_CURL)
|
||||||
|
#include "curl.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if !defined(WAIT_ANY)
|
#if !defined(WAIT_ANY)
|
||||||
#define WAIT_ANY (-1)
|
#define WAIT_ANY (-1)
|
||||||
#endif
|
#endif
|
||||||
|
@ -471,14 +475,18 @@ kore_worker_entry(struct kore_worker *kw)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
kore_timer_run(now);
|
kore_timer_run(now);
|
||||||
|
#if defined(KORE_USE_CURL)
|
||||||
|
kore_curl_do_timeout();
|
||||||
|
#endif
|
||||||
#if !defined(KORE_NO_HTTP)
|
#if !defined(KORE_NO_HTTP)
|
||||||
http_process();
|
http_process();
|
||||||
#endif
|
#endif
|
||||||
#if defined(KORE_USE_PYTHON)
|
#if defined(KORE_USE_PYTHON)
|
||||||
kore_python_coro_run();
|
kore_python_coro_run();
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(KORE_USE_CURL)
|
||||||
|
kore_curl_do_timeout();
|
||||||
|
#endif
|
||||||
if (next_prune <= now) {
|
if (next_prune <= now) {
|
||||||
kore_connection_check_timeout(now);
|
kore_connection_check_timeout(now);
|
||||||
kore_connection_prune(KORE_CONNECTION_PRUNE_DISCONNECT);
|
kore_connection_prune(KORE_CONNECTION_PRUNE_DISCONNECT);
|
||||||
|
|
Loading…
Reference in New Issue