<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>ruby rails sidekiq resque asynchronous on random thoughts</title><link>https://awesomeprogrammer.com/categories/ruby-rails-sidekiq-resque-asynchronous/</link><description>Recent content in ruby rails sidekiq resque asynchronous on random thoughts</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Thu, 03 Oct 2013 00:00:00 +0000</lastBuildDate><atom:link href="https://awesomeprogrammer.com/categories/ruby-rails-sidekiq-resque-asynchronous/index.xml" rel="self" type="application/rss+xml"/><item><title>Migrating from resque to sidekiq</title><link>https://awesomeprogrammer.com/blog/2013/10/03/migrating-from-resque-to-sidekiq/</link><pubDate>Thu, 03 Oct 2013 00:00:00 +0000</pubDate><guid>https://awesomeprogrammer.com/blog/2013/10/03/migrating-from-resque-to-sidekiq/</guid><description><![CDATA[<p>In a company I&rsquo;m currently working we have been using <a href="https://github.com/resque/resque">resque</a> to do some heavy asynchronous work. And well, that&rsquo;s like obvious choice in Rails world - just go with resque, fork some processes and relax ;). But when you get to a point, when you need few hundred workers and few servers, you start to ask yourself - can&rsquo;t you do it better?</p>
<p>You probably can. There are some pretty smart folks out there, who were so kindly to share their knowledge. And that&rsquo;s how you can find <a href="https://github.com/mperham/sidekiq">sidekiq</a> build on top of <a href="https://github.com/celluloid/celluloid/">celluloid</a>.</p>
<p>Sidekiq uses multi-threading, so you can leverage that even if you use MRI (that have un-famous <a href="http://en.wikipedia.org/wiki/Global_Interpreter_Lock">GIL</a>) - if you have a lot of I/O bound work you can still benefit from this great piece of software (even without need to migrate to <a href="https://github.com/jruby/jruby">JRuby</a> or <a href="https://github.com/rubinius/rubinius">Rubinius</a>).</p>
<p>I ran some simple benchmarks and said to myself - hell yeah, let&rsquo;s just do it! About 70 commits later I completely integrated sidekiq, updated test suite and created some custom sidekiq middleware that I needed (man it&rsquo;s great, just <a href="https://github.com/mperham/sidekiq/wiki/Middleware">take a look at the docs</a>). Within 24 hours it processed over 1000000 jobs using 20x less amount of workers. How cool is that? I would say - pretty cool.</p>
<p>Few general tips and notes to all of you and to future-myself ;-)</p>
<ul>
<li>
<p>if you&rsquo;re coming from resque - <a href="https://github.com/mhfs/sidekiq-failures">sidekiq-failures</a> is like the second thing you should checkout, this will make you feel like home</p>
</li>
<li>
<p>when using mongoid - be sure to install <a href="https://rubygems.org/gems/kiqstand">kiqstand</a> to properly disconnect workers from db</p>
</li>
<li>
<p>remember about thread-safety, that also includes gems you are using, be aware of what you are putting in your Gemfile</p>
</li>
<li>
<p>if you need just write your of middleware, it&rsquo;s easy to test and easy to extract into separate gem and reuse in your other projects</p>
</li>
<li>
<p>I wouldn&rsquo;t recommend using resque with sidekiq within the same redis namespace. Theoretically you can, but I just wouldn&rsquo;t go for it, it&rsquo;s too messy. Yeah, you will need to web backends to monitor your jobs (if you are using resque+sidekiq combination somehow), but personally I think it&rsquo;s even better, especially if you are doing a lot of asynch work - it&rsquo;s easier to see what&rsquo;s going on.</p>
</li>
</ul>]]></description><content:encoded><![CDATA[<p>In a company I&rsquo;m currently working we have been using <a href="https://github.com/resque/resque">resque</a> to do some heavy asynchronous work. And well, that&rsquo;s like obvious choice in Rails world - just go with resque, fork some processes and relax ;). But when you get to a point, when you need few hundred workers and few servers, you start to ask yourself - can&rsquo;t you do it better?</p>
<p>You probably can. There are some pretty smart folks out there, who were so kindly to share their knowledge. And that&rsquo;s how you can find <a href="https://github.com/mperham/sidekiq">sidekiq</a> build on top of <a href="https://github.com/celluloid/celluloid/">celluloid</a>.</p>
<p>Sidekiq uses multi-threading, so you can leverage that even if you use MRI (that have un-famous <a href="http://en.wikipedia.org/wiki/Global_Interpreter_Lock">GIL</a>) - if you have a lot of I/O bound work you can still benefit from this great piece of software (even without need to migrate to <a href="https://github.com/jruby/jruby">JRuby</a> or <a href="https://github.com/rubinius/rubinius">Rubinius</a>).</p>
<p>I ran some simple benchmarks and said to myself - hell yeah, let&rsquo;s just do it! About 70 commits later I completely integrated sidekiq, updated test suite and created some custom sidekiq middleware that I needed (man it&rsquo;s great, just <a href="https://github.com/mperham/sidekiq/wiki/Middleware">take a look at the docs</a>). Within 24 hours it processed over 1000000 jobs using 20x less amount of workers. How cool is that? I would say - pretty cool.</p>
<p>Few general tips and notes to all of you and to future-myself ;-)</p>
<ul>
<li>
<p>if you&rsquo;re coming from resque - <a href="https://github.com/mhfs/sidekiq-failures">sidekiq-failures</a> is like the second thing you should checkout, this will make you feel like home</p>
</li>
<li>
<p>when using mongoid - be sure to install <a href="https://rubygems.org/gems/kiqstand">kiqstand</a> to properly disconnect workers from db</p>
</li>
<li>
<p>remember about thread-safety, that also includes gems you are using, be aware of what you are putting in your Gemfile</p>
</li>
<li>
<p>if you need just write your of middleware, it&rsquo;s easy to test and easy to extract into separate gem and reuse in your other projects</p>
</li>
<li>
<p>I wouldn&rsquo;t recommend using resque with sidekiq within the same redis namespace. Theoretically you can, but I just wouldn&rsquo;t go for it, it&rsquo;s too messy. Yeah, you will need to web backends to monitor your jobs (if you are using resque+sidekiq combination somehow), but personally I think it&rsquo;s even better, especially if you are doing a lot of asynch work - it&rsquo;s easier to see what&rsquo;s going on.</p>
</li>
</ul>]]></content:encoded></item></channel></rss>