Apache HTTPD
mod_lbmethod_bybusyness.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "mod_proxy.h"
18#include "scoreboard.h"
19#include "ap_mpm.h"
20#include "apr_version.h"
21#include "ap_hooks.h"
22
23module AP_MODULE_DECLARE_DATA lbmethod_bybusyness_module;
24
27
29{
30 int *total_factor = (int *)baton;
31
32 current->s->lbstatus += current->s->lbfactor;
33 *total_factor += current->s->lbfactor;
34
35 return (
37 || (current->s->busy < prev_best->s->busy)
38 || (
39 (current->s->busy == prev_best->s->busy)
40 && (current->s->lbstatus > prev_best->s->lbstatus)
41 )
42 );
43}
44
47{
48 int total_factor = 0;
49 proxy_worker *worker =
52
53 if (worker) {
54 worker->s->lbstatus -= total_factor;
55 }
56
57 return worker;
58}
59
60/* assumed to be mutex protected by caller */
62{
63 int i;
64 proxy_worker **worker;
65 worker = (proxy_worker **)balancer->workers->elts;
66 for (i = 0; i < balancer->workers->nelts; i++, worker++) {
67 (*worker)->s->lbstatus = 0;
68 (*worker)->s->busy = 0;
69 }
70 return APR_SUCCESS;
71}
72
74{
75 return APR_SUCCESS;
76}
77
79{
80 "bybusyness",
82 NULL,
83 &reset,
84 &age,
85 NULL
86};
87
88/* post_config hook: */
90 apr_pool_t *ptemp, server_rec *s)
91{
92
93 /* lbmethod_bybusyness_post_config() will be called twice during startup. So, don't
94 * set up the static data the 1st time through. */
96 return OK;
97 }
98
103 "mod_proxy must be loaded for mod_lbmethod_bybusyness");
104 return !OK;
105 }
106
107 return OK;
108}
109
115
118 NULL, /* create per-directory config structure */
119 NULL, /* merge per-directory config structures */
120 NULL, /* create per-server config structure */
121 NULL, /* merge per-server config structures */
122 NULL, /* command apr_table_t */
123 register_hook /* register hooks */
124};
ap hook functions and macros
Apache Multi-Processing Module library.
APR Versioning Interface.
static apr_pool_t * pconf
Definition event.c:441
void ap_hook_post_config(ap_HOOK_post_config_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition config.c:105
#define AP_DECLARE_MODULE(foo)
request_rec * r
#define OK
Definition httpd.h:456
#define AP_SQ_MS_CREATE_PRE_CONFIG
Definition http_core.h:1047
int ap_state_query(int query_code)
Definition core.c:5378
#define AP_SQ_MAIN_STATE
Definition http_core.h:1030
#define APLOGNO(n)
Definition http_log.h:117
#define ap_log_error
Definition http_log.h:370
#define APLOG_MARK
Definition http_log.h:283
#define APLOG_EMERG
Definition http_log.h:64
apr_status_t ap_register_provider(apr_pool_t *pool, const char *provider_group, const char *provider_name, const char *provider_version, const void *provider)
Definition provider.c:35
ap_vhost_iterate_conn_cb void * baton
Definition http_vhost.h:87
#define APR_HOOK_MIDDLE
Definition apr_hooks.h:303
#define APR_RETRIEVE_OPTIONAL_FN(name)
#define APR_OPTIONAL_FN_TYPE(name)
#define PROXY_LBMETHOD
Definition mod_proxy.h:1444
#define STANDARD20_MODULE_STUFF
apr_size_t size
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
const char * s
Definition apr_strings.h:95
apr_pool_t * p
Definition md_event.c:32
static apr_status_t age(proxy_balancer *balancer, server_rec *s)
static proxy_worker * find_best_bybusyness(proxy_balancer *balancer, request_rec *r)
static int is_best_bybusyness(proxy_worker *current, proxy_worker *prev_best, void *baton)
static void register_hook(apr_pool_t *p)
static int lbmethod_bybusyness_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
static apr_OFN_proxy_balancer_get_best_worker_t * ap_proxy_balancer_get_best_worker_fn
static const proxy_balancer_method bybusyness
static apr_status_t reset(proxy_balancer *balancer, server_rec *s)
Proxy Extension Module for Apache.
return NULL
Definition mod_so.c:359
int i
Definition mod_so.c:347
static proxy_worker * proxy_balancer_get_best_worker(proxy_balancer *balancer, request_rec *r, proxy_is_best_callback_fn_t *is_best, void *baton)
Apache scoreboard library.
apr_array_header_t * workers
Definition mod_proxy.h:559
proxy_worker_shared * s
Definition mod_proxy.h:505
A structure that represents the current request.
Definition httpd.h:845
A structure to store information for each virtual server.
Definition httpd.h:1322