resque worker load distribution not fair
I have a Resque Job backed by ActiveRecord that saves a post message to the database. Have 7 worker instances running. I send 20K records to my sinatra application. When i query the redis database, i see the follo开发者_StackOverflow社区wing results...
redis> get resque:stat:processed:localhost:6929:default
"5696"
redis> get resque:stat:processed:localhost:6930:default
"1"
redis> get resque:stat:processed:localhost:6942:default
"1"
redis> get resque:stat:processed:localhost:6953:default
"10854"
redis> get resque:stat:processed:localhost:6959:default
"3446"
redis> get resque:stat:processed:localhost:6972:default
"1"
redis> get resque:stat:processed:localhost:6986:default
"1"
can anyone comment on it please? 4 of the 7 workers only processed 1 job each in their lifetime
Finally figured it out when i replaced ActiveRecord with RDBI. I was getting the following error when my workers were trying to connect to the oracle database
java.sql.SQLRecoverableException: I/O Exception: Connection reset
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:281)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:118)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:224)
After googling, i stumbled upon this post http://kr.forums.oracle.com/forums/thread.jspa?messageID=3793101 . So, i decided to pass the -Djava.security.egd=file:///dev/urandom option to my jvm. I edited the settings in glassfish's jvm options, but that did not work as those settings benefited my sinatra app but not the resque workers running in the background.
So, i had to start the resque workers by passing the jvm argument. I wrote a rake task to do the same.
desc "Start multiple workers for JRUBY production environment which ocnnects to oracle database"
task :start_workers => :setup do
threads = []
ENV['COUNT'].to_i.times do
threads << Thread.new do
system "/usr/bin/java -Djdk.home= -Djava.security.egd=file:///dev/urandom -Djruby.home=/usr/local/rvm/rubies/jruby-1.6.0 -Djruby.script=jruby -Djruby.shell=/bin/bash -Djffi.boot.library.path=/usr/local/rvm/rubies/jruby-1.6.0/lib/native/ppc-Linux:/usr/local/rvm/rubies/jruby-1.6.0/lib/native/i386-Linux:/usr/local/rvm/rubies/jruby-1.6.0/lib/native/x86_64-Linux -Xmx500m -Xss1024k -Djruby.memory.max=500m -Djruby.stack.max=1024k -Dsun.java.command=org.jruby.Main -Djava.class.path=/usr/local/rvm/rubies/jruby-1.6.0/lib/mysql-connector-java-5.0.6-bin.jar:/usr/local/rvm/rubies/jruby-1.6.0/lib/ojdbc6.jar:/usr/local/rvm/rubies/jruby-1.6.0/lib/sqlitejdbc-v056.jar: -Xbootclasspath/a:/usr/local/rvm/rubies/jruby-1.6.0/lib/jruby.jar org/jruby/Main /usr/local/rvm/gems/jruby-1.6.0/bin/rake resque:work RACK_ENV=#{ENV['RACK_ENV']} QUEUE=#{ENV['QUEUE']} INTERVAL=#{ENV['INTERVAL']}"
end
end
threads.each { |thread| thread.join }
end
精彩评论