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

Add TCP_NODELAY option #54

Merged
merged 2 commits into from
Jan 9, 2021
Merged

Add TCP_NODELAY option #54

merged 2 commits into from
Jan 9, 2021

Conversation

oraoto
Copy link
Contributor

@oraoto oraoto commented Sep 30, 2020

During benchmark, I found there are significant delay when the block is smaller than the buffer size (defaults to 8192 bytes).

Test program:

#include <clickhouse/client.h>
#include <cstdlib>
#include <chrono>
#include <iostream>

using namespace clickhouse;

int main(int argc, char **argv)
{
    Client client(ClientOptions().SetHost("localhost").SetPassword("qwerty"));

    client.Execute("CREATE TABLE IF NOT EXISTS test.delay (id UInt8) ENGINE = Memory");

    int count = atoi(argv[1]); // count

    for (int i = 0; i < 10; i++) {
	Block block;

	auto id = std::make_shared<ColumnUInt8>();

	for (int j = 0; j < count; j++) {
	    id->Append(65);
	}
	block.AppendColumn("id"  , id);

	auto start = std::chrono::steady_clock::now();
	client.Insert("test.delay", block);
	auto end = std::chrono::steady_clock::now();

	std::cout << std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() << " ms" << std::endl;
    }

}

When data (8171 bytes + some header) is larger than bufffer:

./test-insert-delay 8171
434 ms
567 ms
366 ms
252 ms
354 ms
265 ms
630 ms
237 ms
234 ms
181 ms

When data is smaller than bufffer, there are significant delay:

./test-insert-delay 8170
213 ms
155 ms
43767 ms
43270 ms
46539 ms
46627 ms
43114 ms
43273 ms
394 ms
42893 ms

To resolve this problem, I add an option to enable TCP_NODELAY. It's enabled by default, same as clickhouse-client.

@oraoto oraoto changed the title Nodelay Add TCP_NODELAY option Sep 30, 2020
@oraoto
Copy link
Contributor Author

oraoto commented Sep 30, 2020

Well, the time scale should be μs, which means Nagle's algorithm adds about 40 ms delay.

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

Successfully merging this pull request may close these issues.

3 participants