cachier icon indicating copy to clipboard operation
cachier copied to clipboard

Allow concurrent cache reads with pickle core

Open louismartin opened this issue 3 years ago • 4 comments

I have a use case where my cache is large, rarely written to, but read by many different threads at the same time thus causing timeout errors because only one thread can read the cache at the same time.

This PR allows multiple threads to read the cache using a shared lock but still preserve the thread-safety by requesting an exclusive lock on cache writes.

Therefore if multiple threads want to read the cache then they can do so simultaneously, but if only a single thread wants to write to it, then it needs to acquire an exclusive lock that prevents all other threads to read or write to the cache.

I tested locally for my use case, but would that potentially cause other issues that I didn't think of?

louismartin avatar Jul 29 '22 10:07 louismartin

@shaypal5 I didn't run the tests yet, I'm waiting for early feedback :)

louismartin avatar Jul 29 '22 10:07 louismartin

Hmm. That sounds useful, but assuming all tests pass, it should be optional.

Please figure out how to make this configurable. :) Do you want help with that? You can also take a look at current configurable options Cachier has.

shaypal5 avatar Aug 01 '22 08:08 shaypal5

@louismartin You can see tests above, right? :)

shaypal5 avatar Aug 10 '22 15:08 shaypal5

Yes I can see that they all failed x) I will try to fix this soon :)

louismartin avatar Aug 10 '22 16:08 louismartin

Any news on this front, @louismartin ?

shaypal5 avatar Oct 03 '22 19:10 shaypal5

Hi @shaypal5 ,

Sadly I haven't been able to work on this and I don't know if I will have time to do it soon. Maybe we can close and I'll reopen if I find the time?

louismartin avatar Oct 10 '22 08:10 louismartin

No need to close, on my side. It can wait as an open PR for now.

shaypal5 avatar Oct 10 '22 09:10 shaypal5

Hi @shaypal5 , I made the new feature configurable (although I enabled it by default). pickle_core tests pass on my side.

louismartin avatar Nov 28 '22 23:11 louismartin

Ok. The repository has moved under a new GitHub organization, python-cachier, where you are a contributor.

Your PRs should now be able to successfully pull the secrets required by the test workflow to connect to the mongodb.com server used for tests, and thus you should be able to progress with PRs more independently (with working tests, pinging me only when you get to the code review and later merge phase, or if you need help, of course).

I've also added a flake8 lint job and fixed all flake8 errors except those in the pickle_core.py file, since you're working on it in you current 2 PRs.

PLEASE re-base both PRs over the latest head.

Please also fix all flake8 errors in this file in at least one of your PRs.

Thanks for contributing, friend! 😀

shaypal5 avatar Dec 02 '22 11:12 shaypal5

@louismartin What do you say? Contributing this should be easier now... :)

shaypal5 avatar Dec 24 '22 17:12 shaypal5

Closed after being stale for a long time. Please open a new PR if you with to contribute this feature at some point in the future.

shaypal5 avatar Nov 28 '23 07:11 shaypal5