Lines Matching defs:balancer

17 /* Load balancer module for Apache proxy */
26 static const char *balancer_mutex_type = "proxy-balancer-shm";
54 extern void proxy_update_members(proxy_balancer **balancer, request_rec *r,
66 if (strncasecmp(url, "balancer:", 9) == 0) {
110 proxy_balancer *balancer)
115 workers = (proxy_worker **)balancer->workers->elts;
117 for (i = 0; i < balancer->workers->nelts; i++) {
121 "Looking at %s -> %s initialized?", balancer->s->name,
133 if (!balancer->s->max_attempts_set && balancer->workers->nelts > 1) {
134 balancer->s->max_attempts = balancer->workers->nelts - 1;
135 balancer->s->max_attempts_set = 1;
204 static proxy_worker *find_route_worker(proxy_balancer *balancer,
215 workers = (proxy_worker **)balancer->workers->elts;
216 for (i = 0; i < balancer->workers->nelts; i++, workers++) {
240 * balancer. Of course you will need some kind of
245 rworker = find_route_worker(balancer, worker->s->redirect, r);
269 static proxy_worker *find_session_route(proxy_balancer *balancer,
277 if (!*balancer->s->sticky)
280 *route = get_path_param(r->pool, *url, balancer->s->sticky_path, balancer->s->scolonsep);
284 *route, balancer->s->sticky_path);
285 *sticky_used = balancer->s->sticky_path;
288 *route = get_cookie_param(r, balancer->s->sticky);
290 *sticky_used = balancer->s->sticky;
293 *route, balancer->s->sticky);
301 if ((*route) && (balancer->s->sticky_separator != 0) && ((*route = strchr(*route, balancer->s->sticky_separator)) != NULL ))
308 worker = find_route_worker(balancer, *route, r);
325 static proxy_worker *find_best_worker(proxy_balancer *balancer,
331 if ((rv = PROXY_THREAD_LOCK(balancer)) != APR_SUCCESS) {
334 balancer->s->name);
338 candidate = (*balancer->lbmethod->finder)(balancer, r);
343 if ((rv = PROXY_THREAD_UNLOCK(balancer)) != APR_SUCCESS) {
346 balancer->s->name);
351 * If the balancer has a timeout sleep for a while
357 if (balancer->s->timeout) {
363 apr_interval_time_t timeout = balancer->s->timeout;
368 balancer->s->timeout = 0;
373 if ((candidate = find_best_worker(balancer, r)))
378 balancer->s->timeout = timeout;
407 static void force_recovery(proxy_balancer *balancer, server_rec *s)
413 worker = (proxy_worker **)balancer->workers->elts;
414 for (i = 0; i < balancer->workers->nelts; i++, worker++) {
428 if (!ok && balancer->s->forcerecovery) {
431 worker = (proxy_worker **)balancer->workers->elts;
432 for (i = 0; i < balancer->workers->nelts; i++, worker++) {
437 balancer->s->name, (*worker)->s->hostname);
454 proxy_balancer **balancer,
466 * The url we can handle starts with 'balancer://'
467 * If balancer is already provided skip the search
468 * for balancer, because this is failover attempt.
470 if (!*balancer &&
471 !(*balancer = ap_proxy_get_balancer(r->pool, conf, *url, 1)))
477 if ((rv = PROXY_THREAD_LOCK(*balancer)) != APR_SUCCESS) {
479 "%s: Lock failed for pre_request", (*balancer)->s->name);
484 force_recovery(*balancer, r->server);
486 /* Step 3.5: Update member list for the balancer */
488 ap_proxy_sync_balancer(*balancer, r->server, conf);
491 runtime = find_session_route(*balancer, r, &route, &sticky, url);
493 if ((*balancer)->lbmethod && (*balancer)->lbmethod->updatelbstatus) {
495 (*balancer)->lbmethod->updatelbstatus(*balancer, runtime, r->server);
500 /* We have a sticky load balancer
505 workers = (proxy_worker **)(*balancer)->workers->elts;
506 for (i = 0; i < (*balancer)->workers->nelts; i++) {
522 else if (route && (*balancer)->s->sticky_force) {
527 * balancer name. See if the provider route is the
528 * member of the same balancer in which case return 503
530 workers = (proxy_worker **)(*balancer)->workers->elts;
531 for (i = 0; i < (*balancer)->workers->nelts; i++) {
541 (*balancer)->s->name, route);
542 if ((rv = PROXY_THREAD_UNLOCK(*balancer)) != APR_SUCCESS) {
545 (*balancer)->s->name);
551 if ((rv = PROXY_THREAD_UNLOCK(*balancer)) != APR_SUCCESS) {
554 (*balancer)->s->name);
557 runtime = find_best_worker(*balancer, r);
559 if ((*balancer)->workers->nelts) {
562 (*balancer)->s->name);
565 "%s: No workers in balancer",
566 (*balancer)->s->name);
571 if (*(*balancer)->s->sticky && runtime) {
573 * This balancer has sticky sessions and the client either has not
577 * balancer where we can send the request. Thus notice that we have
589 /* Add balancer/worker info to env. */
591 "BALANCER_NAME", (*balancer)->s->name);
597 /* Rewrite the url from 'balancer://url'
616 (*balancer)->s->name, (*worker)->s->name, *url);
622 proxy_balancer *balancer,
629 if ((rv = PROXY_THREAD_LOCK(balancer)) != APR_SUCCESS) {
632 balancer->s->name);
636 if (!apr_is_empty_array(balancer->errstatuses)
639 for (i = 0; i < balancer->errstatuses->nelts; i++) {
640 int val = ((int *)balancer->errstatuses->elts)[i];
645 "balancer parameter",
646 balancer->s->name, ap_proxy_worker_name(r->pool, worker),
655 if (balancer->failontimeout
661 balancer->s->name, ap_proxy_worker_name(r->pool, worker));
667 if ((rv = PROXY_THREAD_UNLOCK(balancer)) != APR_SUCCESS) {
669 "%s: Unlock failed for post_request", balancer->s->name);
672 "proxy_balancer_post_request for (%s)", balancer->s->name);
677 static void recalc_factors(proxy_balancer *balancer)
684 workers = (proxy_worker **)balancer->workers->elts;
688 if (balancer->workers->nelts == 1) {
692 for (i = 0; i < balancer->workers->nelts; i++) {
701 proxy_balancer *balancer;
706 balancer = (proxy_balancer *)conf->balancers->elts;
707 for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
708 if (balancer->gmutex) {
709 apr_global_mutex_destroy(balancer->gmutex);
710 balancer->gmutex = NULL;
757 * each balancer's workers
762 proxy_balancer *balancer;
801 ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01179) "balancer slotmem_create failed");
809 balancer = (proxy_balancer *)conf->balancers->elts;
810 for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
818 ap_pstr2_alnum(pconf, balancer->s->name + sizeof(BALANCER_PREFIX) - 1,
821 PROXY_STRNCPY(balancer->s->sname, sname); /* We know this will succeed */
823 balancer->max_workers = balancer->workers->nelts + balancer->growth;
826 rv = ap_global_mutex_create(&(balancer->gmutex), NULL, balancer_mutex_type,
827 balancer->s->sname, s, pconf, 0);
828 if (rv != APR_SUCCESS || !balancer->gmutex) {
831 balancer->s->sname);
839 bshm = ap_proxy_find_balancershm(storage, conf->bslot, balancer, &index);
842 ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(02408) "balancer slotmem_fgrab failed");
848 ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01181) "balancer slotmem_grab failed");
852 ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01182) "balancer slotmem_dptr failed");
856 if ((rv = ap_proxy_share_balancer(balancer, bshm, index)) != APR_SUCCESS) {
857 ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01183) "Cannot share balancer");
863 balancer->s->name, balancer->s->sname,
865 (int)balancer->max_workers, i);
867 rv = storage->create(&new, balancer->s->sname,
869 balancer->max_workers, type, pconf);
874 balancer->wslot = new;
875 balancer->storage = storage;
878 balancer->wupdated = balancer->s->wupdated = tstamp;
881 workers = (proxy_worker **)balancer->workers->elts;
882 for (j = 0; j < balancer->workers->nelts; j++, workers++) {
887 shm = ap_proxy_find_workershm(storage, balancer->wslot, worker, &index);
889 if ((rv = storage->fgrab(balancer->wslot, index)) != APR_SUCCESS) {
895 if ((rv = storage->grab(balancer->wslot, &index)) != APR_SUCCESS) {
900 if ((rv = storage->dptr(balancer->wslot, index, (void *)&shm)) != APR_SUCCESS) {
913 balancer->wupdated--;
914 ap_proxy_sync_balancer(balancer, s, conf);
975 * The balancer, worker and nonce are obtained from
980 * /.../<whatever>/balancer/worker/nonce
986 proxy_balancer *balancer, *bsel = NULL;
997 if (strcmp(r->handler, "balancer-manager")) {
1012 balancer = (proxy_balancer *)conf->balancers->elts;
1013 for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
1014 if ((rv = PROXY_THREAD_LOCK(balancer)) != APR_SUCCESS) {
1017 balancer->s->name);
1019 ap_proxy_sync_balancer(balancer, r->server, conf);
1020 if ((rv = PROXY_THREAD_UNLOCK(balancer)) != APR_SUCCESS) {
1023 balancer->s->name);
1127 "settings balancer params");
1255 balancer = (proxy_balancer *)conf->balancers->elts;
1257 ap_rputs(" <httpd:balancer>\n", r);
1259 ap_rvputs(r, " <httpd:name>", balancer->s->name, "</httpd:name>\n", NULL);
1260 if (balancer->s->sticky) {
1261 ap_rvputs(r, " <httpd:stickysession>", balancer->s->sticky,
1265 (balancer->s->sticky_force ? "On" : "Off"));
1269 apr_time_sec(balancer->s->timeout));
1270 if (balancer->s->max_attempts_set) {
1273 balancer->s->max_attempts);
1275 ap_rvputs(r, " <httpd:lbmethod>", balancer->lbmethod->name,
1277 if (balancer->s->sticky) {
1280 (balancer->s->scolonsep ? "On" : "Off"));
1284 workers = (proxy_worker **)balancer->workers->elts;
1285 for (n = 0; n < balancer->workers->nelts; n++) {
1427 ap_rputs(" </httpd:balancer>\n", r);
1428 ++balancer;
1478 balancer = (proxy_balancer *)conf->balancers->elts;
1483 balancer->s->name + sizeof(BALANCER_PREFIX) - 1,
1484 "&amp;nonce=", balancer->s->nonce,
1486 ap_rvputs(r, balancer->s->name, "</a> [",balancer->s->sname, "]</h3>\n", NULL);
1492 ap_rprintf(r, "<td>%d [%d Used]</td>\n", balancer->max_workers,
1493 balancer->max_workers - (int)storage->num_free_slots(balancer->wslot));
1494 if (*balancer->s->sticky) {
1495 if (strcmp(balancer->s->sticky, balancer->s->sticky_path)) {
1496 ap_rvputs(r, "<td>", balancer->s->sticky, " | ",
1497 balancer->s->sticky_path, NULL);
1500 ap_rvputs(r, "<td>", balancer->s->sticky, NULL);
1507 balancer->s->sticky_force ? "On" : "Off");
1509 apr_time_sec(balancer->s->timeout));
1510 ap_rprintf(r, "<td>%d</td>\n", balancer->s->max_attempts);
1512 balancer->s->lbpname);
1514 if (balancer->s->vhost && *(balancer->s->vhost)) {
1515 ap_rvputs(r, balancer->s->vhost, " -> ", NULL);
1517 ap_rvputs(r, balancer->s->vpath, "</td>\n", NULL);
1519 !balancer->s->inactive ? "Yes" : "No");
1528 workers = (proxy_worker **)balancer->workers->elts;
1529 for (n = 0; n < balancer->workers->nelts; n++) {
1534 balancer->s->name + sizeof(BALANCER_PREFIX) - 1, "&amp;w=",
1536 "&amp;nonce=", balancer->s->nonce,
1559 ++balancer;
1604 ap_rputs("<h3>Edit balancer settings for ", r);
1661 proxy_balancer *balancer;
1677 balancer = (proxy_balancer *)conf->balancers->elts;
1678 for (i = 0; i < conf->balancers->nelts; i++, balancer++) {
1679 rv = ap_proxy_initialize_balancer(balancer, s, p);
1683 "Failed to init balancer %s in child",
1684 balancer->s->name);
1687 init_balancer_members(conf->pool, s, balancer);