resque工人负荷分配不公平

时间:2011-03-02 18:33:00

标签: sinatra redis resque

我有一个由ActiveRecord支持的Resque Job,它将一条帖子消息保存到数据库中。 有7个工作器实例在运行。我向我的sinatra应用程序发送了20K记录。 当我查询redis数据库时,我看到以下结果......

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"

有人可以发表评论吗?  7名工人中有4名在其一生中只处理了1份工作

1 个答案:

答案 0 :(得分:1)

当我用RDBI替换ActiveRecord时,终于想通了。当我的工作人员尝试连接到oracle数据库时,我收到以下错误

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)

谷歌搜索后,我偶然发现了这篇文章http://kr.forums.oracle.com/forums/thread.jspa?messageID=3793101。所以,我决定将-Djava.security.egd = file:/// dev / urandom选项传递给我的jvm。我在glassfish的jvm选项中编辑了设置,但这不起作用,因为这些设置使我的sinatra应用程序受益,而不是在后台运行的resque工作者。

所以,我必须通过传递jvm参数来启动resque worker。我写了一个rake任务来做同样的事。

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