0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

学习 sneaker

Last updated at Posted at 2015-09-24

sneaker 很好的把使用 bunny 和 rabbitmq 封装了起来, 而且提供了灵活的进程管理机制. 成为 rabbitmq 官方的推荐版本. 下面来看看它到底做了些什么.

首先来看看 Demo:

require 'sneakers'
require 'redis'
require 'json'

# $redis = Redis.new

class Processor
  include Sneakers::Worker
  from_queue :logs

  def work(msg)
    err = JSON.parse(msg)
    if err["type"] == "error"
      #$redis.incr "processor:#{err["error"]}"
      puts err["error"]
    end

    ack!
  end
end

然后通过

─> sneakers work Processor --require boot.rb

就可以启动当前这个Processor作为一个worker来处理 message.
然后默认会创建4个进程来监听代码里设定的queue logs, 默认在对于 queue 的处理上,当没有对应的 queue 的时候它会负责创建.

  • Sneakers::Publisher

It uses a hybrid process-thread model where many processes are spawned (like Unicorn) and many threads are used per process (like Puma), so all your cores max out and you have best of both worlds.

这个信息量有点大啊. 采用超轻量的进程-线程模式.

  • Unicorn那样,复制很多的进程.
  • 然后像Puma那样,每一个进程都使用了多线程.

所有这样可以最大使用CPU;

尼玛最后跑题了啊, 跑到了进程线程哪里去了!!!

link:

  1. http://thorstenball.com/blog/2014/11/20/unicorn-unix-magic-tricks/
  2. http://unicorn.bogomips.org/
  3. http://media.pragprog.com/titles/jsthreads/wwrt-puma.pdf
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?