-
-
Notifications
You must be signed in to change notification settings - Fork 8
Multi Get and Multi Set #4
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
base: v2
Are you sure you want to change the base?
Conversation
Is there any reason in particular you used two slices in MultiGet() rather than a slice with a struct? It seems to me that's quite a bit more convenient, and this can also work for setting multiple keys:
|
i personaly found the resuling code, that uses the function more readable. But this is personal preference. I can rework this with structs if you like |
It seems to me that juggling around two variables for one thing is rather awkward. Then again I also don't think my version is super-great either (it was just the quickest to write – I mostly wanted to compare performance to see if it's worth it after our Twitter chat). Since I really want to avoid introducing incompatible changes in the future I'd like to get this right – I need to play around and think a bit to see what works, so let me get back to you. |
Also: there's quite a few other operations where it makes sense to operate on more than one key. Why do Get() and Set() have "Multi versions" but not Add() or Delete() or Touch() or GetWithExpire() or any of the others? Adding Multi-variants for each one would be a bit much, but I'm wonder if there's nice way to make a more generic API that extends to more operations – for example maybe something like (and just thinking out loud here):
Implementation is more work, but I don't mind doing the work on that. Getting the API right is what I'm most concerned with. |
That might be a good idea. I tested 2 return types: ([]V, []bool), []struct{v V, exists bool} in benchmarks. I modified your benchmark. The return the get-method is iterated over and if a value doesn't exists time.Sleep(time.Nanosecond) is used to simulate loading the value and the value is set to "".
As you can see, my idea with 2 slices completely ruins the performance, therefore the struct version should be the right return type. |
Hm, I get quite different benchmark results?
I put the benchmark in https://github.com/arp242/zcache/tree/mget My benchmark is a lot simpler though. |
Your Benchmark only tests the method and misses the access of the method retrieved. |
I will further test tomorrow |
It's fine, don't bother – it's not hugely important. |
A "keyset" is a set of keys for a cache, similar to how a slice is a "view" on an array. This allows reasonably convenient and efficient operations on multiple keys. Doing it with a different type like this gives us the advantage that we can reasonably easily add a "multi" version for all methods. Fixes #4
This seems to work reasonably well: #5 – what do you think? Keyset.Set() is up to ~60% faster, and Keyset.Get() up to ~40%. Need to finish with some extra tests and documentation, and maybe also some extra methods. Also not entirely sure about the "Keyset" name; but I couldn't think of anything better. |
i will look at it this weekend |
No description provided.