/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
*/
#ifndef LBM_HEARTBEAT_MAX_LASTSEEN /* If we haven't seen a heartbeat in the last N seconds, don't count this IP * as allive.
*/ #define LBM_HEARTBEAT_MAX_LASTSEEN (10) #endif
/* * configuration structure * path: path of the file where the heartbeat information is stored.
*/ typedefstruct lb_hb_ctx_t
{ constchar *path;
} lb_hb_ctx_t;
typedefstruct hb_server_t { constchar *ip; int busy; int ready; int port; int id;
apr_time_t seen;
proxy_worker *worker;
} hb_server_t;
if ((val = apr_table_get(hbt, "busy"))) {
server->busy = atoi(val);
}
if ((val = apr_table_get(hbt, "ready"))) {
server->ready = atoi(val);
}
if ((val = apr_table_get(hbt, "lastseen"))) {
server->seen = atoi(val);
}
if ((val = apr_table_get(hbt, "port"))) {
server->port = atoi(val);
}
if (server->busy == 0 && server->ready != 0) { /* Server has zero threads active, but lots of them ready, * it likely just started up, so lets /4 the number ready, * to prevent us from completely flooding it with all new * requests.
*/
server->ready = server->ready / 4;
}
ap_proxy_retry_worker_fn =
APR_RETRIEVE_OPTIONAL_FN(ap_proxy_retry_worker); if (!ap_proxy_retry_worker_fn) { /* can only happen if mod_proxy isn't loaded */ return NULL;
}
for (i = 0; i < balancer->workers->nelts; i++) {
worker = &APR_ARRAY_IDX(balancer->workers, i, proxy_worker *);
server = apr_hash_get(servers, (*worker)->s->hostname_ex, APR_HASH_KEY_STRING);
if (!server) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, rv, r, APLOGNO(01214) "lb_heartbeat: No server for worker %s", (*worker)->s->name_ex); continue;
}
if (!PROXY_WORKER_IS_USABLE(*worker)) {
ap_proxy_retry_worker_fn("BALANCER", *worker, r->server);
}
if (openslots > 0) {
apr_uint32_t c = 0;
apr_uint32_t pick = 0;
pick = ap_random_pick(0, openslots);
for (i = 0; i < up_servers->nelts; i++) {
server = APR_ARRAY_IDX(up_servers, i, hb_server_t *); if (pick >= c && pick <= c + server->ready) {
mycandidate = server->worker;
}
/* do nothing on first call */ if (ap_state_query(AP_SQ_MAIN_STATE) == AP_SQ_MS_CREATE_PRE_CONFIG) return OK;
storage = ap_lookup_provider(AP_SLOTMEM_PROVIDER_GROUP, "shm",
AP_SLOTMEM_PROVIDER_VERSION); if (!storage) {
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s, APLOGNO(02281) "Failed to lookup provider 'shm' for '%s'. Maybe you " "need to load mod_slotmem_shm?",
AP_SLOTMEM_PROVIDER_GROUP); return OK;
}
/* Try to use a slotmem created by mod_heartmonitor */
storage->attach(&hm_serversmem, "mod_heartmonitor", &size, &num, p); if (!hm_serversmem)
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s, APLOGNO(02282) "No slotmem from mod_heartmonitor"); else
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s, APLOGNO(02283) "Using slotmem from mod_heartmonitor");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.