wake up the workers once in a while to process anything that is waiting.

This commit is contained in:
Joris Vink 2013-05-30 20:55:50 +02:00
parent f9b3cfcee4
commit ec5ac40706
2 changed files with 13 additions and 7 deletions

View File

@ -435,5 +435,7 @@ http_post_data_recv(struct netbuf *nb)
kore_buf_append(req->post_data, nb->buf, nb->offset);
req->flags |= HTTP_REQUEST_COMPLETE;
kore_log("post complete for request %p", req);
return (KORE_RESULT_OK);
}

View File

@ -90,6 +90,7 @@ int
main(int argc, char *argv[])
{
struct passwd *pw;
struct kore_worker *kw;
struct listener server;
struct epoll_event *events;
int n, i, *fd;
@ -145,13 +146,20 @@ main(int argc, char *argv[])
sig_recv = 0;
}
n = epoll_wait(efd, events, EPOLL_EVENTS, 10);
n = epoll_wait(efd, events, EPOLL_EVENTS, 1000);
if (n == -1) {
if (errno == EINTR)
continue;
fatal("epoll_wait(): %s", errno_s);
}
TAILQ_FOREACH(kw, &kore_workers, list) {
if (pthread_mutex_trylock(&(kw->lock)))
continue;
pthread_cond_signal(&(kw->cond));
pthread_mutex_unlock(&(kw->lock));
}
if (n > 0)
kore_log("main(): %d sockets available", n);
@ -259,8 +267,8 @@ kore_worker_delegate(struct http_request *req)
kore_log("assigning request %p to worker %d:%d", req, kw->id, kw->load);
kw->load++;
TAILQ_INSERT_TAIL(&(kw->requests), req, list);
pthread_mutex_unlock(&(kw->lock));
pthread_cond_signal(&(kw->cond));
pthread_mutex_unlock(&(kw->lock));
}
static int
@ -550,12 +558,8 @@ kore_worker_entry(void *arg)
pthread_mutex_lock(&(kw->lock));
for (;;) {
if (retry == 0) {
kore_log("worker %d going to sleep", kw->id);
if (retry == 0)
pthread_cond_wait(&(kw->cond), &(kw->lock));
kore_log("worker %d woke up with %d reqs",
kw->id, kw->load);
}
retry = 0;
for (req = TAILQ_FIRST(&(kw->requests)); req != NULL;