I have a cluster application that uses a Redis distributed server with dynamically generated Lua scripts sent to redis instances. Lua component scripts can be quite complex and have significant runtimes, and I would like to be able to profile them to find hot spots.
SLOWLOG is useful for telling me that my scripts are slow and how slow they are, but that is not my problem. I know how slow they are, I would like to find out which parts of them are slow.
Docs redis EVAL it is clear that redis does not export any timing functions to lua, which makes it look like it could be a lost cause.
So, Redis short custom fork , is there any way to tell which parts of my Lua script are slower than others?
EDIT I accepted Doug's suggestion and used debug.sethook - here is the manual procedure that I inserted at the top of my script:
redis.call('del', 'line_sample_count') local function profile() local line = debug.getinfo(2)['currentline'] redis.call('zincrby', 'line_sample_count', 1, line) end debug.sethook(profile, '', 100)
Then, to see the hottest 10 lines of my script:
ZREVRANGE line_sample_count 0 9 WITHSCORES
Drew shafer
source share