Apache HTTPD
mod_lbmethod_bytraffic.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_bytraffic_module;
24
27
29{
31 apr_off_t traffic = (current->s->transferred / current->s->lbfactor)
32 + (current->s->read / current->s->lbfactor);
33
34 if (!prev_best || (traffic < *min_traffic)) {
36
37 return TRUE;
38 }
39
40 return FALSE;
41}
42
43/*
44 * The idea behind the find_best_bytraffic scheduler is the following:
45 *
46 * We know the amount of traffic (bytes in and out) handled by each
47 * worker. We normalize that traffic by each workers' weight. So assuming
48 * a setup as below:
49 *
50 * worker a b c
51 * lbfactor 1 1 3
52 *
53 * the scheduler will allow worker c to handle 3 times the
54 * traffic of a and b. If each request/response results in the
55 * same amount of traffic, then c would be accessed 3 times as
56 * often as a or b. If, for example, a handled a request that
57 * resulted in a large i/o bytecount, then b and c would be
58 * chosen more often, to even things out.
59 */
68
69/* assumed to be mutex protected by caller */
71{
72 int i;
73 proxy_worker **worker;
74 worker = (proxy_worker **)balancer->workers->elts;
75 for (i = 0; i < balancer->workers->nelts; i++, worker++) {
76 (*worker)->s->transferred = 0;
77 (*worker)->s->read = 0;
78 }
79 return APR_SUCCESS;
80}
81
83{
84 return APR_SUCCESS;
85}
86
88{
89 "bytraffic",
91 NULL,
92 &reset,
93 &age,
94 NULL
95};
96
97/* post_config hook: */
99 apr_pool_t *ptemp, server_rec *s)
100{
101
102 /* lbmethod_bytraffic_post_config() will be called twice during startup. So, don't
103 * set up the static data the 1st time through. */
105 return OK;
106 }
107
112 "mod_proxy must be loaded for mod_lbmethod_bytraffic");
113 return !OK;
114 }
115
116 return OK;
117}
118
124
127 NULL, /* create per-directory config structure */
128 NULL, /* merge per-directory config structures */
129 NULL, /* create per-server config structure */
130 NULL, /* merge per-server config structures */
131 NULL, /* command apr_table_t */
132 register_hook /* register hooks */
133};
ap hook functions and macros
Apache Multi-Processing Module library.
#define TRUE
Definition abts.h:38
#define FALSE
Definition abts.h:35
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 int is_best_bytraffic(proxy_worker *current, proxy_worker *prev_best, void *baton)
static apr_status_t age(proxy_balancer *balancer, server_rec *s)
static void register_hook(apr_pool_t *p)
static proxy_worker * find_best_bytraffic(proxy_balancer *balancer, request_rec *r)
static apr_OFN_proxy_balancer_get_best_worker_t * ap_proxy_balancer_get_best_worker_fn
static const proxy_balancer_method bytraffic
static apr_status_t reset(proxy_balancer *balancer, server_rec *s)
static int lbmethod_bytraffic_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, 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
apr_off_t transferred
Definition mod_proxy.h:462
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