mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 23:31:18 +08:00
PERF: message_bus will be deferred by server when flooded
The message_bus performs a fair amount of work prior to hijacking requests this change ensures that if there is a situation where the server is flooded message_bus will inform client to back off for 30 seconds + random(120 secs) This back-off is ultra cheap and happens very early in the middleware. It corrects a situation where a flood to message bus could cause the app to become unresponsive MessageBus update is here to ensure message_bus gem properly respects Retry-After header and status 429. Under normal state this code should never trigger, to disable raise the value of DISCOURSE_REJECT_MESSAGE_BUS_QUEUE_SECONDS, default is to tell message bus to go away if we are queueing for 100ms or longer
This commit is contained in:
@ -139,17 +139,23 @@ class Middleware::RequestTracker
|
||||
|
||||
end
|
||||
|
||||
def self.populate_request_queue_seconds!(env)
|
||||
if !env['REQUEST_QUEUE_SECONDS']
|
||||
if queue_start = env['HTTP_X_REQUEST_START']
|
||||
queue_start = queue_start.split("t=")[1].to_f
|
||||
queue_time = (Time.now.to_f - queue_start)
|
||||
env['REQUEST_QUEUE_SECONDS'] = queue_time
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def call(env)
|
||||
result = nil
|
||||
log_request = true
|
||||
|
||||
# doing this as early as possible so we have an
|
||||
# accurate counter
|
||||
if queue_start = env['HTTP_X_REQUEST_START']
|
||||
queue_start = queue_start.split("t=")[1].to_f
|
||||
queue_time = (Time.now.to_f - queue_start)
|
||||
env['REQUEST_QUEUE_SECONDS'] = queue_time
|
||||
end
|
||||
::Middleware::RequestTracker.populate_request_queue_seconds!(env)
|
||||
|
||||
request = Rack::Request.new(env)
|
||||
|
||||
|
Reference in New Issue
Block a user