---
title: "rails后台任务比较"
author: "花花公子"
date: "2008-12-11T13:08:25Z"
tags: []
categories: ["编程语言"]
slug: "rails"
draft: false
lastmod: "2008-12-11T17:16:03Z"
id: 290635
url: "https://masterwujiang.iteye.com/blog/290635"
---

因工作需要，需要找一个[backgroundrb](http://backgroundrb.rubyforge.org/)类似的后台程序。花了一天时间，比较了几个插件，稍微写一下心得。

这些后台程序的组成基本一致：一个队列系统加上后台执行程序。队列系统一般是数据库或者走memcached协议的[starling](http://www.whomatchyou.com/articles/starling-a-ruby-persistent-queue-server-that-speaks-memcached.html)。所以，byebye，[backgroundrb](http://backgroundrb.rubyforge.org/)，使用drb实现队列的消息传递并不是一个好主意。

[backgroundrb](http://backgroundrb.rubyforge.org/)还有一个问题，更新队列的时候，它使用的是悲观锁，在查询的时候会导致数据库不响应。在大访问量的情况下，这种情况是不容允许的。

使用数据库主要是[background job](http://codeforpeople.rubyforge.org/svn/bj/trunk/README)和[background_fu](http://trix.pl/blog/running-long-background-tasks-in-ruby-on-rails-made-dead-simple.html)。相比之下，[background_fu](http://trix.pl/blog/running-long-background-tasks-in-ruby-on-rails-made-dead-simple.html)更简单，[bj](http://codeforpeople.rubyforge.org/svn/bj/trunk/README)需要三张表，略微繁琐了一点。

使用[starling](http://www.whomatchyou.com/articles/starling-a-ruby-persistent-queue-server-that-speaks-memcached.html)的就是[workling](http://www.justinball.com/2008/08/18/using-starling-workling-with-ruby-on-rails/)，这个还没有试过，准备服务器负载增大了以后再说。毕竟[starling](http://www.whomatchyou.com/articles/starling-a-ruby-persistent-queue-server-that-speaks-memcached.html)是[twitter](http://www.twitter.com)使用的消息系统，负载量应该没有问题。

update: [background_fu](http://trix.pl/blog/running-long-background-tasks-in-ruby-on-rails-made-dead-simple.html)还有点小bug，有空我要提交一下patch。