Browse Source

[core] alternate between two joblists

process one joblist and queue work up on second joblist

loop to poll, but poll immediate if work was queued on second joblist
master
Glenn Strauss 1 year ago
parent
commit
784f1ac1da
  1. 4
      src/base.h
  2. 2
      src/connections.h
  3. 15
      src/server.c

4
src/base.h

@ -157,7 +157,9 @@ struct server {
buffer *tmp_buf;
connections conns;
connections joblist;
connections *joblist;
connections joblist_A;
connections joblist_B;
connections fdwaitqueue;
/* counters */

2
src/connections.h

@ -19,7 +19,7 @@ const char * connection_get_state(request_state_t state);
const char * connection_get_short_state(request_state_t state);
void connection_state_machine(connection *con);
#define joblist_append(con) connection_list_append(&(con)->srv->joblist, (con))
#define joblist_append(con) connection_list_append((con)->srv->joblist, (con))
void connection_list_append(connections *conns, connection *con);
#endif

15
src/server.c

@ -233,6 +233,7 @@ static server *server_init(void) {
CLEAN(tmp_buf);
#undef CLEAN
srv->joblist = &srv->joblist_A;
strftime_cache_reset();
@ -274,7 +275,8 @@ static void server_free(server *srv) {
config_free(srv);
free(srv->joblist.ptr);
free(srv->joblist_A.ptr);
free(srv->joblist_B.ptr);
free(srv->fdwaitqueue.ptr);
stat_cache_free();
@ -1504,7 +1506,6 @@ static void server_handle_sigchld (server * const srv) {
__attribute_hot__
__attribute_noinline__
static void server_main_loop (server * const srv) {
connections * const joblist = &srv->joblist;
time_t last_active_ts = time(NULL);
while (!srv_shutdown) {
@ -1550,11 +1551,17 @@ static void server_main_loop (server * const srv) {
server_process_fdwaitqueue(srv);
}
if (fdevent_poll(srv->ev, 1000) > 0) {
connections * const joblist = srv->joblist;
if (fdevent_poll(srv->ev, joblist->used ? 0 : 1000) > 0) {
last_active_ts = log_epoch_secs;
}
for (uint32_t ndx = 0; ndx < joblist->used; ++ndx) {
srv->joblist = (joblist == &srv->joblist_A)
? &srv->joblist_B
: &srv->joblist_A;
for (uint32_t ndx = 0, used = joblist->used; ndx < used; ++ndx) {
connection *con = joblist->ptr[ndx];
connection_state_machine(con);
}

Loading…
Cancel
Save