-
Notifications
You must be signed in to change notification settings - Fork 115
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
Optimizing operation using redis internal functions. #108
base: master
Are you sure you want to change the base?
Conversation
Hi! First off, this is awesome. I have been meaning to rewrite some of the longer Redis interactions in LUA but never got around to it. I'm super excited about this! I do have two questions… I see the temp sets getting created with Also, have you run this PR against your app? I'd be curious to see any benchmarks you might have so I can get a better feel for how much this increases performance by! Thanks again for submitting this! |
|
Nice, I'd call 10-20% a little more than slight! 😀 This looks good to me; the only thing I'm not a huge fan of is all of the |
In fact, it seems like we could get away with two sets maybe? Could be one, but i'd like them to have different names. Something like: liked_set = Recommendable::Helpers::RedisKeyMapper.liked_set_for(klass, user_id)
other_liked_set = Recommendable::Helpers::RedisKeyMapper.liked_set_for(klass, other_user_id)
disliked_set = Recommendable::Helpers::RedisKeyMapper.disliked_set_for(klass, user_id)
other_disliked_set = Recommendable::Helpers::RedisKeyMapper.disliked_set_for(klass, other_user_id)
agreements_set = Recommendable::Helpers::RedisKeyMapper.agreements_set_for(klass, user_id, other_user_id)
disagreements_set = Recommendable::Helpers::RedisKeyMapper.disagreements_set_for(klass, user_id, other_user_id)
results = Recommendable.redis.pipelined do
Recommendable.redis.sinterstore(agreements_set, liked_set, other_liked_set)
Recommendable.redis.sinterstore(agreements_set, disliked_set, other_disliked_set)
Recommendable.redis.sinterstore(disagreements_set, liked_set, other_disliked_set)
Recommendable.redis.sinterstore(disagreements_set, disliked_set, other_liked_set)
Recommendable.redis.scard(liked_set)
Recommendable.redis.scard(disliked_set)
Recommendable.redis.del(agreements_set)
Recommendable.redis.del(disagreements_set)
end If we only care about the resulting count, as long as that count still gets returned in the pipelined call, it doesn't matter if we override what's in the set itself |
I agree. That's more clear names. :) |
I found a bug from my redis-lua code about passing floating point - redis eval() returns float value as floored. ( 3.14 -> 3.0 )
I'll commit patch until sunday. |
Sounds good, looking forward to it. Thanks again for taking this on! |
last commit is 10 Improvement is
And it has some limitation because redis-lua is single thread. |
😱
so, while running a lua script, Redis wouldn't be processing any other commands from web requests? this be a problem since, typically, web requests would need to be pulling out info on ratings or recommendations. is the lua script itself fast enough that it wouldn't cause too much overhead? |
Theoritically, yes. redis-lua is fast enough.
when count=1, it's almost same with current ruby logic. Decrease count if redis response is slow, |
Really interesting PR! Is this ready to go? |
Changes Unknown when pulling af63d30 on balmbees:lua into ** on davidcelis:master**. |
I recommend optimizing operations using redis internal functions.