mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
PERF: remove image optimization throttling from Sidekiq
Previously we only allowed one image optimization per machine, this meant there was cross talk between avatar resizing and Sidekiq. This could lead to large amounts of starvation when optimized image version changed which in turn could block the Sidekiq queue. This increases amount of allowed load on machines but this is preferable to having crosstalk between avatar resizing and Sidekiq.
This commit is contained in:
parent
940a61037c
commit
9c91e68351
@ -11,12 +11,20 @@ class OptimizedImage < ActiveRecord::Base
|
||||
|
||||
def self.lock(upload_id, width, height)
|
||||
@hostname ||= `hostname`.strip rescue "unknown"
|
||||
# note, the extra lock here ensures we only optimize one image per machine
|
||||
# this can very easily lead to runaway CPU so slowing it down is beneficial
|
||||
DistributedMutex.synchronize("optimized_image_host_#{@hostname}") do
|
||||
# note, the extra lock here ensures we only optimize one image per machine on webs
|
||||
# this can very easily lead to runaway CPU so slowing it down is beneficial and it is hijacked
|
||||
#
|
||||
# we can not afford this blocking in Sidekiq cause it can lead to starvation
|
||||
if Sidekiq.server?
|
||||
DistributedMutex.synchronize("optimized_image_#{upload_id}_#{width}_#{height}") do
|
||||
yield
|
||||
end
|
||||
else
|
||||
DistributedMutex.synchronize("optimized_image_host_#{@hostname}") do
|
||||
DistributedMutex.synchronize("optimized_image_#{upload_id}_#{width}_#{height}") do
|
||||
yield
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user