- Don't use EventMachine.defer for running message handlers. Turns out it's

faster if we don't push the call off to another thread.
This commit is contained in:
Jordan Sissel 2009-08-18 09:48:29 +00:00
parent 42df5ba36b
commit 7b83c35eaf

View file

@ -33,15 +33,20 @@ module LogStash; module Net
name = msg.class.name.split(":")[-1]
func = "#{name}Handler"
if @handler.respond_to?(func):
operation = lambda do
@handler.send(func, msg) do |response|
sendmsg(response)
end
end
EventMachine.defer(operation, nil)
#@handler.send(func, msg) do |response|
#sendmsg(response)
#operation = lambda do
#@handler.send(func, msg) do |response|
#sendmsg(response)
#end
#end
#EventMachine.defer(operation, nil)
# We actually get better performance if we don't defer processing
# to another thread. This should be done carefully, though, as
# blocking here will block the receiving thread for this socket
# (maybe for all of eventmachine?).
@handler.send(func, msg) do |response|
sendmsg(response)
end
else
$stderr.puts "#{@handler.class.name} does not support #{func}"
end
@ -50,7 +55,6 @@ module LogStash; module Net
if len > 0
puts "Removing #{len} bytes (#{count} packets)"
@buffer[0 .. len - 1] = ""
sleep 1
end
end # def receive_data