Klaus Demo nginx / 6dae95a
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. Roman Arutyunyan 3 years ago
3 changed file(s) with 37 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
807807
808808 u->state->connect_time = ngx_current_msec - u->state->response_time;
809809
810 if (u->peer.notify) {
811 u->peer.notify(&u->peer, u->peer.data,
812 NGX_STREAM_UPSTREAM_NOTIFY_CONNECT);
813 }
814
810815 c->log->action = "proxying connection";
811816
812817 if (u->upstream_buf.start == NULL) {
2121 #define NGX_STREAM_UPSTREAM_DOWN 0x0010
2222 #define NGX_STREAM_UPSTREAM_BACKUP 0x0020
2323 #define NGX_STREAM_UPSTREAM_MAX_CONNS 0x0100
24
25
26 #define NGX_STREAM_UPSTREAM_NOTIFY_CONNECT 0x1
2427
2528
2629 typedef struct {
1515
1616 static ngx_stream_upstream_rr_peer_t *ngx_stream_upstream_get_peer(
1717 ngx_stream_upstream_rr_peer_data_t *rrp);
18 static void ngx_stream_upstream_notify_round_robin_peer(
19 ngx_peer_connection_t *pc, void *data, ngx_uint_t state);
1820
1921 #if (NGX_STREAM_SSL)
2022
287289
288290 s->upstream->peer.get = ngx_stream_upstream_get_round_robin_peer;
289291 s->upstream->peer.free = ngx_stream_upstream_free_round_robin_peer;
292 s->upstream->peer.notify = ngx_stream_upstream_notify_round_robin_peer;
290293 s->upstream->peer.tries = ngx_stream_upstream_tries(rrp->peers);
291294 #if (NGX_STREAM_SSL)
292295 s->upstream->peer.set_session =
658661 }
659662
660663
664 static void
665 ngx_stream_upstream_notify_round_robin_peer(ngx_peer_connection_t *pc,
666 void *data, ngx_uint_t type)
667 {
668 ngx_stream_upstream_rr_peer_data_t *rrp = data;
669
670 ngx_stream_upstream_rr_peer_t *peer;
671
672 peer = rrp->current;
673
674 if (type == NGX_STREAM_UPSTREAM_NOTIFY_CONNECT
675 && pc->connection->type == SOCK_STREAM)
676 {
677 ngx_stream_upstream_rr_peers_rlock(rrp->peers);
678 ngx_stream_upstream_rr_peer_lock(rrp->peers, peer);
679
680 if (peer->accessed < peer->checked) {
681 peer->fails = 0;
682 }
683
684 ngx_stream_upstream_rr_peer_unlock(rrp->peers, peer);
685 ngx_stream_upstream_rr_peers_unlock(rrp->peers);
686 }
687 }
688
689
661690 #if (NGX_STREAM_SSL)
662691
663692 static ngx_int_t