PERF: stop running background work between requests

Use a dedicated thread to run Scheduler::Defer

This avoids blocking of a worker during operations that require waiting.

In particular uploads risked blocking a unicorn.

This also add a queue "length" that discourse prometheus consumes.
This commit is contained in:
Sam
2017-11-23 15:48:47 +11:00
parent d43a54e83a
commit 2b8d4508e5
4 changed files with 7 additions and 17 deletions

View File

@@ -8,6 +8,10 @@ module Scheduler
@thread = nil
end
def length
@queue.length
end
def pause
stop!
@paused = true
@@ -80,16 +84,6 @@ module Scheduler
end
class Defer
module Unicorn
def process_client(client)
Defer.pause
super(client)
Defer.do_all_work
Defer.resume
end
end
extend Deferrable
initialize
end