A platform for community discussion. Free, open, simple.
PERF: slow down optimizing images per host
Samc42bb9436266
diff --git a/app/models/optimized_image.rb b/app/models/optimized_image.rbindex 46db20458f1..82b64797258 100644--- a/app/models/optimized_image.rb+++ b/app/models/optimized_image.rb@@ -10,10 +10,10 @@ class OptimizedImage < ActiveRecord::BaseVERSION = 1def 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- @mutex ||= Mutex.new- @mutex.synchronize do+ DistributedMutex.synchronize("optimized_image_host_#{@hostname}") doDistributedMutex.synchronize("optimized_image_#{upload_id}_#{width}_#{height}") doyieldend