httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aaron Bannert <aa...@clove.org>
Subject [PATCH] change worker's fdqueue from FIFO to LIFO
Date Tue, 18 Sep 2001 21:49:58 GMT

This is a rather simple patch that may improve cache-hit performance
under some conditions by changing the queue of available worker threads
from FIFO to LIFO. It also adds a tiny reduction in the arithmetic that
happens in the critical section, which will definately help if you have
a lame compiler.

-aaron


Index: server/mpm/worker/fdqueue.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/server/mpm/worker/fdqueue.c,v
retrieving revision 1.6
diff -u -r1.6 fdqueue.c
--- server/mpm/worker/fdqueue.c	2001/09/18 21:14:18	1.6
+++ server/mpm/worker/fdqueue.c	2001/09/18 21:35:23
@@ -73,7 +73,6 @@
  */
 static int ap_queue_empty(fd_queue_t *queue)
 {
-    /*return (queue->head == queue->tail);*/
     return (queue->blanks >= queue->bounds - 1);
 }
 
@@ -108,7 +107,7 @@
         return FD_QUEUE_FAILURE;
 
     bounds = queue_capacity + 1;
-    queue->head = queue->tail = 0;
+    queue->tail = 0;
     queue->data = apr_palloc(a, bounds * sizeof(fd_queue_elem_t));
     queue->bounds = bounds;
     queue->blanks = queue_capacity;
@@ -144,7 +143,7 @@
 
     queue->data[queue->tail].sd = sd;
     queue->data[queue->tail].p = p;
-    queue->tail = (queue->tail + 1) % queue->bounds;
+    queue->tail++;
     queue->blanks--;
 
     pthread_cond_signal(&queue->not_empty);
@@ -164,6 +163,8 @@
  */
 apr_status_t ap_queue_pop(fd_queue_t *queue, apr_socket_t **sd, apr_pool_t **p) 
 {
+    fd_queue_elem_t *elem;
+
     if (pthread_mutex_lock(&queue->one_big_mutex) != 0) {
         return FD_QUEUE_FAILURE;
     }
@@ -180,13 +181,12 @@
         }
     } 
     
-    *sd = queue->data[queue->head].sd;
-    *p = queue->data[queue->head].p;
-    queue->data[queue->head].sd = NULL;
-    queue->data[queue->head].p = NULL;
-    if (sd != NULL) {
-        queue->head = (queue->head + 1) % queue->bounds;
-    }
+    queue->tail--;
+    elem = &queue->data[queue->tail];
+    *sd = elem->sd;
+    *p = elem->p;
+    elem->sd = NULL;
+    elem->p = NULL;
     queue->blanks++;
 
     if (pthread_mutex_unlock(&queue->one_big_mutex) != 0) {
Index: server/mpm/worker/fdqueue.h
===================================================================
RCS file: /home/cvspublic/httpd-2.0/server/mpm/worker/fdqueue.h,v
retrieving revision 1.6
diff -u -r1.6 fdqueue.h
--- server/mpm/worker/fdqueue.h	2001/09/18 21:14:18	1.6
+++ server/mpm/worker/fdqueue.h	2001/09/18 21:35:23
@@ -81,7 +81,6 @@
 typedef struct fd_queue_elem_t fd_queue_elem_t;
 
 struct fd_queue_t {
-    int                head;
     int                tail;
     fd_queue_elem_t   *data;
     int                bounds;

Mime
View raw message