expiringmap icon indicating copy to clipboard operation
expiringmap copied to clipboard

Thread Pool configuration

Open siva38 opened this issue 9 years ago • 10 comments

Can the thread pool configuration be exposed for Expirer and Listener thread pools?

If a single threaded expirer may not be sufficient and an unbounded thread pool an over kill for certain cases, can the caller be asked to optionally supply thread pool executor instance?

siva38 avatar Sep 09 '16 10:09 siva38

Sure this could be configurable. I'm curious if you've actually hit a situation where the expiration thread, in particular, is unable to keep up with expirations. Has that happened? Any details?

jhalterman avatar Sep 09 '16 16:09 jhalterman

I am planning to use this in an application where the TPS no's would be huge. I feel the single threaded expirer thread fits the scenario, but i saw a new thread created for clearing expired entries.

I tried to add 50 k entries with expiration of 3000 ms. After 5000 ms, i saw close to 23k entries cleared of cache.So i thought having an option to configure more threads for expiration would speed up the clean up process.

Also a bit hesitant to use the unbounded thread pool for listener. If these could be configured via builder it would be great

siva38 avatar Sep 09 '16 16:09 siva38

Thanks for the use case. I don't think it will be quite as straightforward as throwing more threads at it since there will be some lock contention when attempting to remove entries from the internal map.

jhalterman avatar Sep 09 '16 16:09 jhalterman

Thanks. Can the listener thread be made configurable to prevent unbounded thread creation

siva38 avatar Sep 12 '16 12:09 siva38

Another option is we could use a fixed thread pool instead of cached. That opens up the potential for new problems... but what do you think?

jhalterman avatar Sep 12 '16 17:09 jhalterman

Here is a related use case: under very restricted resources, I might want to use inline expiration (on access/iteration) instead of having a thread work the expiration.

CodingFabian avatar Jan 25 '17 21:01 CodingFabian

and another "problem" if you use the ExpiringMap in an environment where the class could get unloaded, there is no "API-way" to stop the expirer and listenerService. thus leaking those services and threads

CodingFabian avatar Feb 04 '17 14:02 CodingFabian

Yes, it generates:

org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [test] appears to have started a thread named [ExpiringMap-Expirer] but has failed to stop it. This is very likely to create a memory leak.

Being able to call EXPIRER.awaitTermination(…) would be nice.

lapo-luchini avatar Nov 15 '17 09:11 lapo-luchini

I created PR #62 for that last part.

lapo-luchini avatar Apr 03 '19 12:04 lapo-luchini

Interesting alternative... I left some comments on the PR. Interested to get feedback.

jhalterman avatar Apr 26 '19 04:04 jhalterman