Browse Source

Added round-robin support to mod_fastcgi.

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@1500 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/tags/lighttpd-1.4.14
Robert Jakabosky 16 years ago
parent
commit
db76b98e03
  1. 26
      src/mod_fastcgi.c
  2. 1
      src/mod_proxy.c

26
src/mod_fastcgi.c

@ -275,6 +275,7 @@ typedef struct {
buffer *key; /* like .php */
int note_is_sent;
int last_used_ndx;
fcgi_extension_host **hosts;
@ -563,6 +564,7 @@ int fastcgi_extension_insert(fcgi_exts *ext, buffer *key, fcgi_extension_host *f
fe = calloc(1, sizeof(*fe));
assert(fe);
fe->key = buffer_init();
fe->last_used_ndx = -1;
buffer_copy_string_buffer(fe->key, key);
/* */
@ -2381,6 +2383,7 @@ static int fcgi_demux_response(server *srv, handler_ctx *hctx) {
/* append to read-buffer */
if (-1 == (r = read(hctx->fd, b->ptr, toread))) {
if (errno == EAGAIN) return 0;
log_error_write(srv, __FILE__, __LINE__, "sds",
"unexpected end-of-file (perhaps the fastcgi process died):",
fcgi_fd, strerror(errno));
@ -2979,17 +2982,23 @@ SUBREQUEST_FUNC(mod_fastcgi_handle_subrequest) {
size_t k;
int ndx, used = -1;
/* get best server */
for (k = 0, ndx = -1; k < hctx->ext->used; k++) {
host = hctx->ext->hosts[k];
/* check if the next server has no load. */
ndx = hctx->ext->last_used_ndx + 1;
if(ndx >= hctx->ext->used || ndx < 0) ndx = 0;
host = hctx->ext->hosts[ndx];
if (host->load > 0) {
/* get backend with the least load. */
for (k = 0, ndx = -1; k < hctx->ext->used; k++) {
host = hctx->ext->hosts[k];
/* we should have at least one proc that can do something */
if (host->active_procs == 0) continue;
/* we should have at least one proc that can do something */
if (host->active_procs == 0) continue;
if (used == -1 || host->load < used) {
used = host->load;
if (used == -1 || host->load < used) {
used = host->load;
ndx = k;
ndx = k;
}
}
}
@ -3005,6 +3014,7 @@ SUBREQUEST_FUNC(mod_fastcgi_handle_subrequest) {
return HANDLER_FINISHED;
}
hctx->ext->last_used_ndx = ndx;
host = hctx->ext->hosts[ndx];
/*

1
src/mod_proxy.c

@ -656,6 +656,7 @@ static int proxy_demux_response(server *srv, handler_ctx *hctx) {
}
if (-1 == (r = read(hctx->fd, hctx->response->ptr + hctx->response->used - 1, b))) {
if (errno == EAGAIN) return 0;
log_error_write(srv, __FILE__, __LINE__, "sds",
"unexpected end-of-file (perhaps the proxy process died):",
proxy_fd, strerror(errno));

Loading…
Cancel
Save