Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to run sidekiq on a separate host from the rails host?

I'd like to setup sidekiq so that it runs on a separate host from my rails app, to avoid weighing down the web server when running memory-intensive background tasks.

What are the configuration details I need to look at?

Are there known best practices or configurations for this?

EDIT:

To clarify, what I mean to ask is, how do I configure rails so that sidekiq API calls (MyWorker.perform_async) would run if the sidekiq process isn't running locally?

like image 220
Ovesh Avatar asked Aug 16 '13 03:08

Ovesh


People also ask

How do I run Sidekiq locally?

To run sidekiq, you will need to open a terminal, navigate to your application's directory, and start the sidekiq process, exactly as you would start a web server for the application itself. When the command executes you will see a message that sidekiq has started.

Is Sidekiq concurrent?

Sidekiq handles concurrency by using multiple threads in its process. This way, it can process multiple jobs at once, each thread processing one job at a time. By default, Sidekiq uses 10 threads per process. You can configure it to use more threads, thus increasing concurrency.

How does Sidekiq work in Rails?

Sidekiq server process pulls jobs from the queue in Redis and processes them. Like your web processes, Sidekiq boots Rails so your jobs and workers have the full Rails API, including Active Record, available for use. The server will instantiate the worker and call perform with the given arguments.


1 Answers

Edit to clarify

Before everything else, you should understand that when you run perform_async, it simply sticks the Jobs into a Redis queue. Sidekiq watches this queue and runs jobs when they come in. So as long as your app and your Sidekiq are looking at the same Redis server (and same database, of course), things will work.

Original answer

First, as you can probably guess, it will need a duplicate checkout of your code so that it can run. No big deal.

Secondly, it will need access to your database and redis servers on the other box. That means making sure those ports are open on the other server. That can get tricky, b/c you ideally don't want those exposed to the open Internet. Usually, for a multi-box setup, you'll have only one box exposed to the open Internet. It communicates with the rest of your boxes over private IPs:

Public Web server

Runs Apache/Nginx and maybe your app servers.

Private App Server(s) (optional)

Runs your app servers, if they aren't running on the Public server. Connects to your Database and Redis server.

Private Sidekiq Server(s) (optional)

Runs Sidekiq. Connects to your Database and Redis server.

Private Database/Redis Server

Runs database and Redis. Of course they can split out to different servers if required.

like image 58
bioneuralnet Avatar answered Nov 02 '22 20:11

bioneuralnet