[ANN] eventmachine 0.12.10

64 views
Skip to first unread message

Aman Gupta

unread,
Oct 25, 2009, 8:28:33 PM10/25/09
to eventm...@googlegroups.com
I am happy to announce the release of eventmachine 0.12.10. Gems (including
binary builds for win32 and jruby) have been uploaded to rubyforge and should
be available via `gem install` shortly.

Since 0.12.8, we've had over 130 patches with numerous bug fixes, improvements
and several new features. Highlights include:

- Improved Performance
- subclasses of EM::Connection are not created unless necessary
- prevent unnecessary system calls to epoll_ctl/kevent
- the reactor uses numeric signatures instead of strings,
resulting in a ~15% overall performance boost

- API Changes
- EM.reactor_thread accessor for the reactor's thread
- EM.next_tick and EM.schedule are now thread-safe
- EM::connect will raise a more better EM::ConnectionError with details
- EM.epoll=/kqueue= will raise EM::Unsupported when unavailable
- improved the cryptic "no timer" exception and increased the
default limit to 10k timers
- bugfix and improved performance for EM.current_time
- EM.add_periodic_timer returns PeriodicTimer object
- EM::Connection#get_sock_opt wrapper for getsockopt()
- added EM.watch for notifications about file descriptors
for notify_read/writable events, you cannot use EM.attach
EM.watch(fd, Watcher){ |c| c.notify_readable = true }
- EM::Connection#pending_connect_timeout= setter (defaults to 20s)
- EM.bind_connect can bind to random source port using nil
EM.bind_connect('local.ip', nil, 'remote.ip', 1234)
- added EM::Connection#pause/resume/paused? to pause and resume I/O
- EM::Connection#proxy_incoming_to takes an optional buffer size for
limiting RAM usage when dealing with slow clients

- Protocol Additions
- allow overriding the serializer used for ObjectProtocol
- basic SOCKS v4 client protocol implementation

- Platform Support
AIX, OpenBSD, Solaris
- minor fixes to support these platforms
Windows
- fix missing unbind events on refused outbound connections
- fix issues with ruby 1.9 on windows

- Ruby Support
JRuby
- major overhaul of the jruby reactor for better compat and performance
- basic EM.attach/watch support on the Sun JVM
- fully compatible with JRuby 1.4
Ruby 1.9
- fix bugs trying to kill the EM.defer threadpool
- fix signal handling to catch ctrl+c and other signals gracefully
Rubinius
- minor changes to build a compatible C extension

Special thanks to the following people for making this release possible:
- Bernd Ahlers
- Chris Turner
- Dan Mayer
- Perry Smith
- Bill 'spatulasnout' Kelly
- Hemant 'gnufied' Kumar
- Jake 'yakischloba' Douglas
- James 'raggi' Tucker
- coderrr

The rdoc has been updated and is available at http://eventmachine.rubyforge.org

Aman

Roger Pack

unread,
Oct 26, 2009, 9:00:42 AM10/26/09
to eventm...@googlegroups.com
>    - EM::Connection#pending_connect_timeout= setter (defaults to 20s)

Nice. Thanks for keeping up with all that shtuff.
-r

Levent

unread,
Oct 30, 2009, 6:43:34 PM10/30/09
to EventMachine
I decided to use EM in some new code I've been writing recently. It
was working pretty good. But a few days ago what used to work stopped
working and have been pulling my hair for since then trying to figure
out the cause. Finally after retrying some basic client-server and
with EM.defer and seeing that now for some reason it doesn't work, I
decided to come to this group and post for help. Then I saw this
posting and checked my gems. I saw that 12.10 was there, which must
have been installed during a recent overall gem update. When I
reverted back to 0.8.1, the problem was disappeared (big sigh of
relief).

This version of EM gem has this very serious defect. EM.defer does
not work, it blocks the whole event loop. IMHO you should remove this
gem from distribution, at least for windows, until this defect is
fixed. Thanks.

Aman Gupta

unread,
Oct 30, 2009, 6:46:36 PM10/30/09
to EventMachine
0.8.1 is quite old. Can you try 0.12.8? Also if you can provide some
simple code showing the problem I can try to track it down and fix it.

Aman

Aman Gupta

unread,
Nov 1, 2009, 7:34:23 PM11/1/09
to Levent, eventm...@googlegroups.com
I just tried your script and am not able to reproduce the behavior
you're seeing on windows with eventmachine-0.12.10

C:\Documents and Settings\Administrator\code>gem which eventmachine
(checking gem eventmachine-0.12.10-x86-mswin32-60 for eventmachine)
c:/ruby/lib/ruby/gems/1.8/gems/eventmachine-0.12.10-x86-mswin32-60/lib/eventmachine.rb

C:\Documents and Settings\Administrator\code>ruby testserver.rb
-- someone connected to the echo server!
Processing [0]
-- someone disconnected from the echo server!
Processing [1]
Processing [2]
-- someone connected to the echo server!
Processing [0]
-- someone disconnected from the echo server!
Processing [3]
Processing [1]
Processing [4]
Processing [2]
Processing [5]
Processing [3]
Processing [6]
Processing [4]
Processing [7]
Processing [5]
Processing [8]
Processing [6]
Processing [9]
Processing [7]
Done with last count is [9]...
Processing [8]
Processing [9]
Done with last count is [9]...

To pass in arguments to your handlers, simply:

module Client
def initialize(one, two)
end
end

EM.connect 'host', 1234, Client, 'one', 2

Aman

On Sat, Oct 31, 2009 at 7:24 PM, Levent <levent...@gmail.com> wrote:
> 12.8 worked fine, similar to 8.1
> Below are the simple client and server code.
> After starting the server, invoke the client twice. You'll see two
> simultaneous bacground outputs from the deferred jobs on the server
> side with 12.8
> With 12.10, however, the second request does not go through.
>
> By the way, I'm relatively a rookie in Ruby and new to eventmachine
> and I would appreciate if you could help me figure out how I can pass
> a parameter into the modules used by EM:start_server or EM:connect.
> For example in the example below, I want to pass 'myvar' into the
> Client instead of $input so that I can loop through and create
> multiple connections to multiple machines each passing different type
> of data.
> I looked thru FAQ and snippet, but did not see a simple example
> illustrating that usage.
>
> Thanks,
> Levent
>
> ------------------
>
> require 'rubygems'
> require 'eventmachine'
>
> module Client
>   def post_init
>     send_data $input
>     @data = ""
>   end
>
>   def receive_data data
>     @data = data
>     if  @data
>       puts "RECEIVED" + @data
>       puts "Now we'll terminate the loop, which will also close the
> connection"
>       EventMachine::stop_event_loop
>     end
>   end
>
>   def unbind
>     puts "A connection has terminated"
>   end
>  end
>
> $input = 'mydata'
>
> # myvar = 'myvalue'
>  EventMachine::run {
>   EventMachine::connect "127.0.0.1", 8081,Client
>  }
>  puts "The event loop has ended"
>
>
> -------------
>
> require 'rubygems'
> require 'eventmachine'
>
> module EchoServer
>
>  def run_rats
>    i = 0
>    10.times do |i|
>      puts "Processing [#{i}] "
>      sleep 1
>    end
>    "last count is [#{i}]..."
>  end
>
>  def post_init
>    puts "-- someone connected to the echo server!"
>  end
>
>  def receive_data data
>    send_data ">>>you sent: #{data}"
>    operation = proc {
>      run_rats
>    }
>    callback = proc {|result|
>      puts 'Done with ' + result
>    }
>    EventMachine.defer( operation, callback )
>
>  end
>
>  def unbind
>    puts "-- someone disconnected from the echo server!"
>  end
> end
>
> EventMachine::run {
>  EventMachine::start_server "127.0.0.1", 8081, EchoServer
> }
> puts 'Finished server'

Jeff Seibert

unread,
Nov 2, 2009, 8:51:10 PM11/2/09
to EventMachine
I am seeing a crash on line 996 of eventmachine.rb: jobs is nil, so
nil.each throws an exception.

I have changed that line to:

(jobs ||= []).each { |j| j.call }

and it fixes it, but I am struggling to build the gem for jruby under
Ubuntu. How is this done?

Thanks!

Aman Gupta

unread,
Nov 2, 2009, 8:53:35 PM11/2/09
to eventm...@googlegroups.com
On Mon, Nov 2, 2009 at 5:51 PM, Jeff Seibert <jsei...@gmail.com> wrote:
>
> I am seeing a crash on line 996 of eventmachine.rb: jobs is nil, so
> nil.each throws an exception.

What ruby vm are you seeing this under? What happens if you apply this
patch instead:

diff --git a/lib/eventmachine.rb b/lib/eventmachine.rb
index cb3b14c..3a2ae52 100644
--- a/lib/eventmachine.rb
+++ b/lib/eventmachine.rb
@@ -990,8 +990,8 @@ module EventMachine
end

jobs = @next_tick_mutex.synchronize do
- jobs, @next_tick_queue = @next_tick_queue, []
- jobs
+ j, @next_tick_queue = @next_tick_queue, []
+ j
end
jobs.each { |j| j.call }
end


>
> I have changed that line to:
>
> (jobs ||= []).each { |j| j.call }
>
> and it fixes it, but I am struggling to build the gem for jruby under
> Ubuntu. How is this done?

rake java:gem will generate a jruby gem

Aman

>
> Thanks!
>
> >
>

Aman Gupta

unread,
Nov 2, 2009, 9:03:07 PM11/2/09
to eventm...@googlegroups.com
Can you provide a test case that reproduces this exception. Also,
could you try this patch:

diff --git a/lib/eventmachine.rb b/lib/eventmachine.rb
index cb3b14c..9939382 100644
--- a/lib/eventmachine.rb
+++ b/lib/eventmachine.rb
@@ -189,7 +189,7 @@ module EventMachine
end
@next_tick_mutex = Mutex.new
@reactor_running = false
- @next_tick_queue = nil
+ @next_tick_queue = []
@threadpool = nil


@@ -274,7 +274,7 @@ module EventMachine
@threadpool = nil
end

- @next_tick_queue = nil
+ @next_tick_queue = []
end
@reactor_running = false
@reactor_thread = nil
@@ -1092,7 +1092,7 @@ module EventMachine
def self.next_tick pr=nil, &block
raise ArgumentError, "no proc or block given" unless ((pr &&
pr.respond_to?(:call)) or block)
@next_tick_mutex.synchronize do
- (@next_tick_queue ||= []) << ( pr || block )
+ @next_tick_queue << ( pr || block )
end
signal_loopbreak if reactor_running?
end
Reply all
Reply to author
Forward
0 new messages