The following patch will lower redis' CPU utilization when ruote is
using redis (ruote-redis) for storage:

class Ruote::Redis::Storage
  def reserve(doc)
    return true if doc['type'] == 'msgs'
    (@redis.del(key_for(doc)) == 1)
  end

  def put_msg(action, options)
    doc = prepare_msg_doc(action, options)
    @redis.rpush('msgs', to_json(doc))
    nil
  end

  def get_msgs
    msgs = []
    while (doc = @redis.lpop('msgs')) and (msgs.size < 21)
      msgs << from_json(doc)
    end
    msgs
  end

  protected
  def lock(key, &block)
    kl = "#{key}-lock"
    loop do
      break if @redis.setnx(kl, Time.now.to_f.to_s) != false
      t = @redis.get(kl)
      @redis.del(kl) if t && Time.now.to_f - t.to_f > 60.0
      sleep 0.007 # let's try to lock again after a while
    end
    result = block.call
    @redis.del(kl)
    result
  end
end

This patch lowered our redis' CPU utilization from 47%+ downto 16%;
code was taken from the class Ruote::Redis::Storage of the ruote-
redis' master branch and is applied to the 2.2.0 (latest) version of
ruote-redis.

-- 
you received this message because you are subscribed to the "ruote users" group.
to post : send email to [email protected]
to unsubscribe : send email to [email protected]
more options : http://groups.google.com/group/openwferu-users?hl=en

Reply via email to