Class: EM::VarnishLog::Connection
- Inherits:
-
Object
- Object
- EM::VarnishLog::Connection
- Defined in:
- lib/em/varnish_log/connection.rb
Overview
A subclass of EM::Connection that reads from the Varnish log SHM and pushes single log entries on the channel passed to its constructor.
Note that simply using an EM::Channel pretty much guarantees awful performance, suitable only for extremely low workloads in a development environment. The provided EM::BufferedChannel improves things quite a bit: it has proved able to push about 150k entries per second (corresponding to about 4k HTTP req/s), using a full CPU on a modern MBP.
Class Attribute Summary collapse
-
.channel ⇒ Object
readonly
Returns the value of attribute channel.
Instance Method Summary collapse
-
#initialize(channel) ⇒ Connection
constructor
A new instance of Connection.
- #run ⇒ Object
Constructor Details
#initialize(channel) ⇒ Connection
Returns a new instance of Connection.
22 23 24 |
# File 'lib/em/varnish_log/connection.rb', line 22 def initialize(channel) @channel = channel end |
Class Attribute Details
.channel ⇒ Object (readonly)
Returns the value of attribute channel.
19 20 21 |
# File 'lib/em/varnish_log/connection.rb', line 19 def channel @channel end |
Instance Method Details
#run ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/em/varnish_log/connection.rb', line 26 def run vd = Varnish::VSM.VSM_New Varnish::VSL.VSL_Setup(vd) Varnish::VSL.VSL_Open(vd, 1) callback = Proc.new { |*args| cb(*args) } Thread.new do begin Varnish::VSL.VSL_Dispatch(vd, callback, FFI::MemoryPointer.new(:pointer)) rescue => e puts "exception in thread: #{e.inspect}" ensure EM.stop end end rescue => e puts "exception in post_init: #{e.inspect}" end |