<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>Nicolas B. - sidekiq</title>
    <subtitle>Nicolas B., Ruby Backend Developer</subtitle>
    <link rel="self" type="application/atom+xml" href="https://nicolas-brousse.fr/tags/sidekiq/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://nicolas-brousse.fr"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2015-07-15T00:00:00+00:00</updated>
    <id>https://nicolas-brousse.fr/tags/sidekiq/atom.xml</id>
    <entry xml:lang="en">
        <title>Test #1 — Use Sidekiq on a separate servers</title>
        <published>2015-07-15T00:00:00+00:00</published>
        <updated>2015-07-15T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Nicolas B.
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://nicolas-brousse.fr/articles/2015-07-15-test-1-sidekiq-on-separate-servers/"/>
        <id>https://nicolas-brousse.fr/articles/2015-07-15-test-1-sidekiq-on-separate-servers/</id>
        
        <content type="html" xml:base="https://nicolas-brousse.fr/articles/2015-07-15-test-1-sidekiq-on-separate-servers/">&lt;img src=&quot;https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;banner.361201b45685ca07.jpg&quot; alt=&quot;&quot;
     data-zoomable=&quot;true&quot; data-zoom-src=&quot;https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;banner.361201b45685ca07.jpg&quot;
     width=&quot;1280&quot; height=&quot;512&quot;
     sizes=&quot;(min-width: 920px) 784px, (min-width: 700px) calc(82vw + 46px), calc(100vw - 40px)&quot; 
     srcset=&quot;https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;banner.97e7b0ea090816f9.jpg 640w,
             https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;banner.f7e1b98d978384fc.jpg 784w,
             https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;banner.36c72b2d3bddf572.jpg 1280w,
             https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;banner.66d3022e3055f746.jpg 1920w&quot;
     loading=&quot;lazy&quot;&gt;
&lt;p&gt;These last days I tried to use Sidekiq on different servers than the Rails app one.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;first-what-is-sidekiq&quot;&gt;First, What is Sidekiq?&lt;a class=&quot;post-anchor&quot; href=&quot;#first-what-is-sidekiq&quot; aria-label=&quot;Anchor link for: first-what-is-sidekiq&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;http:&#x2F;&#x2F;sidekiq.org&#x2F;&quot;&gt;Sidekiq&lt;&#x2F;a&gt; is a &lt;q&gt;Simple, efficient background processing for Ruby&lt;&#x2F;q&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;With more words, it’s a library who allows you to create job classes. A job contains the code pieces you want to perform later. It’s a kind of code decentralization.&lt;&#x2F;p&gt;
&lt;p&gt;And in this test the goal is to try running the job in different server than the web server.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;why&quot;&gt;Why?&lt;a class=&quot;post-anchor&quot; href=&quot;#why&quot; aria-label=&quot;Anchor link for: why&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
&lt;&#x2F;h2&gt;
&lt;p&gt;Why is it better to separate worker of web server?&lt;br &#x2F;&gt;
Imagine you need to do processes, so you use memory and CPU. In this case that means you take web server resources. So your web app could be slower.&lt;&#x2F;p&gt;
&lt;p&gt;By using different servers, it uses separate server resources. If process needs time, it takes the time it needs. And you could eventually decide to use a bigger server later.&lt;br &#x2F;&gt;
So it’s just easier to scale web and worker servers separately with you VPS or cloud hosting provider.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;test-in-pictures&quot;&gt;Test in pictures&lt;a class=&quot;post-anchor&quot; href=&quot;#test-in-pictures&quot; aria-label=&quot;Anchor link for: test-in-pictures&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
&lt;&#x2F;h2&gt;
&lt;p&gt;To do this test I used &lt;strong&gt;Vagrant&lt;&#x2F;strong&gt; with 3 VMs. One for the Rails &lt;code&gt;web&lt;&#x2F;code&gt; server and two others for Sidekiq named &lt;code&gt;worker-01&lt;&#x2F;code&gt; + &lt;code&gt;worker-02&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;For the Rails app code I simply used the one of the &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;http:&#x2F;&#x2F;railscasts.com&#x2F;episodes&#x2F;366-sidekiq&#x2F;&quot;&gt;Railscast #366&lt;&#x2F;a&gt; by &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;twitter.com&#x2F;rbates&quot;&gt;Ryan Bates&lt;&#x2F;a&gt;.&lt;br &#x2F;&gt;
I only converted the Sidekiq worker into a Rails ActiveJob.&lt;&#x2F;p&gt;
&lt;p&gt;The example is a simple snippets application.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;1-set-data-into-form&quot;&gt;1. Set data into form&lt;a class=&quot;post-anchor&quot; href=&quot;#1-set-data-into-form&quot; aria-label=&quot;Anchor link for: 1-set-data-into-form&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-1.5caa85a74a167c37.png&quot; alt=&quot;Form&quot;
     data-zoomable=&quot;true&quot; data-zoom-src=&quot;https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-1.5caa85a74a167c37.png&quot;
     width=&quot;1280&quot; height=&quot;769&quot;
     sizes=&quot;(min-width: 920px) 784px, (min-width: 700px) calc(82vw + 46px), calc(100vw - 40px)&quot; 
     srcset=&quot;https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-1.d4f8f22f617575a0.png 640w,
             https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-1.158211d3b5011337.png 784w,
             https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-1.d01f5346399f5f5f.png 1280w&quot;
     loading=&quot;lazy&quot;&gt;

This is the “homepage” and also the form to send the code of our snippet.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;2-after-data-posted&quot;&gt;2. After data posted&lt;a class=&quot;post-anchor&quot; href=&quot;#2-after-data-posted&quot; aria-label=&quot;Anchor link for: 2-after-data-posted&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-2.b8058e4222d8dfc0.png&quot; alt=&quot;Datas posted&quot;
     data-zoomable=&quot;true&quot; data-zoom-src=&quot;https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-2.b8058e4222d8dfc0.png&quot;
     width=&quot;1280&quot; height=&quot;769&quot;
     sizes=&quot;(min-width: 920px) 784px, (min-width: 700px) calc(82vw + 46px), calc(100vw - 40px)&quot; 
     srcset=&quot;https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-2.f040a6b1f5330880.png 640w,
             https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-2.7112e5b930798a61.png 784w,
             https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-2.ba6af315ed7ab9f1.png 1280w&quot;
     loading=&quot;lazy&quot;&gt;

After posted our snippet we could see the code. Currently the code is still raw. We have to wait the job is processed.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;3-after-worker-processed&quot;&gt;3. After worker processed&lt;a class=&quot;post-anchor&quot; href=&quot;#3-after-worker-processed&quot; aria-label=&quot;Anchor link for: 3-after-worker-processed&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-3.f54a079b6fec2af4.png&quot; alt=&quot;Datas processed&quot;
     data-zoomable=&quot;true&quot; data-zoom-src=&quot;https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-3.f54a079b6fec2af4.png&quot;
     width=&quot;1280&quot; height=&quot;769&quot;
     sizes=&quot;(min-width: 920px) 784px, (min-width: 700px) calc(82vw + 46px), calc(100vw - 40px)&quot; 
     srcset=&quot;https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-3.3862dc1d604ccc56.png 640w,
             https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-3.03e13d6274eae6fe.png 784w,
             https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-3.c18ac9026c45f6f4.png 1280w&quot;
     loading=&quot;lazy&quot;&gt;

Now the worker processed the job. The code is full of colors.
And we could see that the IP is a different one and the hostname as well.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;4-retry-a-new-once&quot;&gt;4. Retry a new once&lt;a class=&quot;post-anchor&quot; href=&quot;#4-retry-a-new-once&quot; aria-label=&quot;Anchor link for: 4-retry-a-new-once&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-4.3a61260042689898.png&quot; alt=&quot;Datas posted after retry&quot;
     data-zoomable=&quot;true&quot; data-zoom-src=&quot;https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-4.3a61260042689898.png&quot;
     width=&quot;1280&quot; height=&quot;769&quot;
     sizes=&quot;(min-width: 920px) 784px, (min-width: 700px) calc(82vw + 46px), calc(100vw - 40px)&quot; 
     srcset=&quot;https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-4.aee7a18c4fb16c1d.png 640w,
             https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-4.589dabdcfa2e769f.png 784w,
             https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-4.5e432d0ac2eb2c80.png 1280w&quot;
     loading=&quot;lazy&quot;&gt;

In my example I instantiate two worker servers. So I do others tests.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;5-after-worker-processed-on-a-different-worker&quot;&gt;5. After worker processed on a different worker&lt;a class=&quot;post-anchor&quot; href=&quot;#5-after-worker-processed-on-a-different-worker&quot; aria-label=&quot;Anchor link for: 5-after-worker-processed-on-a-different-worker&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-5.c4445e56f8f62b24.png&quot; alt=&quot;Datas processed after retry&quot;
     data-zoomable=&quot;true&quot; data-zoom-src=&quot;https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-5.c4445e56f8f62b24.png&quot;
     width=&quot;1280&quot; height=&quot;769&quot;
     sizes=&quot;(min-width: 920px) 784px, (min-width: 700px) calc(82vw + 46px), calc(100vw - 40px)&quot; 
     srcset=&quot;https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-5.8cf6ec6647795d01.png 640w,
             https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-5.084cb7c5f5f974c4.png 784w,
             https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-5.8aee9c879fbccff4.png 1280w&quot;
     loading=&quot;lazy&quot;&gt;

In this new test the IP is not the same than the other time. It’s not the same worker server who processed the job.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;sidekiq-admin&quot;&gt;Sidekiq admin&lt;a class=&quot;post-anchor&quot; href=&quot;#sidekiq-admin&quot; aria-label=&quot;Anchor link for: sidekiq-admin&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-6.293292b93cf5dceb.png&quot; alt=&quot;Sidekiq admin&quot;
     data-zoomable=&quot;true&quot; data-zoom-src=&quot;https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-6.293292b93cf5dceb.png&quot;
     width=&quot;1280&quot; height=&quot;770&quot;
     sizes=&quot;(min-width: 920px) 784px, (min-width: 700px) calc(82vw + 46px), calc(100vw - 40px)&quot; 
     srcset=&quot;https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-6.c8505d5a98fff9ad.png 640w,
             https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-6.a467c4167ea4ea00.png 784w,
             https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;img-6.4571224d643b8eb9.png 1280w&quot;
     loading=&quot;lazy&quot;&gt;

We have the list of the Sidekiq processes who are working. The two (or more) workers are listed here :)&lt;&#x2F;p&gt;
&lt;h2 id=&quot;serveurs-configuration&quot;&gt;Serveurs configuration&lt;a class=&quot;post-anchor&quot; href=&quot;#serveurs-configuration&quot; aria-label=&quot;Anchor link for: serveurs-configuration&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
&lt;&#x2F;h2&gt;
&lt;p&gt;Let see with scheme how it looks for the servers configuration.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;my-current-test-with-vagrant&quot;&gt;My current test with Vagrant&lt;a class=&quot;post-anchor&quot; href=&quot;#my-current-test-with-vagrant&quot; aria-label=&quot;Anchor link for: my-current-test-with-vagrant&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
&lt;&#x2F;h3&gt;
&lt;p&gt;For the test I did with Vagrant, it looked like this.&lt;&#x2F;p&gt;
&lt;img src=&quot;https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;configuration-vagrant.a9d5e3078aa8ccd5.png&quot; alt=&quot;Vagrant configuration&quot;
     data-zoomable=&quot;true&quot; data-zoom-src=&quot;https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;configuration-vagrant.a9d5e3078aa8ccd5.png&quot;
     width=&quot;661&quot; height=&quot;469&quot;
     sizes=&quot;(min-width: 920px) 784px, (min-width: 700px) calc(82vw + 46px), calc(100vw - 40px)&quot; 
     srcset=&quot;https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;configuration-vagrant.e6d0cd7b8cc2dd05.png 640w&quot;
     loading=&quot;lazy&quot;&gt;
&lt;p&gt;So we have the &lt;code&gt;web&lt;&#x2F;code&gt; server who also contains the Redis server and the Rails app. Because this is a test, I run the application in development mode with Rack.
The application is exactly the same used for the 3 servers. So I used an Sqlite as a file for simplicity.&lt;&#x2F;p&gt;
&lt;p&gt;For the &lt;code&gt;worker&lt;&#x2F;code&gt;s it uses the same Redis server and database. And I run the Sidekiq root process as a daemon.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;production-example&quot;&gt;Production example&lt;a class=&quot;post-anchor&quot; href=&quot;#production-example&quot; aria-label=&quot;Anchor link for: production-example&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
&lt;&#x2F;h3&gt;
&lt;p&gt;So, what about a production configuration? It could be something like this.&lt;&#x2F;p&gt;
&lt;img src=&quot;https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;configuration-production-example.40a7cfc01ee30012.png&quot; alt=&quot;Example of production configuration&quot;
     data-zoomable=&quot;true&quot; data-zoom-src=&quot;https:&#x2F;&#x2F;nicolas-brousse.fr&#x2F;processed_images&#x2F;configuration-production-example.40a7cfc01ee30012.png&quot;
     width=&quot;495&quot; height=&quot;908&quot;
     sizes=&quot;(min-width: 920px) 784px, (min-width: 700px) calc(82vw + 46px), calc(100vw - 40px)&quot; 
     srcset=&quot;&quot;
     loading=&quot;lazy&quot;&gt;
&lt;p&gt;And have separate &lt;code&gt;db&lt;&#x2F;code&gt; and &lt;code&gt;redis&lt;&#x2F;code&gt; servers. &lt;code&gt;web&lt;&#x2F;code&gt; servers only contain the application with the http server. If you want multiple &lt;code&gt;web&lt;&#x2F;code&gt; servers, you have to install a proxy server as HAProxy.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;code-sources&quot;&gt;Code sources&lt;a class=&quot;post-anchor&quot; href=&quot;#code-sources&quot; aria-label=&quot;Anchor link for: code-sources&quot;&gt;&lt;span aria-hidden=&quot;true&quot;&gt;#&lt;&#x2F;span&gt;&lt;&#x2F;a&gt;
&lt;&#x2F;h2&gt;
&lt;p&gt;If you want to test it, &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;nicolas-brousse&#x2F;1-sidekiq-separate-servers&quot;&gt;all the code is available on GitHub&lt;&#x2F;a&gt;.&lt;br &#x2F;&gt;
After clone or download you only have to install Vagrant (if you haven’t yet) and just &lt;code&gt;vagrant up&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Have fun 😄!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Sources:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;18265427&#x2F;is-it-possible-to-run-sidekiq-on-a-separate-host-from-the-rails-host&quot;&gt;Stackoverflow question about Sidekiq on separate server&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;http:&#x2F;&#x2F;docs.vagrantup.com&#x2F;v2&#x2F;multi-machine&#x2F;&quot;&gt;Vagrant multi-machine documentation&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;http:&#x2F;&#x2F;sidekiq.org&#x2F;&quot;&gt;Sidekiq website&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;http:&#x2F;&#x2F;railscasts.com&#x2F;episodes&#x2F;366-sidekiq&#x2F;&quot;&gt;‘Railscast #366 Sidekiq’&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;nicolas-brousse&#x2F;1-sidekiq-separate-servers&quot;&gt;Source code&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
</feed>
