-
Notifications
You must be signed in to change notification settings - Fork 2
Healthcheck uses many threads #371
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
Conversation
haphut
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.
Good start! This PR aims to fix AB#57799 instead of AB#57775 but we could take out both bugs now.
I think unless we update to Java 21 to get Executors.newVirtualThreadPerTaskExecutor, Executors.newCachedThreadPool is a smart choice. However, we should use only one of them or it gets computationally expensive.
And the problematic line for AB#57775 is httpServer.setExecutor(Executors.newSingleThreadExecutor());.
Recommendations:
-
Create the
ExecutorServiceas a private member. Use it both forhttpServerand the checks.-
Shut it down in
close:public void close() { if (httpServer != null) { httpServer.stop(0); } if (healthCheckExecutor != null) { healthCheckExecutor.shutdown(); try { if (!healthCheckExecutor.awaitTermination(3, TimeUnit.SECONDS)) { healthCheckExecutor.shutdownNow(); } } catch (InterruptedException ie) { healthCheckExecutor.shutdownNow(); Thread.currentThread().interrupt(); } } }
-
-
ArrayListis not thread-safe. It is accessed fromcheckHealthand, I assume, by another thread viaaddCheck,removeCheckandclearChecks. Switch toCopyOnWriteArrayListfor checks. -
Optional: Checks could be traversed in order of completion to get to failure faster. Try
ExecutorCompletionServicefor that. -
As not all futures necessarily finish before finding failure, I would cancel the remaining futures:
for (Future<Boolean> f : futures) { if (!f.isDone()) { f.cancel(true); } }
|
Oops, pushed suggestions early. I wanted to add at least a single test. Great work regardless! |
haphut
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.
LGTM
* Fix topic prefix parsing * Update version to 2.0.3-RC * Revert "Fix topic prefix parsing" This reverts commit fd8b2fc. * Fix topic prefix parsing for passenger count * Update version to 2.0.3-RC1 * Revert "Fix topic prefix parsing for passenger count" This reverts commit 28c5c9e. * Ignore '.DS_Store' * Implement duplicate log filtering * Update version 2.0.3-RC2 * Add tests for log duplicate filtering * Fix small logics bug in log filtering * Update version 2.0.3-RC4 * Healthcheck uses many threads (#371) * AB#57775: HealthServer starts a new thread for each health checker * AB#57775: Update version to 2.0.3-RC3 * AB#57775: Add instance variable healthCheckExecutor * AB#57775: ExecutorCompletionService is used to get the failure faster * refactor: Add final for attributes * refactor: Use StandardCharsets for UTF-8 * style: Remove extra whitespace * refactor: Handle two exceptions explicitly * test: Add a start for unit tests of HealthServer * Update version to 2.0.3-RC5 --------- Co-authored-by: haphut <[email protected]> * Update version to 2.0.3-RC6 * Update version to 2.0.3 * Delete DuplicateLogFilter --------- Co-authored-by: Janne Löfhjelm <[email protected]> Co-authored-by: haphut <[email protected]>
Fixes AB#57775, Fixes AB#57799