1
0
Fork 0
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:
Evan Phoenix 2014-11-25 23:18:30 -08:00
parent 75d9044247
commit 751720a3db
3 changed files with 16 additions and 2 deletions

View file

@ -212,6 +212,13 @@ module Puma
@options[:binds] << "tcp://#{Configuration::DefaultTCPHost}:#{port}" @options[:binds] << "tcp://#{Configuration::DefaultTCPHost}:#{port}"
end 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 # Daemonize the server into the background. Highly suggest that
# this be combined with +pidfile+ and +stdout_redirect+. # this be combined with +pidfile+ and +stdout_redirect+.
def daemonize(which=true) def daemonize(which=true)

View file

@ -259,6 +259,8 @@ module Puma
end end
end end
@thread_pool.clean_thread_locals = @options[:clean_thread_locals]
@reactor = Reactor.new self, @thread_pool @reactor = Reactor.new self, @thread_pool
@reactor.run_in_thread @reactor.run_in_thread

View file

@ -36,9 +36,12 @@ module Puma
@mutex.synchronize do @mutex.synchronize do
@min.times { spawn_thread } @min.times { spawn_thread }
end end
@clean_thread_locals = false
end end
attr_reader :spawned, :trim_requested attr_reader :spawned, :trim_requested
attr_accessor :clean_thread_locals
# How many objects have yet to be processed by the pool? # How many objects have yet to be processed by the pool?
# #
@ -89,9 +92,11 @@ module Puma
break unless continue break unless continue
if @clean_thread_locals
Thread.current.keys.each do |key| Thread.current.keys.each do |key|
Thread.current[key] = nil unless key == :__recursive_key__ Thread.current[key] = nil unless key == :__recursive_key__
end end
end
block.call(work, *extra) block.call(work, *extra)
end end