mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 14:43:46 +01:00
Add timers to time how long each redis request takes
This commit is contained in:
@@ -60,7 +60,9 @@ class MultiClient
|
|||||||
exec: (callback) ->
|
exec: (callback) ->
|
||||||
jobs = @clients.map (client) ->
|
jobs = @clients.map (client) ->
|
||||||
(cb) ->
|
(cb) ->
|
||||||
|
timer = new Metrics.Timer("redis.#{client.driver}.exec")
|
||||||
client.rclient.exec (error, result) ->
|
client.rclient.exec (error, result) ->
|
||||||
|
timer.done()
|
||||||
if client.driver == "ioredis"
|
if client.driver == "ioredis"
|
||||||
# ioredis returns an results like:
|
# ioredis returns an results like:
|
||||||
# [ [null, 42], [null, "foo"] ]
|
# [ [null, 42], [null, "foo"] ]
|
||||||
@@ -112,7 +114,9 @@ for command, key_pos of COMMANDS
|
|||||||
key = key_builder(client.key_schema)
|
key = key_builder(client.key_schema)
|
||||||
args_with_key = args.slice(0)
|
args_with_key = args.slice(0)
|
||||||
args_with_key[key_pos] = key
|
args_with_key[key_pos] = key
|
||||||
|
timer = new Metrics.Timer("redis.#{client.driver}.#{command}")
|
||||||
client.rclient[command] args_with_key..., (error, result...) ->
|
client.rclient[command] args_with_key..., (error, result...) ->
|
||||||
|
timer.done()
|
||||||
if client.primary
|
if client.primary
|
||||||
# Return this result as the actual result
|
# Return this result as the actual result
|
||||||
callback(error, result...)
|
callback(error, result...)
|
||||||
@@ -158,7 +162,7 @@ module.exports =
|
|||||||
if config[key]?
|
if config[key]?
|
||||||
redis_config[key] = config[key]
|
redis_config[key] = config[key]
|
||||||
rclient = require("redis-sharelatex").createClient(redis_config)
|
rclient = require("redis-sharelatex").createClient(redis_config)
|
||||||
driver = "redis"
|
driver = "noderedis"
|
||||||
return {
|
return {
|
||||||
rclient: rclient
|
rclient: rclient
|
||||||
key_schema: config.key_schema
|
key_schema: config.key_schema
|
||||||
|
|||||||
@@ -45,6 +45,11 @@ describe "RedisBackend", ->
|
|||||||
|
|
||||||
nodes: sinon.stub()
|
nodes: sinon.stub()
|
||||||
|
|
||||||
|
@timer = timer = sinon.stub()
|
||||||
|
class Timer
|
||||||
|
constructor: (args...) -> timer(args...)
|
||||||
|
done: () ->
|
||||||
|
|
||||||
@RedisBackend = SandboxedModule.require modulePath, requires:
|
@RedisBackend = SandboxedModule.require modulePath, requires:
|
||||||
"settings-sharelatex": @Settings
|
"settings-sharelatex": @Settings
|
||||||
"logger-sharelatex": @logger = { error: sinon.stub(), log: sinon.stub(), warn: sinon.stub() }
|
"logger-sharelatex": @logger = { error: sinon.stub(), log: sinon.stub(), warn: sinon.stub() }
|
||||||
@@ -54,7 +59,10 @@ describe "RedisBackend", ->
|
|||||||
"ioredis": @ioredis =
|
"ioredis": @ioredis =
|
||||||
Cluster: Cluster
|
Cluster: Cluster
|
||||||
"metrics-sharelatex":
|
"metrics-sharelatex":
|
||||||
@Metrics = inc: sinon.stub()
|
@Metrics =
|
||||||
|
inc: sinon.stub()
|
||||||
|
Timer: Timer
|
||||||
|
|
||||||
@client = @RedisBackend.createClient()
|
@client = @RedisBackend.createClient()
|
||||||
|
|
||||||
@doc_id = "mock-doc-id"
|
@doc_id = "mock-doc-id"
|
||||||
@@ -104,6 +112,14 @@ describe "RedisBackend", ->
|
|||||||
.calledWith("backend-match")
|
.calledWith("backend-match")
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
|
it "should time the commands", ->
|
||||||
|
@timer
|
||||||
|
.calledWith("redis.ioredis.get")
|
||||||
|
.should.equal true
|
||||||
|
@timer
|
||||||
|
.calledWith("redis.noderedis.get")
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
describe "with different results", ->
|
describe "with different results", ->
|
||||||
beforeEach (done) ->
|
beforeEach (done) ->
|
||||||
@rclient_redis.get = sinon.stub()
|
@rclient_redis.get = sinon.stub()
|
||||||
@@ -241,6 +257,14 @@ describe "RedisBackend", ->
|
|||||||
.calledWith("backend-match")
|
.calledWith("backend-match")
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
|
it "should time the exec", ->
|
||||||
|
@timer
|
||||||
|
.calledWith("redis.ioredis.exec")
|
||||||
|
.should.equal true
|
||||||
|
@timer
|
||||||
|
.calledWith("redis.noderedis.exec")
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
describe "with different results", ->
|
describe "with different results", ->
|
||||||
beforeEach (done) ->
|
beforeEach (done) ->
|
||||||
@rclient_redis.get = sinon.stub()
|
@rclient_redis.get = sinon.stub()
|
||||||
|
|||||||
Reference in New Issue
Block a user