Code Monkey home page Code Monkey logo

sqskiq's Introduction

Build Status

Sqskiq

High performance, Sidekiq-like Amazon SQS messages consumer. Currently only supports Rails 3.x.

SQS is complete message solution powered by Amazon, including monitoring, alarms, redundancy, etc. Due to its particularities, we decided to build a message consumer from scratch, to better handle costs, latency and others.

Getting Start

  1. Add sqskiq to your Gemfile:
gem 'sqskiq'
  1. Add an initializer config/initializers/sqskiq.rb with:
  Sqskiq.configure do |config|
    config.aws_access_key_id = 'AWS_ACCESS_KEY_ID'
    config.aws_secret_access_key = 'AWS_SECRET_ACCESS_KEY'
  end
  1. Add a worker in app/workers to process messages asynchronously:
  class HardWorker
    include Sqskiq::Worker

    sqskiq_options queue_name: :queue_test

    def perform(message)
      # do something
    end
  end

The message received by this worker is an instance of AWS::SQS::ReceivedMessage

Configure the parallelism using the param processors: sqskiq_options queue_name: :queue_test, processors: 30 Currently, the min number of processors is 2 and the default is 20. Any unacceptable value will end up using the default.

Configure how long sqskiq will delay new fetches using the param empty_queue_throttle in seconds: sqskiq_options queue_name: :queue_test, empty_queue_throttle: 20 #for 20 seconds of delay If the queue got empty, sqskiq will wait empty_queue_throttle seconds to perform a new fetch. This can drastically reduce your sqs costs.

  1. Start Sqskiq and consume the queue:
  rails runner HardWorker.run

Deploy

Use a Procfile (like Heroku does) to start your workers. In your Procfile, add:

  queue_test: rails runner 'HardWorker.run'

Tips and Limitations

  • Currently, the minimum number of workers is 2
  • If your worker uses Mongoid, ActiveRecord, etc... make sure to disable data caches (or at least clean the data after each execution), otherwise your workers will explode.
  • Workers will automatically retry a job if the execution raises an exception
  • If the execution does not raise an exception, workers assume the execution ran cleanly and will remove the message from queue
  • Be aware of the costs of using SQS, even while under the service's free tier

Future and TODO's

  • Implement a better retry policy (today the message will be retried forever)
  • User can configure only one processor
  • Client side to send messages to SQS, handling batches
  • Better database integration with automatic cache clean
  • Load Celluloid only when the worker starts

sqskiq's People

Contributors

ricardolazaro avatar

Watchers

David Judd avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.