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 ec5ac40706da9c0e78e234597b1bdb31d8c22e62
parent f9b3cfcee406be84b4bab53d5e310625ab545adc
Author: Joris Vink <joris@coders.se>
Date:   Thu, 30 May 2013 20:55:50 +0200

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

Diffstat:
src/http.c | 2++
src/kore.c | 18+++++++++++-------
2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/http.c b/src/http.c @@ -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); } diff --git a/src/kore.c b/src/kore.c @@ -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;