mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Conditionalize thread local cleaning. Possible perf degradation fix
This commit is contained in:
parent
75d9044247
commit
751720a3db
3 changed files with 16 additions and 2 deletions
|
@ -212,6 +212,13 @@ module Puma
|
|||
@options[:binds] << "tcp://#{Configuration::DefaultTCPHost}:#{port}"
|
||||
end
|
||||
|
||||
# Work around leaky apps that leave garbage in Thread locals
|
||||
# across requests
|
||||
#
|
||||
def clean_thread_locals(which=true)
|
||||
@options[:clean_thread_locals] = which
|
||||
end
|
||||
|
||||
# Daemonize the server into the background. Highly suggest that
|
||||
# this be combined with +pidfile+ and +stdout_redirect+.
|
||||
def daemonize(which=true)
|
||||
|
|
|
@ -259,6 +259,8 @@ module Puma
|
|||
end
|
||||
end
|
||||
|
||||
@thread_pool.clean_thread_locals = @options[:clean_thread_locals]
|
||||
|
||||
@reactor = Reactor.new self, @thread_pool
|
||||
|
||||
@reactor.run_in_thread
|
||||
|
|
|
@ -36,9 +36,12 @@ module Puma
|
|||
@mutex.synchronize do
|
||||
@min.times { spawn_thread }
|
||||
end
|
||||
|
||||
@clean_thread_locals = false
|
||||
end
|
||||
|
||||
attr_reader :spawned, :trim_requested
|
||||
attr_accessor :clean_thread_locals
|
||||
|
||||
# How many objects have yet to be processed by the pool?
|
||||
#
|
||||
|
@ -89,8 +92,10 @@ module Puma
|
|||
|
||||
break unless continue
|
||||
|
||||
Thread.current.keys.each do |key|
|
||||
Thread.current[key] = nil unless key == :__recursive_key__
|
||||
if @clean_thread_locals
|
||||
Thread.current.keys.each do |key|
|
||||
Thread.current[key] = nil unless key == :__recursive_key__
|
||||
end
|
||||
end
|
||||
|
||||
block.call(work, *extra)
|
||||
|
|
Loading…
Reference in a new issue