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:
parent
d43a54e83a
commit
2b8d4508e5
|
@ -0,0 +1 @@
|
|||
require_dependency 'scheduler/defer'
|
|
@ -1,7 +0,0 @@
|
|||
require_dependency 'scheduler/defer'
|
||||
|
||||
if defined? Unicorn::HttpServer
|
||||
ObjectSpace.each_object(Unicorn::HttpServer) do |s|
|
||||
s.extend(Scheduler::Defer::Unicorn)
|
||||
end
|
||||
end
|
|
@ -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
|
||||
|
|
|
@ -31,6 +31,8 @@ describe Scheduler::Defer do
|
|||
x = 2
|
||||
end
|
||||
|
||||
expect(@defer.length).to eq(1)
|
||||
|
||||
@defer.do_all_work
|
||||
|
||||
expect(x).to eq(2)
|
||||
|
|
Loading…
Reference in New Issue