mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 20:54:31 +08:00
PERF: slow down optimizing images per host
This commit is contained in:
parent
bfd052a317
commit
c42bb94362
|
@ -10,10 +10,10 @@ class OptimizedImage < ActiveRecord::Base
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
def self.lock(upload_id, width, height)
|
def self.lock(upload_id, width, height)
|
||||||
# note, the extra lock here ensures we only optimize one image per process
|
@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
|
# this can very easily lead to runaway CPU so slowing it down is beneficial
|
||||||
@mutex ||= Mutex.new
|
DistributedMutex.synchronize("optimized_image_host_#{@hostname}") do
|
||||||
@mutex.synchronize do
|
|
||||||
DistributedMutex.synchronize("optimized_image_#{upload_id}_#{width}_#{height}") do
|
DistributedMutex.synchronize("optimized_image_#{upload_id}_#{width}_#{height}") do
|
||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user