[Backgroundrb-devel] Slave socket problem again

Kamil Skalski kamil.skalski at gmail.com
Thu May 31 06:07:51 EDT 2007


Hello!

I have been using backgroundrb for a small project. My worker task is
run every minute, checks the processing queue in data-base and execute
the business method from Rails if something is to be done.

Unfortunately I was hit by the problem of backgroundrb server dying
after some runs. The exception is:

20070531-11:06:05 (31816) Starting worker: s_e_work sql_exe
(s_e_work_sql_exe) ()
20070531-11:07:05 (31816) Schedule triggered: #<struct
#<Class:0xb7df5324>
job=#<Proc:0xb7e3c274@/home/kskalski/railsapp/sars/vendor/plugins/backgroundrb/server/lib/backgroundrb/middleman.rb:355>,
trigger=#<BackgrounDRb::CronTrigger:0xb7a3b42c @day=1..31,
@cron_expr="5 * * * * * *", @sec=[5], @wday=0..6, @min=0..59,
@month=1..12, @hour=0..23, @year=nil>, earliest=Thu May 31 11:07:05
+0200 2007, last=Thu May 31 11:07:05 +0200 2007>
20070531-11:07:05 (31816) failed to find slave socket - (RuntimeError)
20070531-11:07:05 (31816)
/usr/local/lib/ruby/gems/1.8/gems/slave-1.2.0/lib/slave.rb:435:in
`initialize'
20070531-11:07:05 (31816)
/home/kskalski/railsapp/sars/vendor/plugins/backgroundrb/server/lib/backgroundrb/middleman.rb:210:in
`new'
20070531-11:07:05 (31816)
/home/kskalski/railsapp/sars/vendor/plugins/backgroundrb/server/lib/backgroundrb/middleman.rb:210:in
`new_worker'
20070531-11:07:05 (31816)
/home/kskalski/railsapp/sars/vendor/plugins/backgroundrb/server/lib/backgroundrb/thread_pool.rb:36:in
`dispatch'
20070531-11:07:05 (31816)
/home/kskalski/railsapp/sars/vendor/plugins/backgroundrb/server/lib/backgroundrb/thread_pool.rb:22:in
`initialize'

I tried suggestions from
http://rubyforge.org/pipermail/backgroundrb-devel/2007-March/000776.html
but it didn't help... actually it even get worse: I shortened the
class name of worker and I used druby protocol and after that server
fails even faster than before.
Also, what I have spotted - even though I enabled druby protocol (and
in logs there is entry:

20070531-10:24:33 (31813) protocol: druby
20070531-10:24:33 (31813) uri: druby://localhost:2000
20070531-10:24:33 (31813) config:
/home/kskalski/railsapp/sars/config/backgroundrb.yml
20070531-10:24:33 (31813) rails_env: development
20070531-10:24:33 (31813) socket_dir: /tmp/backgroundrb.31813
20070531-10:24:33 (31813) pool_size: 5
20070531-10:24:33 (31813) host: localhost
20070531-10:24:33 (31813) acl: denyallallowlocalhost 127.0.0.1orderdenyallow
20070531-10:24:33 (31813) temp_dir: /tmp
20070531-10:24:33 (31813) port: 2000
20070531-10:24:33 (31813) Installed DRb ACL
)

the server still uses sockets!!!  I have observed, that with every run
of worker the sockets directory gets a new entry, which is never
deleted... maybe this is a problem - new sockets are created, but
never deleted and system runs out of resources?


Currently my configuration is (backgroundrb.yml):
:port: 2000
:rails_env: development
:host: localhost
:protocol: druby
:pool_size: 5
:worker_dir: lib/workers

(backgroundrb_schedules.yml)
sql_scheduler:
  :class: :s_e_work
  :job_key: :sql_exe
  :trigger_args: 5 * * * * * *

Worker code is:
class SEWork < BackgrounDRb::Worker::RailsBase

  def do_work(args)
    # This method is called in it's own new thread
    begin
      script = SqlScript.find(:first, :conditions => [ 'state = ? AND
scheduled_run_at IS NOT NULL AND scheduled_run_at < ? OR' +
                                                       ' EXISTS
(SELECT id FROM execution_params WHERE sql_script_id = sql_scripts.id)
AND' +
                                                       ' state <> ?',
SqlScript::STATE_SCHEDULED, Time.now, SqlScript::STATE_RUNNING])

      if script.nil?
        logger.debug "Nothing to run"
      else
        if script.execution_param.nil?
          ret, status = script.scheduled_execute
        else
          ret, status = script.execute
        end
        logger.info "Executed (#{ret}) #{script.name} - #{status}"
      end
    rescue Exception
      logger.error "Problems executing sql executor worker: #{$!}"
    ensure
      # worker must be finished, otherwise stale process it leaved
      self.delete
    end
  end
end
SEWork.register

(note that I *have* self.delete at the end of worker code)

-- 
Kamil Skalski
http://nazgul.omega.pl


More information about the Backgroundrb-devel mailing list