From d4a8d88750058aa0818f2a20cbf7b39bef88b073 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Fri, 12 May 2017 13:11:04 +0100 Subject: [PATCH 1/2] put a limit on the number of ops per iteration --- .../app/coffee/RealTimeRedisManager.coffee | 6 ++++-- .../RealTimeRedisManager/RealTimeRedisManagerTests.coffee | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/services/document-updater/app/coffee/RealTimeRedisManager.coffee b/services/document-updater/app/coffee/RealTimeRedisManager.coffee index 197a4708c1..7da7ca1f64 100644 --- a/services/document-updater/app/coffee/RealTimeRedisManager.coffee +++ b/services/document-updater/app/coffee/RealTimeRedisManager.coffee @@ -3,11 +3,13 @@ rclient = require("redis-sharelatex").createClient(Settings.redis.realtime) Keys = Settings.redis.realtime.key_schema logger = require('logger-sharelatex') +MAX_OPS_PER_ITERATION = 8 # process a limited number of ops for safety + module.exports = RealTimeRedisManager = getPendingUpdatesForDoc : (doc_id, callback)-> multi = rclient.multi() - multi.lrange Keys.pendingUpdates({doc_id}), 0 , -1 - multi.del Keys.pendingUpdates({doc_id}) + multi.lrange Keys.pendingUpdates({doc_id}), 0, (MAX_OPS_PER_ITERATION-1) + multi.ltrim Keys.pendingUpdates({doc_id}), MAX_OPS_PER_ITERATION, -1 multi.exec (error, replys) -> return callback(error) if error? jsonUpdates = replys[0] diff --git a/services/document-updater/test/unit/coffee/RealTimeRedisManager/RealTimeRedisManagerTests.coffee b/services/document-updater/test/unit/coffee/RealTimeRedisManager/RealTimeRedisManagerTests.coffee index b6aa35ac72..a04da996dc 100644 --- a/services/document-updater/test/unit/coffee/RealTimeRedisManager/RealTimeRedisManagerTests.coffee +++ b/services/document-updater/test/unit/coffee/RealTimeRedisManager/RealTimeRedisManagerTests.coffee @@ -26,7 +26,7 @@ describe "RealTimeRedisManager", -> describe "getPendingUpdatesForDoc", -> beforeEach -> @rclient.lrange = sinon.stub() - @rclient.del = sinon.stub() + @rclient.ltrim = sinon.stub() describe "successfully", -> beforeEach -> @@ -40,12 +40,12 @@ describe "RealTimeRedisManager", -> it "should get the pending updates", -> @rclient.lrange - .calledWith("PendingUpdates:#{@doc_id}", 0, -1) + .calledWith("PendingUpdates:#{@doc_id}", 0, 7) .should.equal true it "should delete the pending updates", -> - @rclient.del - .calledWith("PendingUpdates:#{@doc_id}") + @rclient.ltrim + .calledWith("PendingUpdates:#{@doc_id}", 8, -1) .should.equal true it "should call the callback with the updates", -> From be96548199b8831580a9c6630506fd301ade4ab7 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Fri, 12 May 2017 14:07:59 +0100 Subject: [PATCH 2/2] log number of updates for future debugging --- services/document-updater/app/coffee/UpdateManager.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/services/document-updater/app/coffee/UpdateManager.coffee b/services/document-updater/app/coffee/UpdateManager.coffee index 269b16ee67..12c5c7e95b 100644 --- a/services/document-updater/app/coffee/UpdateManager.coffee +++ b/services/document-updater/app/coffee/UpdateManager.coffee @@ -40,6 +40,7 @@ module.exports = UpdateManager = fetchAndApplyUpdates: (project_id, doc_id, callback = (error) ->) -> RealTimeRedisManager.getPendingUpdatesForDoc doc_id, (error, updates) => return callback(error) if error? + logger.log {project_id: project_id, doc_id: doc_id, count: updates.length}, "processing updates" if updates.length == 0 return callback() async.eachSeries updates,