Mercurial > hg > nginx-quic
comparison src/stream/ngx_stream_upstream_round_robin.c @ 6863:54cf51c4f07a
Stream: speed up TCP peer recovery.
Previously, an unavailable peer was considered recovered after a successful
proxy session to this peer. Until then, only a single client connection per
fail_timeout was allowed to be proxied to the peer.
Since stream sessions can be long, it may take indefinite time for a peer to
recover, limiting the ability of the peer to receive new connections.
Now, a peer is considered recovered after a successful TCP connection is
established to it. Balancers are notified of this event via the notify()
callback.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Mon, 26 Dec 2016 14:27:05 +0300 |
parents | d1d0dd69a419 |
children | 696df3ac27ac |
comparison
equal
deleted
inserted
replaced
6862:abb0a4189cf7 | 6863:54cf51c4f07a |
---|---|
14 + ((p)->next ? (p)->next->number : 0)) | 14 + ((p)->next ? (p)->next->number : 0)) |
15 | 15 |
16 | 16 |
17 static ngx_stream_upstream_rr_peer_t *ngx_stream_upstream_get_peer( | 17 static ngx_stream_upstream_rr_peer_t *ngx_stream_upstream_get_peer( |
18 ngx_stream_upstream_rr_peer_data_t *rrp); | 18 ngx_stream_upstream_rr_peer_data_t *rrp); |
19 static void ngx_stream_upstream_notify_round_robin_peer( | |
20 ngx_peer_connection_t *pc, void *data, ngx_uint_t state); | |
19 | 21 |
20 #if (NGX_STREAM_SSL) | 22 #if (NGX_STREAM_SSL) |
21 | 23 |
22 static ngx_int_t ngx_stream_upstream_set_round_robin_peer_session( | 24 static ngx_int_t ngx_stream_upstream_set_round_robin_peer_session( |
23 ngx_peer_connection_t *pc, void *data); | 25 ngx_peer_connection_t *pc, void *data); |
286 } | 288 } |
287 } | 289 } |
288 | 290 |
289 s->upstream->peer.get = ngx_stream_upstream_get_round_robin_peer; | 291 s->upstream->peer.get = ngx_stream_upstream_get_round_robin_peer; |
290 s->upstream->peer.free = ngx_stream_upstream_free_round_robin_peer; | 292 s->upstream->peer.free = ngx_stream_upstream_free_round_robin_peer; |
293 s->upstream->peer.notify = ngx_stream_upstream_notify_round_robin_peer; | |
291 s->upstream->peer.tries = ngx_stream_upstream_tries(rrp->peers); | 294 s->upstream->peer.tries = ngx_stream_upstream_tries(rrp->peers); |
292 #if (NGX_STREAM_SSL) | 295 #if (NGX_STREAM_SSL) |
293 s->upstream->peer.set_session = | 296 s->upstream->peer.set_session = |
294 ngx_stream_upstream_set_round_robin_peer_session; | 297 ngx_stream_upstream_set_round_robin_peer_session; |
295 s->upstream->peer.save_session = | 298 s->upstream->peer.save_session = |
657 pc->tries--; | 660 pc->tries--; |
658 } | 661 } |
659 } | 662 } |
660 | 663 |
661 | 664 |
665 static void | |
666 ngx_stream_upstream_notify_round_robin_peer(ngx_peer_connection_t *pc, | |
667 void *data, ngx_uint_t type) | |
668 { | |
669 ngx_stream_upstream_rr_peer_data_t *rrp = data; | |
670 | |
671 ngx_stream_upstream_rr_peer_t *peer; | |
672 | |
673 peer = rrp->current; | |
674 | |
675 if (type == NGX_STREAM_UPSTREAM_NOTIFY_CONNECT | |
676 && pc->connection->type == SOCK_STREAM) | |
677 { | |
678 ngx_stream_upstream_rr_peers_rlock(rrp->peers); | |
679 ngx_stream_upstream_rr_peer_lock(rrp->peers, peer); | |
680 | |
681 if (peer->accessed < peer->checked) { | |
682 peer->fails = 0; | |
683 } | |
684 | |
685 ngx_stream_upstream_rr_peer_unlock(rrp->peers, peer); | |
686 ngx_stream_upstream_rr_peers_unlock(rrp->peers); | |
687 } | |
688 } | |
689 | |
690 | |
662 #if (NGX_STREAM_SSL) | 691 #if (NGX_STREAM_SSL) |
663 | 692 |
664 static ngx_int_t | 693 static ngx_int_t |
665 ngx_stream_upstream_set_round_robin_peer_session(ngx_peer_connection_t *pc, | 694 ngx_stream_upstream_set_round_robin_peer_session(ngx_peer_connection_t *pc, |
666 void *data) | 695 void *data) |