From 5790ed1c710cfa5f0ffa098fbd3a959e755d98ff Mon Sep 17 00:00:00 2001 From: Jim Jagielski Date: Thu, 27 Jan 2011 19:34:38 +0000 Subject: [PATCH] Revert an old (~10yr) change to the fd Q; move back to FIFO rather than LIFO, for more consistent performance so that older requests don't suffer git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1064269 13f79535-47bb-0310-9956-ffa450edef68 --- server/mpm/event/fdqueue.c | 13 +++++++++++-- server/mpm/event/fdqueue.h | 6 ++++-- server/mpm/worker/fdqueue.c | 13 +++++++++++-- server/mpm/worker/fdqueue.h | 6 ++++-- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/server/mpm/event/fdqueue.c b/server/mpm/event/fdqueue.c index 10015b7d39..c1dbda1ee5 100644 --- a/server/mpm/event/fdqueue.c +++ b/server/mpm/event/fdqueue.c @@ -310,6 +310,8 @@ apr_status_t ap_queue_init(fd_queue_t * queue, int queue_capacity, queue->data = apr_palloc(a, queue_capacity * sizeof(fd_queue_elem_t)); queue->bounds = queue_capacity; queue->nelts = 0; + queue->in = 0; + queue->out = 0; /* Set all the sockets in the queue to NULL */ for (i = 0; i < queue_capacity; ++i) @@ -340,7 +342,10 @@ apr_status_t ap_queue_push(fd_queue_t * queue, apr_socket_t * sd, AP_DEBUG_ASSERT(!queue->terminated); AP_DEBUG_ASSERT(!ap_queue_full(queue)); - elem = &queue->data[queue->nelts]; + elem = &queue->data[queue->in]; + queue->in++; + if (queue->in >= queue->bounds) + queue->in -= queue->bounds; elem->sd = sd; elem->cs = cs; elem->p = p; @@ -420,7 +425,11 @@ apr_status_t ap_queue_pop_something(fd_queue_t * queue, apr_socket_t ** sd, APR_RING_REMOVE(*te_out, link); } else { - elem = &queue->data[--queue->nelts]; + elem = &queue->data[queue->out]; + queue->out++; + if (queue->out >= queue->bounds) + queue->out -= queue->bounds; + queue->nelts--; *sd = elem->sd; *cs = elem->cs; *p = elem->p; diff --git a/server/mpm/event/fdqueue.h b/server/mpm/event/fdqueue.h index 9482d71b0c..fbe120b8db 100644 --- a/server/mpm/event/fdqueue.h +++ b/server/mpm/event/fdqueue.h @@ -70,8 +70,10 @@ struct fd_queue_t { APR_RING_HEAD(timers_t, timer_event_t) timers; fd_queue_elem_t *data; - int nelts; - int bounds; + unsigned int nelts; + unsigned int bounds; + unsigned int in; + unsigned int out; apr_thread_mutex_t *one_big_mutex; apr_thread_cond_t *not_empty; int terminated; diff --git a/server/mpm/worker/fdqueue.c b/server/mpm/worker/fdqueue.c index 49e53032ce..fe5881b4ce 100644 --- a/server/mpm/worker/fdqueue.c +++ b/server/mpm/worker/fdqueue.c @@ -284,6 +284,8 @@ apr_status_t ap_queue_init(fd_queue_t *queue, int queue_capacity, apr_pool_t *a) queue->data = apr_palloc(a, queue_capacity * sizeof(fd_queue_elem_t)); queue->bounds = queue_capacity; queue->nelts = 0; + queue->in = 0; + queue->out = 0; /* Set all the sockets in the queue to NULL */ for (i = 0; i < queue_capacity; ++i) @@ -312,7 +314,10 @@ apr_status_t ap_queue_push(fd_queue_t *queue, apr_socket_t *sd, apr_pool_t *p) AP_DEBUG_ASSERT(!queue->terminated); AP_DEBUG_ASSERT(!ap_queue_full(queue)); - elem = &queue->data[queue->nelts]; + elem = &queue->data[queue->in]; + queue->in++; + if (queue->in >= queue->bounds) + queue->in -= queue->bounds; elem->sd = sd; elem->p = p; queue->nelts++; @@ -361,7 +366,11 @@ apr_status_t ap_queue_pop(fd_queue_t *queue, apr_socket_t **sd, apr_pool_t **p) } } - elem = &queue->data[--queue->nelts]; + elem = &queue->data[queue->out]; + queue->out++; + if (queue->out >= queue->bounds) + queue->out -= queue->bounds; + queue->nelts--; *sd = elem->sd; *p = elem->p; #ifdef AP_DEBUG diff --git a/server/mpm/worker/fdqueue.h b/server/mpm/worker/fdqueue.h index 7de082a038..1d48a1a826 100644 --- a/server/mpm/worker/fdqueue.h +++ b/server/mpm/worker/fdqueue.h @@ -55,8 +55,10 @@ typedef struct fd_queue_elem_t fd_queue_elem_t; struct fd_queue_t { fd_queue_elem_t *data; - int nelts; - int bounds; + unsigned int nelts; + unsigned int bounds; + unsigned int in; + unsigned int out; apr_thread_mutex_t *one_big_mutex; apr_thread_cond_t *not_empty; int terminated; -- 2.40.0