httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aaron Bannert <aa...@clove.org>
Subject dirty hack gets worker to track hitcounts per thread
Date Wed, 24 Apr 2002 15:42:01 GMT
This is a hack I came up with yesterday to make sure that I wasn't
starving off any of my worker threads. It's nothing I intend to be
committed, but hopefully someone else will find it useful.

-aaron


Index: server/mpm/worker/worker.c
===================================================================
RCS file: /home/cvs/httpd-2.0/server/mpm/worker/worker.c,v
retrieving revision 1.117
diff -u -r1.117 worker.c
--- server/mpm/worker/worker.c	18 Apr 2002 17:46:20 -0000	1.117
+++ server/mpm/worker/worker.c	24 Apr 2002 15:38:41 -0000
@@ -173,6 +173,22 @@
 static int num_listensocks = 0;
 static int resource_shortage = 0;
 static fd_queue_t *worker_queue;
+static int *worker_hitcounts; /* array of number of hits served by each thread */
+
+static apr_status_t print_worker_hitcounts(void *dummy_)
+{
+    int i;
+    fprintf(stderr, "=====================================================\n");
+    fprintf(stderr, "Number of connections processed per thread in PID %d:\n",
+            getpid()); /* FIXME: change this to be child_num */
+    for (i = 0; i < ap_threads_per_child; i++) {
+        fprintf(stderr, "%d%s", worker_hitcounts[i],
+                i % 10 ? " " : "\n");
+    }
+    fprintf(stderr, "\n=====================================================\n");
+
+    return APR_SUCCESS;
+}
 
 /* The structure used to pass unique initialization info to each thread */
 typedef struct {
@@ -883,6 +899,7 @@
         requests_this_child--; /* FIXME: should be synchronized - aaron */
         apr_pool_clear(ptrans);
         last_ptrans = ptrans;
+        worker_hitcounts[thread_slot]++;
     }
 
     ap_update_child_status_from_indexes(process_slot, thread_slot,
@@ -960,6 +977,13 @@
                      "ap_queue_init() failed");
         clean_child_exit(APEXIT_CHILDFATAL);
     }
+
+    /* Initialize the score array, so we can keep track of the number
+     * of connections processed by each thread. */
+    worker_hitcounts = apr_pcalloc(pchild, sizeof(int) * ap_threads_per_child);
+
+    apr_pool_cleanup_register(pchild, NULL, print_worker_hitcounts,
+                              apr_pool_cleanup_null);
 
     loops = prev_threads_created = 0;
     while (1) {

Mime
View raw message