Skip to content

Commit

Permalink
feat: slowlog injection accepts argument for time
Browse files Browse the repository at this point in the history
  • Loading branch information
jim80net committed Apr 27, 2020
1 parent a2d7b55 commit 95baab4
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions inject_slow_query.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env ruby
# WARNING: This will lock up CPU on the target Redis instance. Never run against production.
#
# Copyright 2020 Scribd, Inc.

require 'logger'
Expand All @@ -12,20 +14,26 @@
ssl: :true
)

SCRIPT =<<END
if ARGV[0].nil?
raise "Specify milliseconds to inject as the first positional argument to `#{__FILE__}`"
else
milliseconds = ARGV[0].to_i
end

SCRIPT =<<HEREDOC
-- From https://medium.com/@stockholmux/simulating-a-slow-command-with-node-redis-and-lua-efadbf913cd9
local aTempKey = "a-temp-key"
local cycles
redis.call("SET",aTempKey,"1")
redis.call("PEXPIRE",aTempKey, 100)
for i = 0, 1500000, 1 do
redis.call("PEXPIRE",aTempKey, #{milliseconds})
for i = 0, #{15000 * milliseconds}, 1 do
local apttl = redis.call("PTTL",aTempKey)
cycles = i;
if apttl == 0 then
break;
end
end
return cycles
END
HEREDOC

LOGGER.info REDIS.eval(SCRIPT)

0 comments on commit 95baab4

Please sign in to comment.