-
Notifications
You must be signed in to change notification settings - Fork 73
Use threadpool for subscription checking #465
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
Use threadpool for subscription checking #465
Conversation
- Add new thread pool for SubscriptionHandler - Setup pool for SubscriptionHandler in SpringAsyncConfig - Update test and info to use new properties - Add new application properties - Set org.mongodb.driver.protocol.command log out to error - Remove use of "local.server.port" from debug printout
- Fix of docker-compose correct path to rules - Add config for subscription handler execution pool in tests
tobiasake
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good,, I really like the prefix names in thread properties names, so the user that configures the EI instance knows what the thread configuration do.
But change so we follow the Spring properties naming standards, regarding capital letters etc.
default values for new properties
On master we went for dot notation style in the properties instead of camelCase. So I guess the new properties should follow the same style then. Is "subscription.handler.core.pool.size" better? |
Add javadoc on some public methods Simplified complex methods
src/main/java/com/ericsson/ei/subscription/SubscriptionHandler.java
Outdated
Show resolved
Hide resolved
before creating a new client - Added condition in MongoHandler to check if there are any mongoclients if not create a new client.
- Add new thread pool for SubscriptionHandler - Setup pool for SubscriptionHandler in SpringAsyncConfig - Update test and info to use new properties - Add new application properties - Set org.mongodb.driver.protocol.command log out to error - Remove use of "local.server.port" from debug printout
- Fix of docker-compose correct path to rules - Add config for subscription handler execution pool in tests
default values for new properties
before creating a new client - Added condition in MongoHandler to check if there are any mongoclients if not create a new client.
| "threads.corePoolSize= 3", | ||
| "threads.queueCapacity= 1", | ||
| "threads.maxPoolSize= 4", | ||
| "subscription-handler.threads.corePoolSize= 3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this not be a bottleneck if EventHandler thread works faster than the SubscriptionHandler,, we will queue up more and more threads. So Subscriptionhandler threadpool should be much bigger than Eventhandler threadpool.
This could be a good load test scenario, that tests number SubscritionHandler threads needed for different EventHandler threadpool sizes.
What happens if threads.queueCapacity is reached, is those new threads never created and Aggregations never Subscription checked and no triggering is happening ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I'm not sure if it will be a bottleneck (or if it's a big risk) . The problem we saw before was that an infinite amount of threads were created from SubscriptionHandler and because it reads from the database, it blocked all other processing of events (all EventHandler threads were blocked). Now at least we have a limit on the amount of threads allowed for subscription handler. It's a trade off, which one do we want to prioritize: processing events from rabbitmq or trigger subscriptions as fast as possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to do a "baton pass" so that you wait to process until a thread is available? But then I guess both operations they might as well be in the same thread process...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I explained the situation in a chat.
Short summary of the situation I am trying to explain:
If EventHandler thread (event consumer) executes much faster than SubscriptionHandler that executes much slower due to MongoDb connection,queries, updates and read read of big JSON objects, then a lot of threads will be queuing up in SubscriptionHandler thread pool.
And what happens when that queue is full.
If RabbitMq queue has 100 000 events, than we almost must have 100 000 in queue capacity in SubscriptionHandler treadpool queue, to be on safe side so we don't loose any aggregation subscription checks that is made by SubscriptionHandler thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If eventHandler threads blocks until a new thread slot is free in SubscriptionHandler thread queue before creating the thread in queue, then it will not be a problem, I think.
Someone can maybe check that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand your point @tobiasake but it's hard to test such a scenario. For now I have the same amount of threads in both pools. And don't forget that the event handler also does read/write to mongodb to merge and update aggregations so I don't think it executes so much faster than subscription handler threads do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it would use bigger event linked chains that causes bigger Aggregations and casuign longer/bigger opeations agains MongoDb
It also possible to mock som functions in code and add sleeps in subscriptionHandler threads,, so it takes longer time to process subscriptionhandler threads.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am mean, why implement something to fix a issue without testing that specific situation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sounds complex, doesn't the thread pool have some sort of queue? This queue would keep growing though if the SubscriptionHandler is slower and more and more events are coming in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of what I can understand on the info about ThreadPool,, queue throws exeception if queue is full. So Aggregation and matching subscription will not happen for those aggreagation that happens when subscriptionQueueHandler Queue is full. So alot of Subscripion triggering will never happen if its alot of events in MessageBus queue and EI consumes more event than number of SubscritpionHandler threads can handle due to the ThreadPool limitations.
Christoffer-Cortes
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, can't find any obvious errors and tests are passing.
Applicable Issues
Previously new threads were created every time we compared an aggregation towards all the existing subscriptions. Since there was no limit to the amount of thread this caused a huge load on Eiffel Intelligence and it was unable to consume events fast enough.
Description of the Change
Alternate Designs
Benefits
By using a thread pool it is possible to configure the amount of threads if it's needed.
Possible Drawbacks
Sign-off
Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or
(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or
(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.
Signed-off-by: @m-linner-ericsson, @e-pettersson-ericsson @SantoshNC68