Created
December 12, 2014 03:45
-
-
Save adstage-david/d1057fb6e4b1a676cce4 to your computer and use it in GitHub Desktop.
Reproduces thread error - run in context of rails app with sidekiq_unique_jobs installed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'benchmark' | |
require_relative '../config/environment' | |
threads = [] | |
def connection(conn) | |
if conn | |
conn | |
else | |
Sidekiq.redis{|con| con } | |
end | |
end | |
def do_work(conn, i, j) | |
connection(conn).watch("foo#{i}#{j}") | |
connection(conn).get("foo#{i}#{j}") | |
connection(conn).get("foo#{i}#{j}") | |
connection(conn).multi do | |
connection(conn).set("foo#{i}#{j}", "bar") | |
connection(conn).setex("foo#{i}", 100, "#{j}") | |
end | |
connection(conn).get("foo#{i}#{j}") | |
connection(conn).get("foo#{i}") | |
end | |
5.times do |a| | |
threads << Celluloid::Future.new do |t| | |
100.times do |b| | |
if rand > 0.5 | |
do_work(nil, a, b) | |
else | |
Sidekiq.redis{|conn| | |
do_work(conn, a, b) | |
} | |
end | |
end | |
puts "Thread #{a} batch done. " | |
end | |
end | |
threads.map(&:value) | |
puts "Completed." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment