Jim Jagielski wrote:
>
> On Sep 10, 2007, at 6:37 AM, Plüm, Rüdiger, VF-Group wrote:
>
>>>
>>> For example what about adding:
>>> static APR_OPTIONAL_FN_TYPE(ap_proxy_lb_worker_size)
>>> *proxy_lb_worker_size;
>>> and use a void * in scoreboard and an int for the size?
>>
>> For me this sounds fine, but I would guess that Jim doesn't like
>> the void * idea in the scoreboard.
>>
>
> I don't mind it at all, if we use it because we don't know
> what will be stored away or because we may use the storage
> differently at different times. But this is never the
> case. lb_score always is proxy_worker_stat.
>
>
The attached patch remove "lb_score" from scoreboard.c.
Comments?
Cheers
Jean-Frederic
Index: server/scoreboard.c
===================================================================
--- server/scoreboard.c (revision 573572)
+++ server/scoreboard.c (working copy)
@@ -62,13 +62,15 @@
static APR_OPTIONAL_FN_TYPE(ap_proxy_lb_workers)
*proxy_lb_workers;
+static APR_OPTIONAL_FN_TYPE(ap_proxy_lb_worker_size)
+ *proxy_lb_worker_size;
struct ap_sb_handle_t {
int child_num;
int thread_num;
};
-static int server_limit, thread_limit, lb_limit;
+static int server_limit, thread_limit, lb_limit, worker_size;
static apr_size_t scoreboard_size;
/*
@@ -101,11 +103,18 @@
else
lb_limit = 0;
+ if (!proxy_lb_worker_size)
+ proxy_lb_worker_size =
APR_RETRIEVE_OPTIONAL_FN(ap_proxy_lb_worker_size);
+ if (proxy_lb_worker_size)
+ worker_size = proxy_lb_worker_size();
+ else
+ worker_size = 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;
+ scoreboard_size += worker_size * lb_limit;
return scoreboard_size;
}
@@ -130,8 +139,8 @@
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_scoreboard_image->balancers = (void *)more_storage;
+ more_storage += lb_limit * worker_size;
}
ap_assert(more_storage == (char*)shared_score + scoreboard_size);
ap_scoreboard_image->global->server_limit = server_limit;
@@ -283,7 +292,7 @@
/* Clean up the lb workers data */
if (lb_limit) {
memset(ap_scoreboard_image->balancers, 0,
- sizeof(lb_score) * lb_limit);
+ worker_size * lb_limit);
}
return OK;
}
@@ -488,10 +497,12 @@
return ap_scoreboard_image->global;
}
-AP_DECLARE(lb_score *) ap_get_scoreboard_lb(int lb_num)
+AP_DECLARE(void *) ap_get_scoreboard_lb(int lb_num)
{
+ char *ptr;
if (((lb_num < 0) || (lb_limit < lb_num))) {
return(NULL); /* Out of range */
}
- return &ap_scoreboard_image->balancers[lb_num];
+ ptr = (char *) ap_scoreboard_image->balancers + lb_num*worker_size;
+ return (void *) ptr;
}
Index: modules/proxy/mod_proxy_balancer.c
===================================================================
--- modules/proxy/mod_proxy_balancer.c (revision 573572)
+++ modules/proxy/mod_proxy_balancer.c (working copy)
@@ -19,6 +19,7 @@
#define CORE_PRIVATE
#include "mod_proxy.h"
+#include "scoreboard.h"
#include "ap_mpm.h"
#include "apr_version.h"
#include "apr_hooks.h"
@@ -1078,6 +1079,12 @@
NULL
};
+/* return the sizeof of one lb_worker in scoreboard. */
+static int ap_proxy_lb_worker_size(void)
+{
+ return sizeof(lb_score);
+}
+
static void ap_proxy_balancer_register_hook(apr_pool_t *p)
{
/* Only the mpm_winnt has child init hook handler.
@@ -1085,6 +1092,9 @@
* initializes and after the mod_proxy
*/
static const char *const aszPred[] = { "mpm_winnt.c", "mod_proxy.c", NULL};
+
+ APR_REGISTER_OPTIONAL_FN(ap_proxy_lb_worker_size);
+
/* manager handler */
ap_hook_handler(balancer_handler, NULL, NULL, APR_HOOK_FIRST);
ap_hook_child_init(child_init, aszPred, NULL, APR_HOOK_MIDDLE);
Index: modules/proxy/mod_proxy.h
===================================================================
--- modules/proxy/mod_proxy.h (revision 573572)
+++ modules/proxy/mod_proxy.h (working copy)
@@ -295,6 +295,9 @@
int lbset; /* load balancer cluster set */
} proxy_worker_stat;
+/* stuff which is lb specific */
+typedef proxy_worker_stat lb_score;
+
/* Worker configuration */
struct proxy_worker {
int id; /* scoreboard id */
Index: include/scoreboard.h
===================================================================
--- include/scoreboard.h (revision 573572)
+++ include/scoreboard.h (working copy)
@@ -45,9 +45,6 @@
#define DEFAULT_SCOREBOARD "logs/apache_runtime_status"
#endif
-/* for proxy_worker_stat */
-#include "../modules/proxy/mod_proxy.h"
-
/* Scoreboard info on a process is, for now, kept very brief ---
* just status value and pid (the latter so that the caretaker process
* can properly update the scoreboard when a process dies). We may want
@@ -144,9 +141,6 @@
*/
};
-/* stuff which is lb specific */
-typedef proxy_worker_stat lb_score;
-
/* Scoreboard is now in 'local' memory, since it isn't updated once created,
* even in forked architectures. Child created-processes (non-fork) will
* set up these indicies into the (possibly relocated) shmem records.
@@ -155,7 +149,7 @@
global_score *global;
process_score *parent;
worker_score **servers;
- lb_score *balancers;
+ void *balancers; /* defined in mod_proxy */
} scoreboard;
typedef struct ap_sb_handle_t ap_sb_handle_t;
@@ -181,7 +175,7 @@
AP_DECLARE(worker_score *) ap_get_scoreboard_worker(int x, int y);
AP_DECLARE(process_score *) ap_get_scoreboard_process(int x);
AP_DECLARE(global_score *) ap_get_scoreboard_global(void);
-AP_DECLARE(lb_score *) ap_get_scoreboard_lb(int lb_num);
+AP_DECLARE(void *) ap_get_scoreboard_lb(int lb_num);
AP_DECLARE_DATA extern scoreboard *ap_scoreboard_image;
AP_DECLARE_DATA extern const char *ap_scoreboard_fname;
@@ -205,6 +199,12 @@
*/
APR_DECLARE_OPTIONAL_FN(int, ap_proxy_lb_workers,
(void));
+/**
+ * proxy load balancer
+ * @return the size of lb_workers.
+ */
+APR_DECLARE_OPTIONAL_FN(int, ap_proxy_lb_worker_size,
+ (void));
/* for time_process_request() in http_main.c */
#define START_PREQUEST 1