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

Allow limiting the number of threads spawned for housekeeping and invalidation. #146

Closed
metasim opened this issue Jun 7, 2022 · 2 comments
Labels
enhancement New feature or request
Milestone

Comments

@metasim
Copy link

metasim commented Jun 7, 2022

Not sure how to express this (through the builder)? But for small resource use cases it would nice to limit the number of threads used.

@tatsuya6502 tatsuya6502 added the enhancement New feature or request label Jun 9, 2022
@tatsuya6502
Copy link
Member

tatsuya6502 commented Jun 9, 2022

Thanks for raising the request. Exposing these configurations should be easy, so I will just do it.

These thread pools are shared across all cache instances, so these limits will be cache-global configurations. Also, the thread pool library we use now does not support growing and shrinking the number of worker threads. So for now, they will be fixed numbers of worker threads, instead of limits (the maximum numbers of worker threads).

One limitation is that you cannot change those numbers while cache instances exist. So you will set them before creating any cache.

Just to clarify, this is how they work now (as of Moka v0.8.5):
(I will put them to somewhere in the doc)

  • There are two global thread pools:
    1. Housekeeping
      • Used by all concurrent caches (sync, future, experimental dash caches).
      • Used for:
        • Updating internal cache data structures such as LRU queue and LFU filter.
        • Removing expired entries.
        • etc.
    2. Invalidation
      • Used by sync and future caches with invalidation_closures configuration explicitly enabled.
      • Used for executing user-provided invalidation closures on cache entries.
  • A pool will be shared across all cache instance:
    • There should be zero or one housekeeping pool, and zero or one invalidation pool, no matter how many cache instances have been created.
  • A pool will be created when a cache using it is created.
    • I think many users do not set invalidation closures, so only the housekeeping thread pool will be created in many cases.
  • A pool will be dropped when all cache using it have been dropped.
  • A pool has a fixed number of worker threads:
    • The number is the same to available logical cores of the processor(s) of the machine.
    • I will make the number configurable.

@tatsuya6502
Copy link
Member

Closing as complete.

v0.12.0 has major breaking changes. Please read the MIGRATION-GUIDE.md for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants