Optimizing overall performance under heavy load by temporarily rejecting new sessions that will likely not finish successfully anyway.

This commit is contained in:
Zaid Abdulla committed 2013-08-08 11:24:14 +03:00
1 parent eae6e8b079
commit 4c4b1d630b
1 file changed
+19 -1
+19 -1
View File
@@ -16,6 +16,10 @@ OBJECT_REGEX = /\.$/
INSTANCE_REGEX = /\.[\d]+\.$/
# Used to reject new TR-069 sessions when under load
holdUntil = Date.now()
applyConfigurations = (currentRequest, taskList) ->
if taskList.length
util.log("#{currentRequest.deviceId}: Presets discrepancy found")
@@ -129,9 +133,16 @@ updateDevice = (currentRequest, actions, callback) ->
runTask = (currentRequest, task, methodResponse) ->
timeDiff = process.hrtime()
tasks.task(task, methodResponse, (err, status, cwmpResponse, deviceUpdates) ->
# TODO handle error
updateDevice(currentRequest, deviceUpdates)
updateDevice(currentRequest, deviceUpdates, (err) ->
util.error(err) if err?
timeDiff = process.hrtime(timeDiff)[0] + 1
if timeDiff > 3 # in seconds
# Server under load. Hold new sessions temporarily.
holdUntil = Math.max(Date.now() + timeDiff * 2000, holdUntil)
switch status
when tasks.STATUS_FINISHED
@@ -160,6 +171,7 @@ runTask = (currentRequest, task, methodResponse) ->
else
throw Error('Unknown task status')
)
)
isTaskExpired = (task) ->
@@ -263,6 +275,12 @@ listener = (httpRequest, httpResponse) ->
if cwmpRequest.methodRequest?
if cwmpRequest.methodRequest.type is 'Inform'
if Date.now() < holdUntil
# Ask CPE to retry in 5 mins
res = {code : 503, headers : {'Content-Length' : 0, 'Retry-After' : 300}, data : ''}
writeResponse(currentRequest, res)
return
cwmpResponse.methodResponse = {type : 'InformResponse'}
if config.LOG_INFORMS