Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deferred message delivery spikes CPU usage to 100% #1

Open
mtodd opened this issue Apr 22, 2009 · 2 comments
Open

Deferred message delivery spikes CPU usage to 100% #1

mtodd opened this issue Apr 22, 2009 · 2 comments

Comments

@mtodd
Copy link

mtodd commented Apr 22, 2009

This is directly related to:

http://code.google.com/p/xmpp4r-simple/issues/detail?id=7#makechanges

The culprit is start_deferred_delivery_thread with the following code:

def start_deferred_delivery_thread #:nodoc:
Thread.new {
  loop {
    messages = [queue(:pending_messages).pop].flatten
    messages.each do |message|
      if subscribed_to?(message[:to])
        deliver(message[:to], message[:message], message[:type])
      else
        queue(:pending_messages) << message
      end
    end
  }
}

end

The loop has absolutely no sleep time and will run at max speed, continually dequeueing and queueing until there is no more CPU power left, then it keeps going until nothing else runs on your computer (unless you've got god/monit monitoring it) until the subscription actually occurs.

In my production environment, this is asynchronous, and can occur even upwards of days later, and I'd rather not have my CPU raped for that long.

@mtodd
Copy link
Author

mtodd commented Apr 22, 2009

Committed quick fix and submitted pull request with tests.

@mtodd
Copy link
Author

mtodd commented Apr 23, 2009

http://github.com/mtodd/xmpp4r-simple just in case you want to inspect my patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant