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

Performance optimization: SendAsync: call TrySend within Task #49

Merged
merged 1 commit into from
Mar 17, 2020

Conversation

darxis
Copy link
Contributor

@darxis darxis commented Mar 17, 2020

Related issue #48

Calling TrySend asynchronously (within new Task) to match the behavior of CppServer.

Benchmark results before:

TcpMulticastClient -c 100 -p 53698
Total time: 10.095 s
Total data: 27.1016 MiB
Total messages: 917256
Data throughput: 2.791 MiB/s
Message latency: 11.006 mcs
Message throughput: 90857 msg/s

Benchmark results after:

TcpMulticastClient -c 100 -p 53698
Total time: 10.202 s
Total data: 295.201 MiB
Total messages: 9673002
Data throughput: 28.954 MiB/s
Message latency: 1.054 mcs
Message throughput: 948056 msg/s

Before applying this fix, the _sendBufferFlush data size that was sent using SendAsync in the benchmark was constant size = 32 very low comparing to CppServer, where I had 6 digit sizes:

std::cout << "SEND SIZE: " << _send_buffer_flush.size() - _send_buffer_flush_offset << std::endl;
if (_strand_required)
    _socket.async_write_some(asio::buffer(_send_buffer_flush.data() + _send_buffer_flush_offset, _send_buffer_flush.size() - _send_buffer_flush_offset), bind_executor(_strand, async_write_handler));
else
    _socket.async_write_some(asio::buffer(_send_buffer_flush.data() + _send_buffer_flush_offset, _send_buffer_flush.size() - _send_buffer_flush_offset), async_write_handler);
SEND SIZE: 275232
SEND SIZE: 538112
SEND SIZE: 581248
SEND SIZE: 433248
SEND SIZE: 193696
SEND SIZE: 564864
SEND SIZE: 557216
SEND SIZE: 570080
SEND SIZE: 217312
SEND SIZE: 396128
SEND SIZE: 591968

That caused that the NetCoreServer sent single TCP packets with 32 bytes of data each, but the CppServer sent packets with much bigger sizes (max TCP packet sizes). It seems that without this fix, sending buffered data (multiple messages in _sendBufferFlush) was not properly working when calling SendAsync in a loop in single-thread

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.

2 participants