diff options
| author | Garrett D'Amore <garrett@damore.org> | 2019-02-18 20:15:16 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2019-02-23 11:50:17 -0800 |
| commit | 64e784237d143aa032311942bc44abd22e1e4114 (patch) | |
| tree | e3ea529d5e5adfd022773ab207622cc2247f057c /src/core | |
| parent | d210ef96517c1462bc058c95bced8c27b5e19c4f (diff) | |
| download | nng-64e784237d143aa032311942bc44abd22e1e4114.tar.gz nng-64e784237d143aa032311942bc44abd22e1e4114.tar.bz2 nng-64e784237d143aa032311942bc44abd22e1e4114.zip | |
fixes #848 server hang waiting for client handshake
fixes #698 Need TCP stats
fixes #699 Need IPC stats
fixes #701 Need TLS stats
This commit addresses a problem when negotiating using one of the stream
based negotiation APIs -- a slow or misbehaving peer can prevent well
behaved ones from establishing a connection. The fix is a fairly
significant change in how these transports link up, and it does rely
on the fact that the socket only has a single accept() or connect()
pending at a time (on a given endpoint that is).
While here, we have completely revamped the way transport statistics are
done, offering a standard API for collecting these statistics.
Unfortunately, this completely borks the statistics for inproc. As we
are planning to change the way inproc works soon, in order to provide
more control and work on performance fixes for the message queue, we feel
this is an acceptable trade-off. Furthermore, almost nobody uses inproc
for anything, and even fewer people are making use of the statistics
at this time.
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/dialer.c | 76 | ||||
| -rw-r--r-- | src/core/dialer.h | 3 | ||||
| -rw-r--r-- | src/core/listener.c | 69 | ||||
| -rw-r--r-- | src/core/listener.h | 1 | ||||
| -rw-r--r-- | src/core/pipe.c | 38 | ||||
| -rw-r--r-- | src/core/pipe.h | 8 | ||||
| -rw-r--r-- | src/core/socket.c | 30 | ||||
| -rw-r--r-- | src/core/sockimpl.h | 25 |
8 files changed, 178 insertions, 72 deletions
diff --git a/src/core/dialer.c b/src/core/dialer.c index f0589275..ffbef8a7 100644 --- a/src/core/dialer.c +++ b/src/core/dialer.c @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // Copyright 2018 Devolutions <info@devolutions.net> // @@ -94,31 +94,69 @@ dialer_stats_init(nni_dialer *d) nni_stat_init_atomic(&st->s_npipes, "npipes", "open pipes"); nni_stat_append(root, &st->s_npipes); - nni_stat_init_atomic(&st->s_connok, "connok", "connections made"); - nni_stat_append(root, &st->s_connok); - nni_stat_init_atomic( - &st->s_canceled, "canceled", "connections canceled"); - nni_stat_append(root, &st->s_canceled); + &st->s_connok, "connect", "connections established"); + nni_stat_append(root, &st->s_connok); nni_stat_init_atomic(&st->s_refused, "refused", "connections refused"); nni_stat_append(root, &st->s_refused); - nni_stat_init_atomic( - &st->s_timedout, "timedout", "connections timed out"); - nni_stat_append(root, &st->s_timedout); + nni_stat_init_atomic(&st->s_discon, "discon", "remote disconnects"); + nni_stat_append(root, &st->s_discon); - nni_stat_init_atomic( - &st->s_othererr, "othererr", "other connection errors"); + nni_stat_init_atomic(&st->s_canceled, "canceled", "canceled"); + nni_stat_append(root, &st->s_canceled); + + nni_stat_init_atomic(&st->s_othererr, "othererr", "other errors"); nni_stat_append(root, &st->s_othererr); - nni_stat_init_atomic( - &st->s_protorej, "protoreject", "pipes rejected by protocol"); - nni_stat_append(root, &st->s_protorej); + nni_stat_init_atomic(&st->s_etimedout, "timedout", "timed out"); + nni_stat_append(root, &st->s_etimedout); - nni_stat_init_atomic( - &st->s_apprej, "appreject", "pipes rejected by application"); - nni_stat_append(root, &st->s_apprej); + nni_stat_init_atomic(&st->s_eproto, "protoerr", "protcol errors"); + nni_stat_append(root, &st->s_eproto); + + nni_stat_init_atomic(&st->s_eauth, "autherr", "auth errors"); + nni_stat_append(root, &st->s_eauth); + + nni_stat_init_atomic(&st->s_enomem, "nomem", "out of memory"); + nni_stat_append(root, &st->s_enomem); + + nni_stat_init_atomic(&st->s_reject, "reject", "pipes rejected"); + nni_stat_append(root, &st->s_reject); +} + +void +nni_dialer_bump_error(nni_dialer *d, int err) +{ + switch (err) { + case NNG_ECONNABORTED: + case NNG_ECONNRESET: + BUMPSTAT(&d->d_stats.s_discon); + break; + case NNG_ECONNREFUSED: + BUMPSTAT(&d->d_stats.s_refused); + break; + case NNG_ECANCELED: + BUMPSTAT(&d->d_stats.s_canceled); + break; + case NNG_ETIMEDOUT: + BUMPSTAT(&d->d_stats.s_etimedout); + break; + case NNG_EPROTO: + BUMPSTAT(&d->d_stats.s_eproto); + break; + case NNG_EPEERAUTH: + case NNG_ECRYPTO: + BUMPSTAT(&d->d_stats.s_eauth); + break; + case NNG_ENOMEM: + BUMPSTAT(&d->d_stats.s_enomem); + break; + default: + BUMPSTAT(&d->d_stats.s_othererr); + break; + } } int @@ -304,10 +342,8 @@ dialer_connect_cb(void *arg) break; case NNG_ECLOSED: // No further action. case NNG_ECANCELED: // No further action. - BUMPSTAT(&d->d_stats.s_canceled); break; case NNG_ECONNREFUSED: - BUMPSTAT(&d->d_stats.s_refused); if (uaio == NULL) { nni_dialer_timer_start(d); } else { @@ -316,7 +352,6 @@ dialer_connect_cb(void *arg) break; case NNG_ETIMEDOUT: - BUMPSTAT(&d->d_stats.s_timedout); if (uaio == NULL) { nni_dialer_timer_start(d); } else { @@ -325,7 +360,6 @@ dialer_connect_cb(void *arg) break; default: - BUMPSTAT(&d->d_stats.s_othererr); if (uaio == NULL) { nni_dialer_timer_start(d); } else { diff --git a/src/core/dialer.h b/src/core/dialer.h index af715955..200ad01d 100644 --- a/src/core/dialer.h +++ b/src/core/dialer.h @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // Copyright 2018 Devolutions <info@devolutions.net> // @@ -28,5 +28,6 @@ extern int nni_dialer_setopt( extern int nni_dialer_getopt( nni_dialer *, const char *, void *, size_t *, nni_type); extern void nni_dialer_add_stat(nni_dialer *, nni_stat_item *); +extern void nni_dialer_bump_error(nni_dialer *, int); #endif // CORE_DIALER_H diff --git a/src/core/listener.c b/src/core/listener.c index df6dab11..58758cf3 100644 --- a/src/core/listener.c +++ b/src/core/listener.c @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // Copyright 2018 Devolutions <info@devolutions.net> // @@ -98,27 +98,59 @@ listener_stats_init(nni_listener *l) nni_stat_init_atomic(&st->s_accept, "accept", "connections accepted"); nni_stat_append(root, &st->s_accept); - nni_stat_init_atomic( - &st->s_aborted, "aborted", "accepts aborted remotely"); - nni_stat_append(root, &st->s_aborted); + nni_stat_init_atomic(&st->s_discon, "discon", "remote disconnects"); + nni_stat_append(root, &st->s_discon); - nni_stat_init_atomic(&st->s_timedout, "timedout", "accepts timed out"); - nni_stat_append(root, &st->s_timedout); - - nni_stat_init_atomic(&st->s_canceled, "canceled", "accepts canceled"); + nni_stat_init_atomic(&st->s_canceled, "canceled", "canceled"); nni_stat_append(root, &st->s_canceled); - nni_stat_init_atomic( - &st->s_othererr, "othererr", "other accept errors"); + nni_stat_init_atomic(&st->s_othererr, "othererr", "other errors"); nni_stat_append(root, &st->s_othererr); - nni_stat_init_atomic( - &st->s_protorej, "protoreject", "pipes rejected by protocol"); - nni_stat_append(root, &st->s_protorej); + nni_stat_init_atomic(&st->s_etimedout, "timedout", "timed out"); + nni_stat_append(root, &st->s_etimedout); + + nni_stat_init_atomic(&st->s_eproto, "protoerr", "protcol errors"); + nni_stat_append(root, &st->s_eproto); + + nni_stat_init_atomic(&st->s_eauth, "autherr", "auth errors"); + nni_stat_append(root, &st->s_eauth); - nni_stat_init_atomic( - &st->s_apprej, "appreject", "pipes rejected by application"); - nni_stat_append(root, &st->s_apprej); + nni_stat_init_atomic(&st->s_enomem, "nomem", "out of memory"); + nni_stat_append(root, &st->s_enomem); + + nni_stat_init_atomic(&st->s_reject, "reject", "pipes rejected"); + nni_stat_append(root, &st->s_reject); +} + +void +nni_listener_bump_error(nni_listener *l, int err) +{ + switch (err) { + case NNG_ECONNABORTED: + case NNG_ECONNRESET: + BUMPSTAT(&l->l_stats.s_discon); + break; + case NNG_ECANCELED: + BUMPSTAT(&l->l_stats.s_canceled); + break; + case NNG_ETIMEDOUT: + BUMPSTAT(&l->l_stats.s_etimedout); + break; + case NNG_EPROTO: + BUMPSTAT(&l->l_stats.s_eproto); + break; + case NNG_EPEERAUTH: + case NNG_ECRYPTO: + BUMPSTAT(&l->l_stats.s_eauth); + break; + case NNG_ENOMEM: + BUMPSTAT(&l->l_stats.s_enomem); + break; + default: + BUMPSTAT(&l->l_stats.s_othererr); + break; + } } int @@ -298,24 +330,19 @@ listener_accept_cb(void *arg) break; case NNG_ECONNABORTED: // remote condition, no cooldown case NNG_ECONNRESET: // remote condition, no cooldown - BUMPSTAT(&l->l_stats.s_aborted); listener_accept_start(l); break; case NNG_ETIMEDOUT: // No need to sleep since we timed out already. - BUMPSTAT(&l->l_stats.s_timedout); listener_accept_start(l); break; case NNG_EPEERAUTH: // peer validation failure - BUMPSTAT(&l->l_stats.s_othererr); listener_accept_start(l); break; case NNG_ECLOSED: // no further action case NNG_ECANCELED: // no further action - BUMPSTAT(&l->l_stats.s_canceled); break; default: - BUMPSTAT(&l->l_stats.s_othererr); // We don't really know why we failed, but we backoff // here. This is because errors here are probably due // to system failures (resource exhaustion) and we hope diff --git a/src/core/listener.h b/src/core/listener.h index 12974880..ef87a930 100644 --- a/src/core/listener.h +++ b/src/core/listener.h @@ -28,5 +28,6 @@ extern int nni_listener_setopt( extern int nni_listener_getopt( nni_listener *, const char *, void *, size_t *, nni_type); extern void nni_listener_add_stat(nni_listener *, nni_stat_item *); +extern void nni_listener_bump_error(nni_listener *, int); #endif // CORE_LISTENER_H diff --git a/src/core/pipe.c b/src/core/pipe.c index 6ad62fa4..44957def 100644 --- a/src/core/pipe.c +++ b/src/core/pipe.c @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // Copyright 2018 Devolutions <info@devolutions.net> // @@ -228,6 +228,18 @@ pipe_create(nni_pipe **pp, nni_sock *sock, nni_tran *tran, void *tdata) nni_stat_init_id(&st->s_sock_id, "socket", "socket for pipe", nni_sock_id(p->p_sock)); nni_stat_append(&st->s_root, &st->s_sock_id); + nni_stat_init_atomic(&st->s_rxmsgs, "rxmsgs", "messages received"); + nni_stat_set_unit(&st->s_rxmsgs, NNG_UNIT_MESSAGES); + nni_stat_append(&st->s_root, &st->s_rxmsgs); + nni_stat_init_atomic(&st->s_txmsgs, "txmsgs", "messages sent"); + nni_stat_set_unit(&st->s_txmsgs, NNG_UNIT_MESSAGES); + nni_stat_append(&st->s_root, &st->s_txmsgs); + nni_stat_init_atomic(&st->s_rxbytes, "rxbytes", "bytes received"); + nni_stat_set_unit(&st->s_rxbytes, NNG_UNIT_BYTES); + nni_stat_append(&st->s_root, &st->s_rxbytes); + nni_stat_init_atomic(&st->s_txbytes, "txbytes", "bytes sent"); + nni_stat_set_unit(&st->s_txbytes, NNG_UNIT_BYTES); + nni_stat_append(&st->s_root, &st->s_txbytes); if ((rv != 0) || ((rv = p->p_tran_ops.p_init(tdata, p)) != 0) || ((rv = pops->pipe_init(&p->p_proto_data, p, sdata)) != 0)) { @@ -337,3 +349,27 @@ nni_pipe_add_stat(nni_pipe *p, nni_stat_item *item) { nni_stat_append(&p->p_stats.s_root, item); } + +void +nni_pipe_bump_rx(nni_pipe *p, size_t nbytes) +{ + nni_stat_inc_atomic(&p->p_stats.s_rxbytes, nbytes); + nni_stat_inc_atomic(&p->p_stats.s_rxmsgs, 1); +} + +void +nni_pipe_bump_tx(nni_pipe *p, size_t nbytes) +{ + nni_stat_inc_atomic(&p->p_stats.s_txbytes, nbytes); + nni_stat_inc_atomic(&p->p_stats.s_txmsgs, 1); +} + +void +nni_pipe_bump_error(nni_pipe *p, int err) +{ + if (p->p_dialer != NULL) { + nni_dialer_bump_error(p->p_dialer, err); + } else { + nni_listener_bump_error(p->p_listener, err); + } +}
\ No newline at end of file diff --git a/src/core/pipe.h b/src/core/pipe.h index 5a83059f..20d34e82 100644 --- a/src/core/pipe.h +++ b/src/core/pipe.h @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -63,6 +63,10 @@ extern uint32_t nni_pipe_dialer_id(nni_pipe *); extern void nni_pipe_rele(nni_pipe *); // nni_pipe_add_stat adds a statistic to the pipe -extern void nni_pipe_add_stat(nni_pipe *p, nni_stat_item *); +extern void nni_pipe_add_stat(nni_pipe *, nni_stat_item *); + +extern void nni_pipe_bump_rx(nni_pipe *, size_t); +extern void nni_pipe_bump_tx(nni_pipe *, size_t); +extern void nni_pipe_bump_error(nni_pipe *, int); #endif // CORE_PIPE_H diff --git a/src/core/socket.c b/src/core/socket.c index 387796a6..dadc9073 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -58,8 +58,7 @@ typedef struct sock_stats { nni_stat_item s_txbytes; // number of bytes received nni_stat_item s_rxmsgs; // number of msgs received nni_stat_item s_txmsgs; // number of msgs sent - nni_stat_item s_protorej; // pipes rejected by protocol - nni_stat_item s_apprej; // pipes rejected by application + nni_stat_item s_reject; // pipes rejected } sock_stats; struct nni_socket { @@ -465,13 +464,8 @@ sock_stats_init(nni_sock *s) nni_stat_set_unit(&st->s_txmsgs, NNG_UNIT_MESSAGES); nni_stat_append(root, &st->s_txmsgs); - nni_stat_init_atomic( - &st->s_protorej, "protoreject", "pipes rejected by protocol"); - nni_stat_append(root, &st->s_protorej); - - nni_stat_init_atomic( - &st->s_apprej, "appreject", "pipes rejected by application"); - nni_stat_append(root, &st->s_apprej); + nni_stat_init_atomic(&st->s_reject, "reject", "pipes rejected"); + nni_stat_append(root, &st->s_reject); #else NNI_ARG_UNUSED(s); #endif @@ -1441,15 +1435,15 @@ nni_dialer_add_pipe(nni_dialer *d, void *tpipe) nni_mtx_lock(&s->s_mx); if (p->p_closed) { nni_mtx_unlock(&s->s_mx); - nni_stat_inc_atomic(&d->d_stats.s_apprej, 1); - nni_stat_inc_atomic(&s->s_stats.s_apprej, 1); + nni_stat_inc_atomic(&d->d_stats.s_reject, 1); + nni_stat_inc_atomic(&s->s_stats.s_reject, 1); nni_pipe_rele(p); return; } if (p->p_proto_ops.pipe_start(p->p_proto_data) != 0) { nni_mtx_unlock(&s->s_mx); - nni_stat_inc_atomic(&d->d_stats.s_protorej, 1); - nni_stat_inc_atomic(&s->s_stats.s_protorej, 1); + nni_stat_inc_atomic(&d->d_stats.s_reject, 1); + nni_stat_inc_atomic(&s->s_stats.s_reject, 1); nni_pipe_close(p); nni_pipe_rele(p); return; @@ -1550,15 +1544,15 @@ nni_listener_add_pipe(nni_listener *l, void *tpipe) nni_mtx_lock(&s->s_mx); if (p->p_closed) { nni_mtx_unlock(&s->s_mx); - nni_stat_inc_atomic(&l->l_stats.s_apprej, 1); - nni_stat_inc_atomic(&s->s_stats.s_apprej, 1); + nni_stat_inc_atomic(&l->l_stats.s_reject, 1); + nni_stat_inc_atomic(&s->s_stats.s_reject, 1); nni_pipe_rele(p); return; } if (p->p_proto_ops.pipe_start(p->p_proto_data) != 0) { nni_mtx_unlock(&s->s_mx); - nni_stat_inc_atomic(&l->l_stats.s_protorej, 1); - nni_stat_inc_atomic(&s->s_stats.s_protorej, 1); + nni_stat_inc_atomic(&l->l_stats.s_reject, 1); + nni_stat_inc_atomic(&s->s_stats.s_reject, 1); nni_pipe_close(p); nni_pipe_rele(p); return; diff --git a/src/core/sockimpl.h b/src/core/sockimpl.h index 5a9a2589..ffe6c6e8 100644 --- a/src/core/sockimpl.h +++ b/src/core/sockimpl.h @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -23,11 +23,14 @@ typedef struct nni_dialer_stats { nni_stat_item s_npipes; nni_stat_item s_connok; nni_stat_item s_refused; + nni_stat_item s_discon; nni_stat_item s_canceled; - nni_stat_item s_timedout; nni_stat_item s_othererr; - nni_stat_item s_protorej; - nni_stat_item s_apprej; + nni_stat_item s_etimedout; + nni_stat_item s_eproto; // protocol error + nni_stat_item s_eauth; + nni_stat_item s_enomem; + nni_stat_item s_reject; char s_scope[24]; // scope name for stats } nni_dialer_stats; @@ -64,12 +67,14 @@ typedef struct nni_listener_stats { nni_stat_item s_url; nni_stat_item s_npipes; nni_stat_item s_accept; - nni_stat_item s_aborted; // aborted remotely - nni_stat_item s_timedout; + nni_stat_item s_discon; // aborted remotely nni_stat_item s_canceled; nni_stat_item s_othererr; - nni_stat_item s_protorej; - nni_stat_item s_apprej; + nni_stat_item s_etimedout; + nni_stat_item s_eproto; // protocol error + nni_stat_item s_eauth; + nni_stat_item s_enomem; + nni_stat_item s_reject; char s_scope[24]; // scope name for stats } nni_listener_stats; @@ -97,6 +102,10 @@ typedef struct nni_pipe_stats { nni_stat_item s_id; nni_stat_item s_ep_id; nni_stat_item s_sock_id; + nni_stat_item s_rxmsgs; + nni_stat_item s_txmsgs; + nni_stat_item s_rxbytes; + nni_stat_item s_txbytes; char s_scope[16]; // scope name for stats ("pipe" is short) } nni_pipe_stats; |
