A platform for community discussion. Free, open, simple.
PERF: remove image optimization throttling from Sidekiq
Sam9c91e6835164
diff --git a/app/models/optimized_image.rb b/app/models/optimized_image.rbindex 5cc24846543..2b5f9864e86 100644--- a/app/models/optimized_image.rb+++ b/app/models/optimized_image.rb@@ -11,12 +11,20 @@ class OptimizedImage < ActiveRecord::Basedef 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}") doyieldend+ else+ DistributedMutex.synchronize("optimized_image_host_#{@hostname}") do+ DistributedMutex.synchronize("optimized_image_#{upload_id}_#{width}_#{height}") do+ yield+ end+ endendend