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

Assign io_context for each thread. #866

Merged
merged 2 commits into from
Sep 20, 2021
Merged

Assign io_context for each thread. #866

merged 2 commits into from
Sep 20, 2021

Conversation

redboltz
Copy link
Owner

The original design was calling ioc.run() from multple threads.
It worked well but scale out limit is up to about 8 threads.
The pps is 120,000 publish / second (QoS0). It was pretty nice but only
8 cores ware used.
I tested it on AWS 48 vcpu environment.
When I used 48 threads, the result was the same as 8 threads.

I suspected OS or VM limit. But when I ran the two broker processes that
listens different port, then each broker resulted 120,000 pps.
So total is 240,000 pps.
It indicates the limit is not caused by OS or VM.

Finally, I found the bottle neck. It is io_context.

So I updated as follows:

  1. Separated io_contexts.
    For timer, for accepting connections, and for MQTT communication.
    For MQTT communication, I prepared io_context as the same number of
    the threads.

  2. Added server constructor that accepts io_context_getter.

The original design was calling `ioc.run()` from multple threads.
It worked well but scale out limit is up to about 8 threads.
The pps is 120,000 publish / second (QoS0). It was pretty nice but only
8 cores ware used.
I tested it on AWS 48 vcpu environment.
When I used 48 threads, the result was the same as 8 threads.

I suspected OS or VM limit. But when I ran the two broker processes that
listens different port, then each broker resulted 120,000 pps.
So total is 240,000 pps.
It indicates the limit is not caused by OS or VM.

Finally, I found the bottle neck. It is io_context.

So I updated as follows:

1. Separated io_contexts.
   For timer, for accepting connections, and for MQTT communication.
   For MQTT communication, I prepared io_context as the same number of
   the threads.

2. Added server constructor that accepts io_context_getter.
@codecov
Copy link

codecov bot commented Sep 20, 2021

Codecov Report

Merging #866 (a55b006) into master (f144f02) will decrease coverage by 0.07%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #866      +/-   ##
==========================================
- Coverage   83.51%   83.43%   -0.08%     
==========================================
  Files          62       62              
  Lines        9524     9685     +161     
==========================================
+ Hits         7954     8081     +127     
- Misses       1570     1604      +34     

@redboltz redboltz merged commit 6c25c7a into master Sep 20, 2021
@redboltz redboltz deleted the poc_ioc_per_th branch September 20, 2021 02:56
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.

1 participant