0.0
No commit activity in last 3 years
No release in over 3 years
Moves Resque enqueues out of the request cycle in a Rails application.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.13
>= 10.0
>= 3.0

Runtime

 Project Readme

lazyresque

Lazy Resque

Move Resque enqueues out of the Rails request cycle to help decrease time to first byte.

Install

From gem:

gem 'lazy_resque'

From source:

gem 'lazy_resque', git: 'git@github.com:samuelgiles/lazy_resque.git'

Use

Trigger the actual enqueue of the jobs after the request in an after_action block, this can be done by including LazyResque::ControllerEnqueue which will automatically add the after_action for you.

class ApplicationController < ActionController::Base
  include LazyResque::ControllerEnqueue

  def index
    Resque.lazy_enqueue(MyResqueJob, 1234, 'some_job_data')
  end
end

Why?

Though moving a long running task to a Resque job is beneficial the actual enqueuing process isn't free:

  • Any before_enqueue hooks are run
  • A new job instance is initialized and validated
  • Arguments are dumped/encoded into JSON
  • Redis rpush takes places requiring communication with the Redis server

This is fine for 1-2 enqueues in a request cycle but can add up to a measurable amount of time if your enqueuing several jobs.

You don't lose anything by moving the actual enqueuing outside the request cycle and it saves precious milliseconds.

How?

yodawg

Internally when you call Resque.lazy_enqueue the job class and arguments are stored in an array on a per request thread variable, then at the end of the request via the after_action callback the queue is looped through and the jobs are actually sent to Resque.