Xiaopei's DokuWiki

These are the good times in your life,
so put on a smile and it'll be alright

User Tools

Site Tools


it:beanstalkd

beanstalkd

Beanstalk is a simple, fast work queue.

Here is a picture of the typical job lifecycle:


   put            reserve               delete
  -----> [READY] ---------> [RESERVED] --------> *poof*



Here is a picture with more possibilities:



   put with delay               release with delay
  ----------------> [DELAYED] <------------.
                        |                   |
                        | (time passes)     |
                        |                   |
   put                  v     reserve       |       delete
  -----------------> [READY] ---------> [RESERVED] --------> *poof*
                       ^  ^                |  |
                       |   \  release      |  |
                       |    `-------------'   |
                       |                      |
                       | kick                 |
                       |                      |
                       |       bury           |
                    [BURIED] <---------------'
                       |
                       |  delete
                        `--------> *poof*
  • Beanspector, A commandline tool to quickly inspect beanstalk tubes and insert test data
  • nodestalker, A beanstalk client for node.js
  • beanstalkd 默认非持久化的, 重启服务后, 原任务会消失!
    $ node beanspector.js -st lims2_msg_extract
    ---
    name: lims2_msg_extract
    current-jobs-urgent: 1
    current-jobs-ready: 1
    # 重启之前有任务
     
    $ sudo service beanstalkd restart
     * Restarting in-memory queueing server beanstalkd                                                    [ OK ]
     
    # 重启之后 tube 都没了
    $ node beanspector.js -st lims2_msg_extract
    [ 'NOT_FOUND' ]
    $ node beanspector.js -lt
    ---
    - default
  • beanstalk -b DIR 可设置 binlog, 达到持久化储存的目的
  • beanstalk client 的 watch(some_tube) 除了会监视指名的 some_tube 外, 还 会默认监视 default tube
    • 所以在 watch(some_tube) 后, 需注意要 ignore(default)
    • 另外所有用 beanstalkd 的地方都要慎用 default, 应该不往 default 中插入东西
    • watch() 正确的示例用法如下:
      client
          .watch(some_tube)
          .onSuccess( function() {
              logger.info('watching ' + some_tube + ' tube');
       
              // client 默认会 watch default tube, 所以 watch 后,
              // 需手动 ignore default, 再执行业务
              if (some_tube != 'default') {
                  client.ignore('default').onSuccess(function(idata) {
       
                      logger.info('ignoring default tube');
       
                      handle();
                  });
              } else {
                  handle();
              }
          });
it/beanstalkd.txt · Last modified: 2016/04/20 16:54 by admin