Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

Strange behavior when reusing connection #17

Closed
hugoabonizio opened this issue Aug 16, 2016 · 10 comments
Closed

Strange behavior when reusing connection #17

hugoabonizio opened this issue Aug 16, 2016 · 10 comments

Comments

@hugoabonizio
Copy link
Collaborator

I'm getting a strange result when benchmarking BoJack Client, the performance when I reuse the same TCPSocket is much worse than opening a new one for each command. The code is here.

             user     system      total        real
shared   0.000000   0.030000   0.030000 (  7.918069)
new      0.000000   0.010000   0.010000 (  0.010263)

I noticed that @marceloboeira is making some tests on branch benchmarks, are you having the same problem?

@mauricioabreu
Copy link
Collaborator

mauricioabreu commented Aug 16, 2016

Have you tried to disable Nagle algorithm by setting tcp_nodelay to true?
https://crystal-lang.org/api/0.18.7/TCPSocket.html#tcp_nodelay%3F-instance-method

@mauricioabreu
Copy link
Collaborator

Other programming languages have this very same problem due to how Nagle works. If it works, we should think about it. Here is a nice reading about the topic: https://www.extrahop.com/community/blog/2009/to-nagle-or-not-to-nagle-that-is-the-question/

@mauricioabreu
Copy link
Collaborator

My results:

➜  bojack git:(master) ✗ crystal run --release benchmarks/socket_nagle.cr 
             user     system      total        real
shared   0.000000   0.000000   0.000000 (  0.007952)
new      0.000000   0.010000   0.010000 (  0.015957)

@marceloboeira
Copy link
Owner

@mauricioabreu / @hugoabonizio I was doing the same thing last night, but I was trying to measure how long it would take to have like 100_000 or 1_000_000 keys in the database. The thing is we have some consistency/concurrency issues on handling several requests.

I had to test this with ruby, because I wasn't able to create many parallel tcp requests with Crystal for some reason.

Take a look at the benchmarks branch.

@hugoabonizio
Copy link
Collaborator Author

Interesting! I didn't know about Nagle's algorithm yet. Disabling for both client and server the performance was much better. It seems like Redis disables this by default, should we do the same?

@mauricioabreu
Copy link
Collaborator

@hugoabonizio I don't know. I suck at TCP but it is worth a try. :)

@marceloboeira what is this "consistency/concurrency" problem exactly?

@marceloboeira
Copy link
Owner

marceloboeira commented Aug 16, 2016

@hugoabonizio gonna have a look on this, but if it increases performance and redis is doing it, probably we should!

@marceloboeira
Copy link
Owner

marceloboeira commented Aug 16, 2016

@mauricioabreu it seems that we are not correctly implementing the "secure" routine for the TCP connection/request handler.

Please read #19 for a complete answer!

@marceloboeira
Copy link
Owner

@hugoabonizio will you handle the Nagle's thing? cause I would like to try solving the concurrency problems yet it will take me a while.

@hugoabonizio
Copy link
Collaborator Author

@marceloboeira OK!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants