diff options
| author | Garrett D'Amore <garrett@damore.org> | 2020-01-19 11:06:55 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2020-01-20 12:59:45 -0800 |
| commit | 8abf75857e8993a25e50d07bdd6d9628f028d7cc (patch) | |
| tree | 15f89948cfa97a44130db224e9e27e51a00e5f76 /src/protocol/bus0/bus.c | |
| parent | b2ba35251986d2754de5f0f274ee7cbf577223e1 (diff) | |
| download | nng-8abf75857e8993a25e50d07bdd6d9628f028d7cc.tar.gz nng-8abf75857e8993a25e50d07bdd6d9628f028d7cc.tar.bz2 nng-8abf75857e8993a25e50d07bdd6d9628f028d7cc.zip | |
fixes #1156 Message cloning could help reduce copies a lot
This introduces reference counting on messages to reduce the data copies.
This should have a marked improvement when moving large messages through
the system, or when publishing to many subscribers. For some transports,
when using large messages, the copy time can be the dominant factor.
Note that when a message is actually shared, inproc will still perform
an extra copy in order to ensure that it can modify the headers.
This will unfortunately always be the case with REQ, as the REQ protocol
keeps a copy of the original message so it can retry.
Diffstat (limited to 'src/protocol/bus0/bus.c')
| -rw-r--r-- | src/protocol/bus0/bus.c | 21 |
1 files changed, 3 insertions, 18 deletions
diff --git a/src/protocol/bus0/bus.c b/src/protocol/bus0/bus.c index dea228a1..c409292e 100644 --- a/src/protocol/bus0/bus.c +++ b/src/protocol/bus0/bus.c @@ -332,9 +332,7 @@ bus0_sock_getq_cb_raw(void *arg) { bus0_sock *s = arg; bus0_pipe *p; - bus0_pipe *lastp; nni_msg * msg; - nni_msg * dup; uint32_t sender; if (nni_aio_result(s->aio_getq) != 0) { @@ -354,26 +352,13 @@ bus0_sock_getq_cb_raw(void *arg) } nni_mtx_lock(&s->mtx); - if (((lastp = nni_list_last(&s->pipes)) != NULL) && - (nni_pipe_id(lastp->npipe) == sender)) { - // If the last pipe in the list is our sender, - // then ignore it and move to the one just previous. - lastp = nni_list_prev(&s->pipes, lastp); - } NNI_LIST_FOREACH (&s->pipes, p) { if (nni_pipe_id(p->npipe) == sender) { continue; } - if (p != lastp) { - if (nni_msg_dup(&dup, msg) != 0) { - continue; - } - } else { - dup = msg; - msg = NULL; - } - if (nni_msgq_tryput(p->sendq, dup) != 0) { - nni_msg_free(dup); + nni_msg_clone(msg); + if (nni_msgq_tryput(p->sendq, msg) != 0) { + nni_msg_free(msg); } } nni_mtx_unlock(&s->mtx); |
