Skip to content

Commit

Permalink
improve with nginx_upstream_check_module
Browse files Browse the repository at this point in the history
  • Loading branch information
sysulq committed Aug 27, 2014
1 parent a18b409 commit 3df8e6b
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions ngx_http_upstream_fair_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ typedef struct {
ngx_uint_t max_fails;
time_t fail_timeout;

#if (NGX_HTTP_UPSTREAM_CHECK)
ngx_uint_t check_index;
#endif

time_t accessed;
ngx_uint_t down:1;

Expand Down Expand Up @@ -474,6 +478,16 @@ ngx_http_upstream_init_fair_rr(ngx_conf_t *cf, ngx_http_upstream_srv_conf_t *us)
peers->peer[n].fail_timeout = server[i].fail_timeout;
peers->peer[n].down = server[i].down;
peers->peer[n].weight = server[i].down ? 0 : server[i].weight;

#if (NGX_HTTP_UPSTREAM_CHECK)
if (!server[i].down) {
peers->peer[n].check_index =
ngx_http_upstream_check_add_peer(cf, us, &server[i].addrs[j]);
} else {
peers->peer[n].check_index = (ngx_uint_t) NGX_ERROR;
}
#endif

n++;
}
}
Expand Down Expand Up @@ -524,6 +538,16 @@ ngx_http_upstream_init_fair_rr(ngx_conf_t *cf, ngx_http_upstream_srv_conf_t *us)
backup->peer[n].max_fails = server[i].max_fails;
backup->peer[n].fail_timeout = server[i].fail_timeout;
backup->peer[n].down = server[i].down;

#if (NGX_HTTP_UPSTREAM_CHECK)
if (!server[i].down) {
backup->peer[n].check_index =
ngx_http_upstream_check_add_peer(cf, us, &server[i].addrs[j]);
} else {
backup->peer[n].check_index = (ngx_uint_t) NGX_ERROR;
}
#endif

n++;
}
}
Expand Down Expand Up @@ -580,6 +604,11 @@ ngx_http_upstream_init_fair_rr(ngx_conf_t *cf, ngx_http_upstream_srv_conf_t *us)
peers->peer[i].weight = 1;
peers->peer[i].max_fails = 1;
peers->peer[i].fail_timeout = 10;

#if (NGX_HTTP_UPSTREAM_CHECK)
peers->peer[i].check_index = (ngx_uint_t) NGX_ERROR;
#endif

}

us->peer.data = peers;
Expand Down Expand Up @@ -723,6 +752,15 @@ ngx_http_upstream_fair_try_peer(ngx_peer_connection_t *pc,
peer = &fp->peers->peer[peer_id];

if (!peer->down) {

#if (NGX_HTTP_UPSTREAM_CHECK)
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
"[upstream_fair] get fair peer, check_index: %ui",
peer->check_index);

if (!ngx_http_upstream_check_peer_down(peer->check_index)) {
#endif

if (peer->max_fails == 0 || peer->shared->fails < peer->max_fails) {
return NGX_OK;
}
Expand All @@ -733,6 +771,11 @@ ngx_http_upstream_fair_try_peer(ngx_peer_connection_t *pc,
peer->shared->fails = 0;
return NGX_OK;
}

#if (NGX_HTTP_UPSTREAM_CHECK)
}
#endif

}

return NGX_BUSY;
Expand Down

0 comments on commit 3df8e6b

Please sign in to comment.