Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node: unix sockets are slow in case of lots of small buffers #5095

Closed
BridgeAR opened this issue Feb 5, 2016 · 6 comments
Closed

node: unix sockets are slow in case of lots of small buffers #5095

BridgeAR opened this issue Feb 5, 2016 · 6 comments
Assignees
Labels
net Issues and PRs related to the net subsystem.

Comments

@BridgeAR
Copy link
Member

BridgeAR commented Feb 5, 2016

While running the node_redis benchmarks with unix sockets I see a huge performance decrease opposed to TCP while pipelining lots of small buffers (4byte || 4kb) to the stream. The performance will drop to 50% of TCP while benchmarking the small buffers and increase by about 50% by using 4mb buffers opposed to TCP.
Writing strings to the stream stays about the same or increases the performance a tiny bit.

I tried to work out where the difference came from but this is handled in C and I have no clue about C.

As a side note: node_redis mixes buffers and strings while writing buffers to the stream. Strictly only using buffers does not change the outcome though.

clients: 1, NodeJS: 5.5.0, Redis: 3.0.5, parser: hiredis, connected by: socket
   SET 4B str,         1/1 min/max/avg:   0.01/  2.77/  0.02   2501ms total,   54347 ops/sec
   SET 4B str,  batch 50/1 min/max/avg:   0.09/  3.41/  0.11   2501ms total,  430688 ops/sec
   SET 4B buf,         1/1 min/max/avg:   0.02/  3.11/  0.03   2501ms total,   37721 ops/sec
   SET 4B buf,  batch 50/1 min/max/avg:   0.49/  4.43/  0.59   2501ms total,   83826 ops/sec
 SET 4KiB str,         1/1 min/max/avg:   0.02/  3.52/  0.02   2501ms total,   39837 ops/sec
 SET 4KiB str,  batch 50/1 min/max/avg:   0.25/  1.96/  0.29   2501ms total,  172891 ops/sec
 SET 4KiB buf,         1/1 min/max/avg:   0.02/  2.79/  0.03   2501ms total,   35443 ops/sec
 SET 4KiB buf,  batch 50/1 min/max/avg:   0.53/  6.28/  0.67   2501ms total,   73870 ops/sec
 SET 4MiB str,         1/1 min/max/avg:   3.54/ 20.85/  4.41   2501ms total,     226 ops/sec
 SET 4MiB str,  batch 20/1 min/max/avg:  67.20/ 89.91/ 75.32   2561ms total,     266 ops/sec
 SET 4MiB buf,         1/1 min/max/avg:   1.25/  4.78/  1.37   2501ms total,     724 ops/sec
 SET 4MiB buf,  batch 20/1 min/max/avg:  24.51/ 36.13/ 26.51   2520ms total,     754 ops/sec
clients: 1, NodeJS: 5.5.0, Redis: 3.0.5, parser: hiredis, connected by: tcp
   SET 4B str,         1/1 min/max/avg:   0.02/  5.21/  0.03   2501ms total,   34392 ops/sec
   SET 4B str,  batch 50/1 min/max/avg:   0.10/  3.37/  0.11   2501ms total,  439584 ops/sec
   SET 4B buf,         1/1 min/max/avg:   0.04/  3.61/  0.05   2501ms total,   19350 ops/sec
   SET 4B buf,  batch 50/1 min/max/avg:   0.25/  6.18/  0.29   2501ms total,  170292 ops/sec
 SET 4KiB str,         1/1 min/max/avg:   0.03/  5.49/  0.03   2501ms total,   29333 ops/sec
 SET 4KiB str,  batch 50/1 min/max/avg:   0.27/  6.38/  0.32   2501ms total,  152879 ops/sec
 SET 4KiB buf,         1/1 min/max/avg:   0.04/  3.63/  0.06   2501ms total,   17617 ops/sec
 SET 4KiB buf,  batch 50/1 min/max/avg:   0.31/  3.92/  0.36   2501ms total,  136026 ops/sec
 SET 4MiB str,         1/1 min/max/avg:   4.01/ 20.96/  5.29   2501ms total,     189 ops/sec
 SET 4MiB str,  batch 20/1 min/max/avg:  78.62/117.93/ 87.70   2544ms total,     228 ops/sec
 SET 4MiB buf,         1/1 min/max/avg:   1.82/ 10.09/  2.28   2502ms total,     436 ops/sec
 SET 4MiB buf,  batch 20/1 min/max/avg:  38.21/ 51.92/ 41.36   2523ms total,     484 ops/sec

Ping @trevnorris

@mscdex mscdex added the net Issues and PRs related to the net subsystem. label Feb 5, 2016
@mscdex
Copy link
Contributor

mscdex commented Feb 5, 2016

What if you explicitly use .cork()/.uncork() in node_redis to batch writes?

@BridgeAR
Copy link
Member Author

BridgeAR commented Feb 5, 2016

@mscdex this is already in use but it does not change anything by removing it.

@GeorgeBailey
Copy link

Thanks for bringing this up. I had a similar experience in Node 0.10.36 about 11 months ago, but opted to use STDIO for my project.

@mcollina
Copy link
Member

The way currently cork it's being currently done in node_redis is not the most efficient (as it is right now). Basically it calls cork/uncork multiple times during the same synchronous flow, effectively crossing the C++ barrier multiple times. @BridgeAR have you tried calling uncork in nextTick and see if there is any difference? That will likely batch up all your writes as they were a single one.

@BridgeAR
Copy link
Member Author

Using nextTick does not change the performance in my tests. It stays in the tolerance range after each test run. There might be a increase that I can't measure well because of the noise but it won't be significant.

@mcollina
Copy link
Member

Run the same thing with http://npm.im/0x, and upload the results somewhere, so we can have a look.

It might even be OS specific (maybe some tuning in the kernel). Be careful of not running it on OS X, I had some surprises when running stuff on Linux for production.

aqrln added a commit to aqrln/node that referenced this issue Jan 11, 2017
This commit enables writev for Unix Domain Sockets on supported
platforms thus enabling cork/uncork functionality for them and
improving IPC performance.

Fixes: nodejs#5095
@jasnell jasnell closed this as completed Jan 12, 2017
jasnell pushed a commit that referenced this issue Jan 12, 2017
This commit enables writev for Unix Domain Sockets on supported
platforms thus enabling cork/uncork functionality for them and
improving IPC performance.

Fixes: #5095
PR-URL: #10677
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Fedor Indutny <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: James M Snell <[email protected]>
italoacasas pushed a commit to italoacasas/node that referenced this issue Jan 18, 2017
This commit enables writev for Unix Domain Sockets on supported
platforms thus enabling cork/uncork functionality for them and
improving IPC performance.

Fixes: nodejs#5095
PR-URL: nodejs#10677
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Fedor Indutny <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: James M Snell <[email protected]>
italoacasas pushed a commit to italoacasas/node that referenced this issue Jan 23, 2017
This commit enables writev for Unix Domain Sockets on supported
platforms thus enabling cork/uncork functionality for them and
improving IPC performance.

Fixes: nodejs#5095
PR-URL: nodejs#10677
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Fedor Indutny <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: James M Snell <[email protected]>
italoacasas pushed a commit to italoacasas/node that referenced this issue Jan 25, 2017
This commit enables writev for Unix Domain Sockets on supported
platforms thus enabling cork/uncork functionality for them and
improving IPC performance.

Fixes: nodejs#5095
PR-URL: nodejs#10677
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Fedor Indutny <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: James M Snell <[email protected]>
italoacasas pushed a commit to italoacasas/node that referenced this issue Jan 27, 2017
This commit enables writev for Unix Domain Sockets on supported
platforms thus enabling cork/uncork functionality for them and
improving IPC performance.

Fixes: nodejs#5095
PR-URL: nodejs#10677
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Fedor Indutny <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this issue Mar 8, 2017
This commit enables writev for Unix Domain Sockets on supported
platforms thus enabling cork/uncork functionality for them and
improving IPC performance.

Fixes: #5095
PR-URL: #10677
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Fedor Indutny <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this issue Mar 8, 2017
This commit enables writev for Unix Domain Sockets on supported
platforms thus enabling cork/uncork functionality for them and
improving IPC performance.

Fixes: #5095
PR-URL: #10677
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Fedor Indutny <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this issue Mar 9, 2017
This commit enables writev for Unix Domain Sockets on supported
platforms thus enabling cork/uncork functionality for them and
improving IPC performance.

Fixes: #5095
PR-URL: #10677
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Fedor Indutny <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this issue Mar 9, 2017
This commit enables writev for Unix Domain Sockets on supported
platforms thus enabling cork/uncork functionality for them and
improving IPC performance.

Fixes: #5095
PR-URL: #10677
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Fedor Indutny <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
net Issues and PRs related to the net subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants