Project

General

Profile

Feature #2117 ยป lighttpd-sticky.patch

bra, 2009-12-10 13:49

View differences:

lighttpd-1.4.25-sticky/src/mod_proxy.c 2009-12-09 15:35:15.000000000 +0100
PROXY_BALANCE_UNSET,
PROXY_BALANCE_FAIR,
PROXY_BALANCE_HASH,
PROXY_BALANCE_RR
PROXY_BALANCE_RR,
PROXY_BALANCE_STICKY
} proxy_balance_t;
typedef struct {
......
s->balance = PROXY_BALANCE_RR;
} else if (buffer_is_equal_string(p->balance_buf, CONST_STR_LEN("hash"))) {
s->balance = PROXY_BALANCE_HASH;
} else if (buffer_is_equal_string(p->balance_buf, CONST_STR_LEN("sticky"))) {
s->balance = PROXY_BALANCE_STICKY;
} else {
log_error_write(srv, __FILE__, __LINE__, "sb",
"proxy.balance has to be one of: fair, round-robin, hash, but not:", p->balance_buf);
"proxy.balance has to be one of: fair, round-robin, hash, sticky, but not:", p->balance_buf);
return HANDLER_ERROR;
}
......
ndx = 0;
}
} else if (extension->value->used != 0) switch(p->conf.balance) {
case PROXY_BALANCE_STICKY:
/* source sticky balancing */
if (p->conf.debug) {
log_error_write(srv, __FILE__, __LINE__, "sd",
"proxy - used sticky balancing, hosts:", extension->value->used);
}
for (k = 0, ndx = -1, last_max = ULONG_MAX; k < extension->value->used; k++) {
data_proxy *host = (data_proxy *)extension->value->data[k];
unsigned long cur_max;
if (host->is_disabled) continue;
char *remote_ip;
remote_ip = strdup(inet_ntop_cache_get_ip(srv, &(con->dst_addr)));
cur_max = generate_crc32c(remote_ip, strlen(remote_ip)) +
generate_crc32c(CONST_BUF_LEN(host->host)) +
host->port;
if (p->conf.debug) {
log_error_write(srv, __FILE__, __LINE__, "ssbdd",
"proxy - election:",
remote_ip,
host->host,
host->port,
cur_max);
}
if ((last_max == ULONG_MAX) || /* first round */
(cur_max > last_max)) {
last_max = cur_max;
ndx = k;
}
}
break;
case PROXY_BALANCE_HASH:
/* hash balancing */
    (1-1/1)