-
Notifications
You must be signed in to change notification settings - Fork 47
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
About get_or_create_multi feature #33
Comments
lxyu (lxyu) wrote: Add it's a little confusing to me as some codes check value version while some not:
This checks version while |
Michael Bayer (zzzeek) wrote: it might be possible, and I think as far as the lock, you'd use the async_creation_runner feature. this delivers the mutex held by Lock to the actual creator function. The expiration times and dogpile locks are per-key, so the function here would have a list of locks which it would need to close out once it has retrieved all values. |
Michael Bayer (zzzeek) wrote: get_multi() checks the expiration time using _unexpired_value_fn(). |
lxyu (lxyu) wrote: yes I know, but |
Michael Bayer (zzzeek) wrote: oh that. That's a separate issue, that's just a check in case we upgrade how dogpile.cache stores values in the cache, we'd bump "value_version" to 2. So we'd want to add the value_version check everywhere its missing now sure, but that only matters if and when we bump "value_version". that logic has no meaning right now. |
Changes by Michael Bayer (zzzeek):
|
Michael Bayer (zzzeek) wrote: try out that patch. I've only tested it in a non-concurrent case. I'd need to think pretty deeply about it in order to see if it actually maintains "dogpile" behavior, it might not, because it does the get_multi() outside of the mutex. the tricky thing here is that the mutexes have to remain per-key because you want all kinds of combinations of get(x, y, z, ...) to coordinate on keys. |
Michael Bayer (zzzeek) wrote: silly test:
|
lxyu (lxyu) wrote: Thanks, I'll test the performance tomorrow. IMHO, we use |
Michael Bayer (zzzeek) wrote: I think its a great feature, but with mutexing etc. I'm worried about deadlocks. this stuff deadlocks easily when it's not correct |
Michael Bayer (zzzeek) wrote: in fact we might need to sort the keys to prevent this. consider one call against (3, 4) and another against (4, 3). If get_multi calls go out against both simultaneously, you can deadlock on A->waiting for 4 B->waiting for 3. I need to look more closely, maybe produce a test, to see if that happens here. |
lxyu (lxyu) wrote: Just tested the code modified a litter, you can check it here: https://gist.github.com/lxyu/5712915 Changes:
And another consideration is, the creator function differs from So it becomes a little complex to add a namespace to keys, see the following code for example.
Any idea on how to refine this situation? and I'm also wondering if this feature can be written as a |
Michael Bayer (zzzeek) wrote: I've created the function decorator method, addressed the namespace issue as well as produced some real tests in b323546. The method still needed a lot of changes in order to function fully. This will now be 0.5.0. Let me know that this implementation addresses your issues and reopen if you have problems, thanks. |
Changes by Michael Bayer (zzzeek):
|
lxyu (lxyu) wrote: Yes this resolved my problems. I actually implement a decorator my own and just thinking for a pull request, then find out that your implementation is better than mine. hah! Thank you very much! |
Migrated issue, originally created by lxyu (lxyu)
I need a feature to get/create multi in one call.
Take this code for example
The
cache_on_arguments
works great for the fistget_order
function. But for the later one, if I mget[1, 2, 3]
and[1, 2]
, they'll generate 2 cached value, and if a single element in the ids expired, the whole cache expired.So I want to let the later one make use of the first function's cache. Then mget
[1, 2, 3, 4, 5]
will directly make use of cache generated in 'get', and if say[2, 3]
expired, we only need to regenerate[2, 3]
. It'll be much more fast and efficient when ids list grow larger.While I go through the source code, the
cache_on_arguments
use aLock
fromdogpile.core
with this code, which seems not very suitable to do the multiple way in my situation.So do you have any suggestions on how to accomplish this goal?
Attachments: 33.patch
The text was updated successfully, but these errors were encountered: