-
Notifications
You must be signed in to change notification settings - Fork 2k
shdict_get flag comparison #1921
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
Comments
Hi @Miniwoffer |
Sure, i had som trouble getting consistent results betwene runs, but managed to get some more or less reliable data.
|
Any progress? |
@Miniwoffer, please rebase to the master and change the lua-resty-core in .travis.yml to your branch. |
we need to update the api in doc/HttpLuaModule.wiki. |
@zhuizhuhaomeng Done, travis is green on lua-nginx-module but not lua-resty-core. But master is also red, so i am unsure if its me. |
Okay so there are some tests in lua-resty-core that uses get and get_stale with two arguments. Dont know why those tests specify a secound argument, so would need some guidance on how to alter those tests. Tests in question are t/stdict.t(Test 24 and 25) Also want me to write tests for lua-rest-core even though the tests in lua-nginx-module should cover everything? |
Fixed so Test 24 and 25 in t/shdict.t pass, just changed so key == nil is check first. |
lua-resty-core still failed. |
@zhuizhuhaomeng Yeah sorry about that, thought stream was generated from http so didn't implement anything in stream. I ported tho code and the tests over to the stream module. |
@zhuizhuhaomeng Think you might have missed the openresty/stream-lua-nginx-module#265 pull request. Also am i the one who should revert the Il add a summary of pull requests here and in the original post Pull requests
|
@Miniwoffer No, you don't need a revert .travis.yml. |
I think it's better to introduce a new Lua method instead of piggybacking the existing |
Do you have a suggestion, @agentzh? get_conditional(key, flags) ? perhaps (key, flags, comparator) with comparator defaulting to "~=" or get_if(key, flags, comparator) |
@bjne I've found the semantics a bit confusing. I don't see equivalents in redis or memcached's API. So that's probably a bad sign. What exactly is your use case here? You're using flags as some kind of version number here? We'd better set the semantics straight first? |
@agentzh We are doing multilevel caching, db -> shm -> lru, but due to lack of (or complexity/performance) of IPC between workers, we are using the lru and shm uint32 flags to store a version of the object (actually just time of shm-insert in ms % 2^32 with a ttl of half that), but it could be any versioning ofcorse. To keep updates to config available fast, we now get flags and value from shm, and then compare with lru flags and if they are same no need to deserialize. This is where this idea was born, what performance can be gained from not getting the value at all from shm if we do not need it. And as shown above, quite significant numbers. The closest thing found in redis I guess is for the CAS (compare-and-swap), dont know if COG (compare-or-get) exists in that context, but that is what we want. Also redis/memcache does not have flags afaik, so this type of op would not make sense there. At the moment I only see the use for the 'NE' comparator, so I am fine with implementing without a comparator input or eventually with 'NE' as the default. |
@agentzh ping |
Maybe we can add a |
BTW, we also provide lua-resty-jsonb library which does not need any serialization or de-serialization overhead when storing JSON data in shm. But it's not open source. You can contact [email protected] if you're interested. |
@bjne BTW, memcached does support flags. that's actually where our flags come from. |
@agentzh Yeah, we can also implement a cas() method, but perhaps in a separate pull request. |
Ping @agentzh |
So where do we go from here, @agentzh. This is in many cases quite a performance gain, so I hope we can get it merged. |
New propossal #1954 |
Proposal
Add optional flags argument to
shmdict_get(_stale)?
that only returns value if flags do not match.And a 3rd (4th for _stale) return value to indicate if it is a flag match.
Example usage
Why?
Allocating and collecting the memory nedded to return a value can be
very expensive when value is not needed.
Bencmarking
Link to benchmark repo
Read only benchmarking, with random access order.
Tested with 5 000 000 shm lookups on a single worker.
Pull requests
The text was updated successfully, but these errors were encountered: