]> granicus.if.org Git - apache/blobdiff - server/scoreboard.c
Update the copyright year in all .c, .h and .xml files
[apache] / server / scoreboard.c
index da1bf95fd6cadb2a2b7cb36473247e50b612150a..1a5b8047978447e3e65295fe9c91939b2d42237c 100644 (file)
@@ -1,4 +1,5 @@
-/* Copyright 2001-2004 The Apache Software Foundation
+/* Copyright 2001-2006 The Apache Software Foundation or its licensors, as
+ * applicable.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -54,17 +55,20 @@ static /* but must be exported to mpm_winnt */
 APR_HOOK_STRUCT(
     APR_HOOK_LINK(pre_mpm)
 )
+
 AP_IMPLEMENT_HOOK_RUN_ALL(int,pre_mpm,
                           (apr_pool_t *p, ap_scoreboard_e sb_type),
                           (p, sb_type),OK,DECLINED)
 
+static APR_OPTIONAL_FN_TYPE(ap_proxy_lb_workers)
+                                *proxy_lb_workers;
+
 struct ap_sb_handle_t {
     int child_num;
     int thread_num;
 };
 
-static int server_limit, thread_limit;
+static int server_limit, thread_limit, lb_limit;
 static apr_size_t scoreboard_size;
 
 /*
@@ -73,7 +77,7 @@ static apr_size_t scoreboard_size;
  * and it should handle cleaning up a scoreboard shared
  * between processes using any form of IPC (file, shared memory
  * segment, etc.). Leave it as is now because it is being used
- * by various MPMs. 
+ * by various MPMs.
  */
 static apr_status_t ap_cleanup_shared_mem(void *d)
 {
@@ -89,9 +93,20 @@ AP_DECLARE(int) ap_calc_scoreboard_size(void)
 {
     ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &thread_limit);
     ap_mpm_query(AP_MPMQ_HARD_LIMIT_DAEMONS, &server_limit);
+
+    if (!proxy_lb_workers)
+        proxy_lb_workers = APR_RETRIEVE_OPTIONAL_FN(ap_proxy_lb_workers);
+    if (proxy_lb_workers)
+        lb_limit = proxy_lb_workers();
+    else
+        lb_limit = 0;
+
     scoreboard_size = sizeof(global_score);
     scoreboard_size += sizeof(process_score) * server_limit;
     scoreboard_size += sizeof(worker_score) * server_limit * thread_limit;
+    if (lb_limit)
+        scoreboard_size += sizeof(lb_score) * lb_limit;
+
     return scoreboard_size;
 }
 
@@ -99,24 +114,30 @@ void ap_init_scoreboard(void *shared_score)
 {
     char *more_storage;
     int i;
-    
+
     ap_calc_scoreboard_size();
-    ap_scoreboard_image = 
-        calloc(1, sizeof(scoreboard) + server_limit * sizeof(worker_score *));
+    ap_scoreboard_image =
+        calloc(1, sizeof(scoreboard) + server_limit * sizeof(worker_score *) +
+               server_limit * lb_limit * sizeof(lb_score *));
     more_storage = shared_score;
     ap_scoreboard_image->global = (global_score *)more_storage;
     more_storage += sizeof(global_score);
     ap_scoreboard_image->parent = (process_score *)more_storage;
     more_storage += sizeof(process_score) * server_limit;
-    ap_scoreboard_image->servers = 
+    ap_scoreboard_image->servers =
         (worker_score **)((char*)ap_scoreboard_image + sizeof(scoreboard));
     for (i = 0; i < server_limit; i++) {
         ap_scoreboard_image->servers[i] = (worker_score *)more_storage;
         more_storage += thread_limit * sizeof(worker_score);
     }
+    if (lb_limit) {
+        ap_scoreboard_image->balancers = (lb_score *)more_storage;
+        more_storage += lb_limit * sizeof(lb_score);
+    }
     ap_assert(more_storage == (char*)shared_score + scoreboard_size);
     ap_scoreboard_image->global->server_limit = server_limit;
     ap_scoreboard_image->global->thread_limit = thread_limit;
+    ap_scoreboard_image->global->lb_limit     = lb_limit;
 }
 
 /**
@@ -131,7 +152,7 @@ static apr_status_t create_namebased_scoreboard(apr_pool_t *pool,
 
     /* The shared memory file must not exist before we create the
      * segment. */
-    apr_file_remove(fname, pool); /* ignore errors */
+    apr_shm_remove(fname, pool); /* ignore errors */
 
     rv = apr_shm_create(&ap_scoreboard_shm, scoreboard_size, fname, pool);
     if (rv != APR_SUCCESS) {
@@ -144,8 +165,8 @@ static apr_status_t create_namebased_scoreboard(apr_pool_t *pool,
     return APR_SUCCESS;
 }
 
-/* ToDo: This function should be made to handle setting up 
- * a scoreboard shared between processes using any IPC technique, 
+/* ToDo: This function should be made to handle setting up
+ * a scoreboard shared between processes using any IPC technique,
  * not just a shared memory segment
  */
 static apr_status_t open_scoreboard(apr_pool_t *pconf)
@@ -254,12 +275,17 @@ int ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e sb_type)
     if (ap_scoreboard_image) {
         running_gen = ap_scoreboard_image->global->running_generation;
         ap_scoreboard_image->global->restart_time = apr_time_now();
-        memset(ap_scoreboard_image->parent, 0, 
+        memset(ap_scoreboard_image->parent, 0,
                sizeof(process_score) * server_limit);
         for (i = 0; i < server_limit; i++) {
             memset(ap_scoreboard_image->servers[i], 0,
                    sizeof(worker_score) * thread_limit);
         }
+        /* Clean up the lb workers data */
+        if (lb_limit) {
+            memset(ap_scoreboard_image->balancers, 0,
+                   sizeof(lb_score) * lb_limit);
+        }
         return OK;
     }
 
@@ -274,7 +300,7 @@ int ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e sb_type)
         memset(sb_shared, 0, scoreboard_size);
         ap_init_scoreboard(sb_shared);
     }
-    else 
+    else
 #endif
     {
         /* A simple malloc will suffice */
@@ -330,7 +356,7 @@ AP_DECLARE(void) ap_increment_counts(ap_sb_handle_t *sb, request_rec *r)
     ws->conn_bytes += r->bytes_sent;
 }
 
-AP_DECLARE(int) find_child_by_pid(apr_proc_t *pid)
+int find_child_by_pid(apr_proc_t *pid)
 {
     int i;
     int max_daemons_limit;
@@ -372,7 +398,7 @@ AP_DECLARE(int) ap_update_child_status_from_indexes(int child_num,
     ws->status = status;
 
     ps = &ap_scoreboard_image->parent[child_num];
-    
+
     if (status == SERVER_READY
         && old_status == SERVER_STARTING) {
         ws->thread_num = child_num * thread_limit + thread_num;
@@ -412,7 +438,7 @@ AP_DECLARE(int) ap_update_child_status_from_indexes(int child_num,
                         sizeof(ws->vhost));
         }
     }
-    
+
     return old_status;
 }
 
@@ -423,21 +449,21 @@ AP_DECLARE(int) ap_update_child_status(ap_sb_handle_t *sbh, int status,
                                                status, r);
 }
 
-void ap_time_process_request(int child_num, int thread_num, int status)
+void ap_time_process_request(ap_sb_handle_t *sbh, int status)
 {
     worker_score *ws;
 
-    if (child_num < 0) {
+    if (sbh->child_num < 0) {
         return;
     }
 
-    ws = &ap_scoreboard_image->servers[child_num][thread_num];
+    ws = &ap_scoreboard_image->servers[sbh->child_num][sbh->thread_num];
 
     if (status == START_PREQUEST) {
-        ws->start_time = apr_time_now(); 
+        ws->start_time = apr_time_now();
     }
     else if (status == STOP_PREQUEST) {
-        ws->stop_time = apr_time_now(); 
+        ws->stop_time = apr_time_now();
     }
 }
 
@@ -462,3 +488,11 @@ AP_DECLARE(global_score *) ap_get_scoreboard_global()
 {
     return ap_scoreboard_image->global;
 }
+
+AP_DECLARE(lb_score *) ap_get_scoreboard_lb(int lb_num)
+{
+    if (((lb_num < 0) || (lb_limit < lb_num))) {
+        return(NULL); /* Out of range */
+    }
+    return &ap_scoreboard_image->balancers[lb_num];
+}