Giter Site home page Giter Site logo

eventmachine's Introduction

About EventMachine Build Status Code Climate Maintainability

What is EventMachine

EventMachine is an event-driven I/O and lightweight concurrency library for Ruby. It provides event-driven I/O using the Reactor pattern, much like JBoss Netty, Apache MINA, Python's Twisted, Node.js, libevent and libev.

EventMachine is designed to simultaneously meet two key needs:

  • Extremely high scalability, performance and stability for the most demanding production environments.
  • An API that eliminates the complexities of high-performance threaded network programming, allowing engineers to concentrate on their application logic.

This unique combination makes EventMachine a premier choice for designers of critical networked applications, including Web servers and proxies, email and IM production systems, authentication/authorization processors, and many more.

EventMachine has been around since the early 2000s and is a mature and battle-tested library.

What EventMachine is good for?

What platforms are supported by EventMachine?

EventMachine supports Ruby 2.0.0 and later (see tested versions at .github/workflows/workflow.yml). It runs on JRuby and works well on Windows as well as many operating systems from the Unix family (Linux, Mac OS X, BSD flavors).

Install the gem

Install it with RubyGems

gem install eventmachine

or add this to your Gemfile if you use Bundler:

gem 'eventmachine'

Getting started

For an introduction to EventMachine, check out:

Server example: Echo server

Here's a fully-functional echo server written with EventMachine:

 require 'eventmachine'

 module EchoServer
   def post_init
     puts "-- someone connected to the echo server!"
   end

   def receive_data data
     send_data ">>>you sent: #{data}"
     close_connection if data =~ /quit/i
   end

   def unbind
     puts "-- someone disconnected from the echo server!"
   end
end

# Note that this will block current thread.
EventMachine.run {
  EventMachine.start_server "127.0.0.1", 8081, EchoServer
}

EventMachine documentation

Currently we only have reference documentation and a wiki.

Community and where to get help

  • Join the mailing list (Google Group)
  • Join IRC channel #eventmachine on irc.freenode.net

License and copyright

EventMachine is copyrighted free software made available under the terms of either the GPL or Ruby's License.

Copyright: (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.

Alternatives

If you are unhappy with EventMachine and want to use Ruby, check out Celluloid.

eventmachine's People

Contributors

benburkert avatar bklang avatar davidsmalley avatar deiv avatar dj2 avatar dmargery avatar fabiokung avatar flameeyes avatar funny-falcon avatar garbagecat avatar gnufied avatar hsbt avatar igrigorik avatar jakedouglas avatar josh avatar junaruga avatar luislavena avatar michaelklishin avatar msp-greg avatar nolman avatar paddor avatar phiggins avatar portertech avatar raggi avatar razielgn avatar smparkes avatar sodabrew avatar tmm1 avatar voxik avatar wyhaines avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eventmachine's Issues

windows: slow nonblocking TCP, SO_SNDBUF (from Trac)

Moved from Trac

Reported by: spatulasnout Assigned to:
Priority: minor Milestone:
Keywords: windows slow nonblocking TCP SO_SNDBUF Cc:
Description ¶

Hi,

I ran across this article the other day, and figured I'd pass it along.

http://support.microsoft.com/kb/823764

I haven't done any benchmarks yet myself locally. But based on the article, it sounds like EventMachine may want to specify a fairly large SO_SNDBUF size on windows.

Regards,

EM equivalent to Open3.popen3 (from Trac)

Moved from Trac

Reported by: careo Assigned to:
Priority: major Milestone:
Keywords: Cc:
Description ¶

EM.popen behaves the same as IO.popen, which fails to capture stderr.

It'd be nice if there was an EM.popen3, or if EM.popen could take a stderr handler, that would capture the stderr of the child process.

03/17/09 01:55:02 changed by careo ¶

A pure-Ruby version of the above (with a painfully-bad "api") that works in both os x and linux can be found here: http://gist.github.com/80296 .

in a nutshell, it does is:

  1. open a new pipe
  2. reopen stderr to the writable end
  3. does the EM.popen as usual, passing in
  4. fixes stderr,

The confusing bit is that the stderr handler doesn't...handle... in linux if it uses receive_data, but works fine in os x. Everything works all around if it uses notify_readable however.
03/29/09 19:23:08 changed by tmm1 ¶

On Linux, calling recv() on a pipe was failing. Latest git uses read() instead.

improve set_effective_user (from Trac)

Moved from Trac

Reported by: tmm1 Assigned to: raggi (accepted)
Priority: minor Milestone: EventMachine "Framework"
Keywords: Cc: wyhaines
Description ¶

swiftiply uses:

    def self.run_as(user = "nobody", group = "nobody")
        Process.initgroups(user,Etc.getgrnam(group).gid) if user and group
        ::Process::GID.change_privilege(Etc.getgrnam(group).gid) if group
        ::Process::UID.change_privilege(Etc.getpwnam(user).uid) if user
    rescue Errno::EPERM
        raise "Failed to change the effective user to #{user} and the group to #{group}"
    end

maybe add a EM.run_as that supports groups, and rescues EPERM (incase you're already running as non-root)

Change History
06/30/08 20:12:59 changed by raggi ¶

* status changed from new to assigned.

Need to verify win32

need a way to tell why an unbind happened (from Trac)

Moved from Trac

either through an argument passed to unbind, or a method on Connection (get_reason, get_error, disconnect_reason, etc)

possible reasons would include:

  • eventmachine is shutting down
  • could not connect to remote end
  • remote end closed connection

02/26/09 14:07:54 changed by tmm1 ¶

See also:

http://groups.google.com/group/eventmachine/browse_thread/thread/5761a7576c33e677 http://groups.google.com/group/eventmachine/browse_thread/thread/84e360629cb7c65c

Java EM does not handle EM::Connection.error? (from Trac)

Reported by: cremes Assigned to:
Priority: major Milestone:
Keywords: Cc:
Description ¶

Any call to #error? fails with this backtrace:

cremes$ jruby a.rb connecting... a.rb:16:in post_init': undefined method report_connection_error_status' for EventMachine:Module (NoMethodError?)

from /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.7/lib/em/connection.rb:43:in `new' from /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.7/lib/em/connection.rb:36:in `instance_eval' from /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.7/lib/em/connection.rb:36:in `new' from /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.7/lib/eventmachine.rb:716:in `bind_connect' from /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.7/lib/eventmachine.rb:723:in `connect' from a.rb:32 from /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.7/lib/eventmachine.rb:1489:in `call' from /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.7/lib/eventmachine.rb:1489:in `event_callback' from /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.7/lib/jeventmachine.rb:48:in `eventCallback' from /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.7/lib/jeventmachine.rb:66:in `run_machine' from /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.7/lib/eventmachine.rb:242:in `run' from a.rb:27

That method is defined as:

def error?

    EventMachine::report_connection_error_status(@signature) != 0

end

I looked at the code for the C++ reactor which leads to ConnectionDescriptor::ReportErrorStatus? defined in ed.c. It is beyond my Java ability to translate this into Java otherwise I would have a patch.

Lack of this feature in the Java reactor is a blocker bug for running tmm1's AMQP gem under jruby.
Attachments

a.rb (0.6 kB) - added by cremes on 05/19/09 20:12:19.
sample program showing crash under jruby

Change History
05/19/09 20:12:19 changed by cremes

* attachment a.rb added.

sample program showing crash under jruby

1 require 'rubygems'
2 require 'eventmachine'
3
4 module EchoServer
5 def receive_data data
6 msg = ">>>you sent: #{data}"
7 puts msg
8 send_data msg
9 close_connection if data =~ /quit/i
10 end
11 end
12
13 module EchoClient
14 def post_init
15 send_data "hello\n"
16 puts "ERROR" if error?
17 end
18
19 def receive_data data
20 msg = "ok"
21 puts msg
22 send_data msg
23 close_connection if data =~ /quit/i
24 end
25 end
26
27 EventMachine::run {
28 EventMachine::start_server "0.0.0.0", 8081, EchoServer
29
30 EM.add_timer(1) {
31 puts "connecting..."
32 EventMachine::connect "0.0.0.0", 8081, EchoClient
33 }
34 }

SMTP authentication issues

The smtp server has two minor issues with authentication. First, it advertises the LOGIN authentication mechanism but doesn't support it. This breaks the JavaMail smtp api because it will always try that method before plain. Second, the PLAIN mechanism only accepted single-line auth commands, but not the multi-line command that the JavaMail API uses.

Patches from Roger Pack, including 1024 and 64 descriptor patch (from Trac)

Moved from Trac

Reported by: rogerdpack Assigned to: francis
Priority: major Milestone:
Keywords: Cc:
Description ¶

Unless using epoll or kqueue, EM incorrectly handles file descriptors > 1024 (> 64 on windows) It creates the new servers or connects the sockets, but the sockets are ignored by select and thus never have any of their actions called on them.

I'd be happy to update my patch to be against trunk if anybody would like it. http://rubyforge.org/tracker/index.php?group_id=1555&atid=6058

test_lotsa_sockets.rb (4.5 kB) - added by rogerdpack on 06/26/08 20:14:37.
lotsa_sockets_updated.diff (27.0 kB) - added by rogerdpack on 06/30/08 13:30:29.
updated diff. It includes a few extra functionality not related to this one [GetMaxTimers?] which should probably be extracted, and applies to a different ticket
lotsa_sockets_updated.2.diff (14.8 kB) - added by raggi on 06/30/08 19:34:08.
Munged out whitespace and other purely syntax changes, removed whole changeset for cmain.cpp (applied). Contains changes for select argument boundaries and get timer millis.

Change History
06/26/08 20:14:37 changed by rogerdpack

* attachment test_lotsa_sockets.rb added.

06/30/08 13:30:29 changed by rogerdpack

* attachment lotsa_sockets_updated.diff added.

updated diff. It includes a few extra functionality not related to this one [GetMaxTimers?] which should probably be extracted, and applies to a different ticket
06/30/08 13:31:20 changed by rogerdpack ¶

that diff also includes a mingw hack which would be nice, but isn't necessarily part of this ticket
06/30/08 14:27:10 changed by rogerdpack ¶

Ideally we should actually use IO Completion Ports for windows [though this patch is still necessary for Linux, since any descriptors > 1024 is not accepted by select].
06/30/08 19:32:09 changed by raggi ¶

* owner set to raggi.
* status changed from new to assigned.
* summary changed from EM errs with file descriptors over 1024 to Patches from Roger Pack, including 1024 and 64 descriptor patch.

Ok, I've refactored and merged in the error value changes on that patch. Renaming this to Roger patch set, and will re-open windows stuff.

* In your extconf changes, can you explain the PPC one, does mkmf not use uname -m?
* Can you confirm that uname -m returns a viable value (it should)? 

* The mingw stuff is already integrated on my branch, by using a POSIX (gcc) build chain target now. 

* The edd.cpp patch for assert(nbytes > 0); I have only seen this appear if kqueue is causing issues, can you confirm why and for what reason you added this patch? 

* The get timer quantumn millis I will split out into a seperate patch and apply as an aside. 

And down to about a 300 line diff (n.b. munged), that's a little more manageable. I will continue with this tomorrow.
06/30/08 19:34:08 changed by raggi

* attachment lotsa_sockets_updated.2.diff added.

Munged out whitespace and other purely syntax changes, removed whole changeset for cmain.cpp (applied). Contains changes for select argument boundaries and get timer millis.
07/14/08 22:20:52 changed by rogerdpack ¶

yeah I don't care about the PPC stuff anymore, but it worked as it should. Might fail in windows [?] I can't remember if I ran into the assert(nbytes > 0) problem in windows or not. I'd say leave it in until it gets recreated in windows. It gets thrown all the time [as you noted] with kqueue. See the other ticket regarding it. Thanks for doing that! -R
07/22/08 15:09:25 changed by raggi ¶

* owner changed from raggi to francis.
* status changed from assigned to new.

Francis, can you verify the remainder of this patchset?

I have applied / split out most of it, so the last diffset in the list should be good to look at.

pr_eventmachine fails on windows (from Trac)

Reported by: rogerdpack Assigned to:
Priority: major Milestone:
Keywords: Cc:
Description ¶

@seed = uuidgen.chomp.gsub(/-/,"")

from pr_eventmachine.rb fails on windoze boxes. Of course, this may be a low prio since windows boxes usually use the binary distro.

Minor fix for LineAndTextProtocol

From 5a77af54a27cfbf8e8354aa2c8e7c35153130e77 Mon Sep 17 00:00:00 2001
From: Chuck Remes <[email protected]>
Date: Sat, 30 May 2009 14:20:33 -0500
Subject: [PATCH] Minor fix for custom delimiters in the LineAndText protocol; it was
 still "chomping" off newlines when it should have preserved them.
 Fixed it plus added a new test to verify this behavior.

---
 lib/em/protocols/line_and_text.rb |    6 +++---
 tests/test_ltp.rb                 |   20 ++++++++++++++++++--
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/lib/em/protocols/line_and_text.rb b/lib/em/protocols/line_and_text.rb
index 4b3d797..2979642 100644
--- a/lib/em/protocols/line_and_text.rb
+++ b/lib/em/protocols/line_and_text.rb
@@ -39,16 +39,16 @@ module EventMachine
       def initialize *args
         super
         hsh = args.select { |element| element if element.respond_to?(:has_key?) && element.has_key?(:delimiter) }.first
-        delimiter = hsh ? hsh[:delimiter] : "\n"
+        @delimiter = hsh ? hsh[:delimiter] : "\n"

-        lbp_init_line_state delimiter
+        lbp_init_line_state @delimiter
       end

       def receive_data data
         if @lbp_mode == :lines
           begin
             @lpb_buffer.extract(data).each do |line| 
-              receive_line(line.chomp) if respond_to?(:receive_line)
+              receive_line(line.chomp(@delimiter)) if respond_to?(:receive_line)
             end
           rescue Exception
             receive_error('overlength line') if respond_to?(:receive_error)
diff --git a/tests/test_ltp.rb b/tests/test_ltp.rb
index 59eb9f8..dbdf0d6 100644
--- a/tests/test_ltp.rb
+++ b/tests/test_ltp.rb
@@ -114,11 +114,27 @@ class TestLineAndTextProtocol < Test::Unit::TestCase
       EventMachine.add_timer(4) {assert(false, "test timed out")}

       EventMachine.connect TestHost, TestPort, StopClient do |c|
-        c.send_data "aaa|bbb|ccc|"
+        c.send_data "aaa|bbb|ccc"
         c.close_connection_after_writing
       end
     }
-    assert_equal( %w(aaa bbb ccc), lines_received )
+    assert_equal( ["aaa", "bbb"], lines_received )
+  end
+
+  def test_custom_delimiter_preserves_newlines
+    lines_received = []
+    EventMachine.run {
+      EventMachine.start_server( TestHost, TestPort, SimpleLineTest, {:delimiter => "|"} ) do |conn|
+        conn.instance_eval "@line_buffer = lines_received"
+      end
+      EventMachine.add_timer(4) {assert(false, "test timed out")}
+
+      EventMachine.connect TestHost, TestPort, StopClient do |c|
+        c.send_data "aaa|bbb|ccc|\n|"
+        c.close_connection_after_writing
+      end
+    }
+    assert_equal( ["aaa", "bbb", "ccc", "\n"], lines_received )
   end


-- 
1.6.2.4

EM fails when out of descriptors on window

This output is generated from the code after it in doze [mingw 1.8.6]

1013
Assertion failed: nbytes > 0, file ed.cpp, line 916

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

$:.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
require 'eventmachine'
require 'socket'
require 'test/unit'

class Receiver < EM::Connection

  @@number_of_receipts = 0
  def post_init
    EM::Timer.new(1) { # 1 second later
      @sent = rand(100000).to_s
      send_data @sent
    }
  end

  def receive_data data
    if data != @sent
      puts "bad!"
    else
      @@number_of_receipts += 1
    end
  end

end

class EchoServer < EM::Connection

  @@count = 3
  def post_init
    # new connection
    puts @@count += 1
    EM.connect '127.0.0.1', 8081, Receiver # give me another!
  end

  def receive_data data
    send_data data # echo it back
    close_connection_after_writing
  end

end

class TestBasic < Test::Unit::TestCase

  def setup
    assert(!EM.reactor_running?)
  end

  def teardown
    assert(!EM.reactor_running?)
  end

  #-------------------------------------

  # this test is
  # connect as many as you can
  # and then send on all connections back to them all
  # and they should all get it back
  def test_use_all_descriptors_available

      EM.run {
        EventMachine::start_server "127.0.0.1", 8081, EchoServer
        EventMachine::connect '127.0.0.1', 8081, Receiver
      }


  end
end

EM::Timer should have helpers for common operations (reset timer and postpone timer) (from Trac)

Moved from Trac

Reported by: tmm1 Assigned to: raggi
Priority: minor Milestone: EventMachine "Framework"
Keywords: Cc:
Description ¶

class EventMachine::Timer
def reset seconds
prev = EM.instance_variable_get('@Timers')[@Signature]
cancel
initialize(seconds){ prev.call }
end

def postpone seconds
prev = EM.instance_variable_get('@Timers')[@Signature]
EM.instance_variable_get('@Timers')[@Signature] = proc{
EM.add_timer(seconds){ prev.call }
}
end
end

http://rubyeventmachine.com/attachment/ticket/77/timers.patch

Change History
09/05/08 18:03:21 changed by tmm1 ¶

initialize should probably also set @seconds, and reset should default to re-using the value of @seconds
09/12/08 02:12:06 changed by tmm1

* attachment timers.patch added.

09/25/08 17:54:23 changed by tmm1 ¶

This patch potentially causes leaks, if it holds a reference to the proc even after its fired. More generally, the behavior of #reset and #postpone is unclear if they are invoked after the timer was already fired.

EventMachine will segfault occasionally on program end (ends well branch) (from Trac)

Moved from Trac

If something interrupts EM currently during an unbind callback, EM will 'jump' to its release_machine block. At that point the Descriptors array is in a 'half finished' state, since it had been going through and deleting out members to be unbound. It therefore seg faults. This patch seems to do the trick [and, conveniently, might be slightly faster than the existing code, anyway]. Test included. Finally EM feels stable after this patch exists.

06/26/08 18:46:33 changed by rogerdpack

* attachment assure_ends_well.diff added.

patch and tests
06/28/08 10:29:10 changed by rogerdpack

I may need to submit an updated version of this patch that removes the Descriptor from the list before calling delete, in all cases. The one submitted currently works, however.
06/30/08 13:28:13 changed by rogerdpack

these changes need to be carefully examined to make sure that they remote the socket from the Descriptors list BEFORE being deleted. It may be the case it does it right now. I'm not sure.
06/30/08 20:20:05 changed by raggi

* owner set to raggi.
* priority changed from major to minor.
* status changed from new to assigned.

Interesting, will check back on this as soon as runtime patches are cleared, lowering priority until then, as it's an on-exit condition.
07/25/08 11:45:49 changed by raggi

* cc set to francis.

Summary of discussion:

* unbind callbacks need a refactor on the C++ side. Francis said he wants to move them out of the C++ destructor.
* some of the errors that reach event_callback could do with more debugging info, will create a separate ticket for that. 

It may also be relevant to add an errback system to run, which catches errors that fall through from event_callback.
07/25/08 14:26:08 changed by rogerdpack

There was an errback system but it was deemed to costly performance-wise. I would support an errback 'begin rescue' around EM.run itself, though [before the ensure that calls .release_system or what not].

It appears that v 0.12.0 and SVN trunk do this:

/opt/local/lib/ruby/gems/1.8/gems/eventmachine-0.12.0/lib/eventmachine.rb:226: [BUG] Segmentation fault ruby 1.8.6 (2008-03-03) [i686-darwin9.2.0]

while with the patch they do

test_ends_well_multi_thread(DeathEnd?): EventMachine::ConnectionNotBound?: EventMachine::ConnectionNotBound?

So I think what this is showing is that the first problem has been overcome, which revealed another problem. I'll look into it and see if it's easily fixable, as well as release a 'higher quality' version of this patch. -R
07/26/08 03:54:49 changed by rogerdpack

Francis' patch 756 seems to fix this by disallowing the "unbind newly dead sockets loop" to be interrupted, thus the stack isn't abandoned prematurely causing our old seg faults.

Unfortunately, now if several throw uncaught exceptions during unbind, it effectively 'discards' all the the last exception, and has a small performance hit. It does fix the bug in question, though.

I may be able to get my patch to work as well as his, however :) I might look at it sometime. Note that with the patch here we get 'connection unbound errors' which seems to match what happens currently when OTHER methods raise in a similar manner, as well. See next attached. Thanks! -R
07/26/08 03:57:18 changed by rogerdpack

* attachment test_handles_uncaught_exception.rb added.

01/27/09 18:25:14 changed by raggi

Merged into:

http://github.com/eventmachine/eventmachine/tree/ends_well

Highlights some new errors on trunk, where we're doing connection unbinding before setting up the binding.

epoll error handling

link error on mingw/rubyinstaller

On mingw/rubyinstaller eventmachine checks for libssl before checking for libcrypto, but since libssl depends on libcrypto the final link command (with -lcrypto -lssl) is incorrect and linker fails. The correct order of checking is first for libcrypto and then for libssl.

See snaury/eventmachine@0382057 for a patch

tests hang forever (windows)

Tried both 0.12.8 and 0.12.10

C:\Ruby\lib\ruby\gems\1.8\gems\eventmachine-0.12.8-x86-mswin32-60>rake test
... builds ...
C:/Ruby/bin/ruby.exe -Ilib -Iext -Iext/fastfilereader -Ijava tests/testem.rb
Loaded suite tests/testem
Started
..
C:\Ruby\lib\ruby\gems\1.8\gems\eventmachine-0.12.10-x86-mswin32-60>rake test
(in C:/Ruby/lib/ruby/gems/1.8/gems/eventmachine-0.12.10-x86-mswin32-60)
fatal: Not a git repository (or any of the parent directories): .git
Loaded suite C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
.

add cron style syntax on top of periodic timers in EM (from Trac)

Moved from Trac

Reported by: tmm1 Assigned to:
Priority: minor Milestone: EventMachine "Framework"
Keywords: Cc: raggi
Description ¶

Here's a simple one I'm using to run something daily at a given time (i.e. EM.daily('9:00am'){ puts 'Wake up!!' })

require 'ramaze/snippets' # for 1.day
require 'time' # for Time.parse
require 'eventmachine'

module EventMachine
def self.daily at, &blk
time = Time.parse(at) - Time.now
time += 1.day if time < 0

EM.run do
  EM::add_timer(time) do
    blk.call
    EM::add_periodic_timer(1.day, &blk)
  end
end

end
end

Change History
07/20/08 05:15:38 changed by tmm1 ¶

OpenWFEru has a great scheduler api: http://www.igvita.com/2007/03/29/scheduling-tasks-in-ruby-rails/
02/26/09 16:45:49 changed by tmm1 ¶

Also see http://github.com/javan/whenever/tree/master
02/27/09 23:41:21 changed by tmm1 ¶

This version schedules the next timer as soon as the new one fires, preventing "drift" over time:

require 'time'
module EventMachine
def self.daily at, &blk
time = Time.parse(at) - Time.now
time += 1.day if time < 0

EM.run do
  run_me = proc{
    EM.add_timer(1.day, run_me)
    blk.call
  }
  EM.add_timer(time, run_me)
end

end
end

02/28/09 01:12:24 changed by yakischloba ¶

here is some helper stuff, though not using cron syntax

http://github.com/yakischloba/em-timers/tree/master

EM epoll/kqueue don't use rb_tbr on 1.9 (from Trac)

Moved from Trac

_RunEpollOnce has to be split into two functions, one that can be provided to rb_thread_blocking_region

neverblock's performance (req/s using ab, three runs each) is currenty:

Ruby 1.8
with epoll: 58, 71, 68
without epoll: 160, 163, 148

Ruby 1.9
with epoll: 121, 127, 132
without epoll: 199, 203, 202

10/08/08 12:55:23 changed by rogerdpack ¶

why is this so different?
02/08/09 04:00:40 changed by tmm1 ¶

* owner changed from raggi to tmm1.
* status changed from new to assigned.

1.9.1p0 provides rb_thread_blocking_region_begin/end

see http://redmine.ruby-lang.org/issues/show/1130 and http://github.com/eventmachine/eventmachine/commit/5cb0794af9592b625a1832af8189e6eaf45defcf

EventMachine 0.12.4 fails to build on Solaris 10, 0.12.2 builds fine (from Trac)

Moved from Trac

Reported by: Alasdairrr Assigned to: raggi
Priority: minor Milestone:
Keywords: Cc:
Description ¶

Hello,

The new version of EventMachine (0.12.4) fails to build on Solaris. It assumes the GNU Linker is used, and during the build of ext/fastfilereader passes the "-shared" option to g++. On Solaris, the "-G" option should be passed, as per:

http://developers.sun.com/sunstudio/documentation/techart/gc_options.html

This happens when using gem, or manually building with rake. Further more, after manually linking ext/fastfilereader, "rake install" fails as it assumes GNU Tar:

tar: z: unknown function modifier Usage: tar {c|r|t|u|x}[BDeEFhilmnopPqTvw@[0-7]][bfk][X...] [blocksize] [tarfile] [size] [exclude-file...] {file | -I include-file | -C directory file}... rake aborted! Command failed with status (1): [tar zcvf eventmachine-0.12.4.tgz eventmach...]

An alternative such as "tar -cf - eventmachine-0.12.4 | gzip > eventmachine-0.12.4.tgz" is a more cross-platform version.

I can provide more information if needed, but the above should be enough to fix this.

EventMachine 0.12.2 builds correctly with Gem (I couldn't find the source version so I can't test whether it builds correctly with rake). So a change between the two versions has introduced options which break the build on Solaris.

Many thanks,

Alasdair

Change History
02/11/09 01:06:02 changed by tmm1 ¶

* owner set to raggi.

02/11/09 04:09:22 changed by raggi ¶

* status changed from new to assigned.

Alasdair,

I have created a branch at http://github.com/eventmachine/eventmachine/tree/solaris

Can you please, on a solaris box (I don't have one immediately to hand), do the following:

git clone git://github.com/eventmachine/eventmachine.git
cd eventmachine
git checkout -b solaris origin/solaris
rake build

if that works, I will merge into master, if not, please paste results here.

Thanks.
03/01/09 09:52:43 changed by raggi ¶

* priority changed from critical to minor.

Dropping priority, pending feedback.
03/03/09 01:55:16 changed by raggi ¶

* status changed from assigned to closed.
* resolution set to fixed.

Applied to master. Please re-open if the problem re-appears.
03/03/09 13:19:45 changed by nicksellen ¶

* status changed from closed to reopened.
* resolution deleted.

Hi, I've cloned the master branch and still having problems.

I'll attach the full output of rake build seperately but here is the output from running the following line whilst in ext/fastfilereader:

/opt/SUNWspro/bin/CC -I. -I. -I/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10 -I. -DBUILD_FOR_RUBY -DOS_UNIX -DOS_SOLARIS8 -I/usr/sfw/include -I/opt/sfw/include -D_FILE_OFFSET_BITS=64 -fPIC -g -O2 -fPIC -G -c mapper.cpp

CC: Warning: Option -fPIC passed to ld, if ld is invoked, ignored otherwise
CC: Warning: Option -fPIC passed to ld, if ld is invoked, ignored otherwise
"mapper.cpp", line 91: Error: Formal argument 1 of type char* in call to munmap(char_, unsigned) is being passed void_.
1 Error(s) detected.

changing the fPIC to the Sun Studio verion, KPIC doesn't help matters:

/opt/SUNWspro/bin/CC -I. -I. -I/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10 -I. -DBUILD_FOR_RUBY -DOS_UNIX -DOS_SOLARIS8 -I/usr/sfw/include -I/opt/sfw/include -D_FILE_OFFSET_BITS=64 -KPIC -g -O2 -G -c mapper.cpp

"mapper.cpp", line 91: Error: Formal argument 1 of type char* in call to munmap(char_, unsigned) is being passed void_.
1 Error(s) detected.

Thanks,

Nick (on behalf of Alasdair)
03/03/09 13:20:03 changed by nicksellen

* attachment eventmachine.rake.build.output added.

03/03/09 18:02:43 changed by tmm1 ¶

Pushed a patch for the issues posted above: http://github.com/eventmachine/eventmachine/commit/15bcb962c3cee4e72899e1df09436a6310116314

Nick, can you test against master again?
03/05/09 05:00:20 changed by nicksellen ¶

Hi, still no joy:

git clone git://github.com/eventmachine/eventmachine.git
cd eventmachine
rake build

gives:

root eventmachine (nsdev01): rake build
(in /root/eventmachine)
/opt/ec/ruby/1.8.6/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/gempackagetask.rb:13:Warning: Gem::manage_gems is deprecated and will be removed on or after March 2009.
cd ext
checking for rb_trap_immediate in ruby.h,rubysig.h... yes
checking for rb_thread_blocking_region()... no
checking for sys/event.h... no
checking for main() in -lnsl... yes
checking for main() in -lsocket... yes
sh: gnome-config: not found
checking for main() in -lssl... yes
checking for main() in -lcrypto... yes
checking for openssl/ssl.h... yes
checking for openssl/err.h... yes
creating Makefile
cd -
cd ext/fastfilereader
checking for main() in -lnsl... yes
checking for main() in -lsocket... yes
creating Makefile
cd -
cd ext
/opt/SUNWspro/bin/CC -I. -I. -I/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10 -I. -DBUILD_FOR_RUBY -DHAVE_RB_TRAP_IMMEDIATE -DHAVE_RBTRAP -DOS_UNIX -DOS_SOLARIS8 -DHAVE_OPENSSL_SSL_H -DHAVE_OPENSSL_ERR_H -DWITH_SSL -I/usr/sfw/include -I/opt/sfw/include -D_FILE_OFFSET_BITS=64 -fPIC -g -O2 -fPIC -G -c ed.cpp
CC: Warning: Option -fPIC passed to ld, if ld is invoked, ignored otherwise
CC: Warning: Option -fPIC passed to ld, if ld is invoked, ignored otherwise
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/ruby.h", line 554: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/ruby.h", line 555: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/ruby.h", line 556: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/ruby.h", line 557: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/ruby.h", line 558: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/ruby.h", line 559: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/ruby.h", line 560: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/ruby.h", line 577: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/ruby.h", line 594: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 129: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 136: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 137: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 138: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 141: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 142: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 147: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 148: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 179: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 194: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 239: Warning: attribute noreturn is unsupported and will be skipped..
20 Warning(s) detected.
/opt/SUNWspro/bin/CC -I. -I. -I/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10 -I. -DBUILD_FOR_RUBY -DHAVE_RB_TRAP_IMMEDIATE -DHAVE_RBTRAP -DOS_UNIX -DOS_SOLARIS8 -DHAVE_OPENSSL_SSL_H -DHAVE_OPENSSL_ERR_H -DWITH_SSL -I/usr/sfw/include -I/opt/sfw/include -D_FILE_OFFSET_BITS=64 -fPIC -g -O2 -fPIC -G -c epoll.cpp
CC: Warning: Option -fPIC passed to ld, if ld is invoked, ignored otherwise
CC: Warning: Option -fPIC passed to ld, if ld is invoked, ignored otherwise
/opt/SUNWspro/bin/CC -I. -I. -I/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10 -I. -DBUILD_FOR_RUBY -DHAVE_RB_TRAP_IMMEDIATE -DHAVE_RBTRAP -DOS_UNIX -DOS_SOLARIS8 -DHAVE_OPENSSL_SSL_H -DHAVE_OPENSSL_ERR_H -DWITH_SSL -I/usr/sfw/include -I/opt/sfw/include -D_FILE_OFFSET_BITS=64 -fPIC -g -O2 -fPIC -G -c em.cpp
CC: Warning: Option -fPIC passed to ld, if ld is invoked, ignored otherwise
CC: Warning: Option -fPIC passed to ld, if ld is invoked, ignored otherwise
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/ruby.h", line 554: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/ruby.h", line 555: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/ruby.h", line 556: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/ruby.h", line 557: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/ruby.h", line 558: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/ruby.h", line 559: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/ruby.h", line 560: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/ruby.h", line 577: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/ruby.h", line 594: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 129: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 136: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 137: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 138: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 141: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 142: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 147: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 148: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 179: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 194: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 239: Warning: attribute noreturn is unsupported and will be skipped..
"em.cpp", line 936: Error: Could not find a match for std::multimap<long long, EventMachine_t::Timer_t, std::less, std::allocator<std::pair<const long long, EventMachine_t::Timer_t>>>::insert(std::pair<long long, EventMachine_t::Timer_t>) needed in EventMachine_t::InstallOneshotTimer(int).
1 Error(s) and 20 Warning(s) detected.
*** Error code 1
make: Fatal error: Command failed for target `em.o'
rake aborted!
Command failed with status (1): [make...]
/root/eventmachine/Rakefile:141
(See full trace by running task with --trace)

cd ext/fastfilereader
ruby extconf.rb
gmake

gives:

root fastfilereader (nsdev01): gmake
/opt/SUNWspro/bin/CC -I. -I. -I/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10 -I. -DBUILD_FOR_RUBY -DOS_UNIX -DOS_SOLARIS8 -I/usr/sfw/include -I/opt/sfw/include -D_FILE_OFFSET_BITS=64 -fPIC -g -O2 -fPIC -G -c rubymain.cpp
CC: Warning: Option -fPIC passed to ld, if ld is invoked, ignored otherwise
CC: Warning: Option -fPIC passed to ld, if ld is invoked, ignored otherwise
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/ruby.h", line 554: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/ruby.h", line 555: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/ruby.h", line 556: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/ruby.h", line 557: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/ruby.h", line 558: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/ruby.h", line 559: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/ruby.h", line 560: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/ruby.h", line 577: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/ruby.h", line 594: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 129: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 136: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 137: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 138: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 141: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 142: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 147: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 148: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 179: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 194: Warning: attribute noreturn is unsupported and will be skipped..
"/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10/intern.h", line 239: Warning: attribute noreturn is unsupported and will be skipped..
20 Warning(s) detected.
/opt/SUNWspro/bin/CC -I. -I. -I/opt/ec/ruby/1.8.6/lib/ruby/1.8/i386-solaris2.10 -I. -DBUILD_FOR_RUBY -DOS_UNIX -DOS_SOLARIS8 -I/usr/sfw/include -I/opt/sfw/include -D_FILE_OFFSET_BITS=64 -fPIC -g -O2 -fPIC -G -c mapper.cpp
CC: Warning: Option -fPIC passed to ld, if ld is invoked, ignored otherwise
CC: Warning: Option -fPIC passed to ld, if ld is invoked, ignored otherwise
"mapper.cpp", line 92: Error: Formal argument 1 of type char* in call to munmap(char_, unsigned) is being passed const char_.
1 Error(s) detected.
gmake: *** [mapper.o] Error 1

also to note that it is still using -fPIC option not -KPIC as required by Sun Studio cc as on http://developers.sun.com/sunstudio/documentation/techart/gc_options.html.

keep going! happy to test more.
03/08/09 17:54:23 changed by tmm1 ¶

The two errors I'm still getting are:

"em.cpp", line 937: Error: Could not find a match for std::multimap<long long, EventMachine_t::Timer_t, std::less, std::allocator<std::pair<const long long, EventMachine_t::Timer_t>>>::insert(std::pair<long long, EventMachine_t::Timer_t>) needed in EventMachine_t::InstallOneshotTimer(int).

and

"cmain.cpp", line 56: Error: Could not find a match for EventMachine_t::EventMachine_t(extern "C" void()(const char,int,const char_,int)) needed in evma_initialize_library(extern "C" void()(const char,int,const char_,int)).

03/08/09 17:59:21 changed by tmm1 ¶

And also:

"cplusplus.cpp", line 37: Warning (Anachronism): Formal argument 1 of type extern "C" void()(const char,int,const char_,int) in call to evma_initialize_library(extern "C" void()(const char,int,const char_,int)) is being passed void()(const char,int,const char_,int).
"cplusplus.cpp", line 52: Error: Could not find a match for std::mapstd::string,void(_)()::insert(std::pair<const char*, void()()>) needed in EM::AddTimer(int, void(_)()).
"cplusplus.cpp", line 75: Error: Could not find a match for std::mapstd::string,EM::Eventable_::insert(std::pair<std::string, EM::Connection
>) needed in EM::Acceptor::Accept(const char_).
"cplusplus.cpp", line 117: Error: Could not find a match for std::mapstd::string,EM::Eventable_::insert(std::pair<std::string, EM::Connection*>) needed in EM::Connection::Connect(const char_, int).
"cplusplus.cpp", line 127: Error: Could not find a match for std::mapstd::string,EM::Eventable_::insert(std::pair<std::string, EM::Acceptor*>) needed in EM::Acceptor::Start(const char*, int).

These errors happen with 0.12.0 for me as well.
03/08/09 18:06:49 changed by tmm1 ¶

Could not find a match for std::multimap<...>::insert(std::pair<...,...>)
Compiler: Sun C++ 5.9
Cause: the multimap classes don't have a method insert(pair<First, Second>), only insert(pair<const First, Second>).
Solution: Instead of insert(make_pair(first, second)), use insert(mm::value_type(first, second)).

03/10/09 21:27:30 changed by tmm1 ¶

Fixes the compile issue but the resulting extension still doesn't work:

diff --git a/ext/cmain.cpp b/ext/cmain.cpp
index ea348fd..1a398a1 100644
--- a/ext/cmain.cpp
+++ b/ext/cmain.cpp
@@ -24,6 +24,8 @@ static EventMachine_t *EventMachine;
static int bUseEpoll = 0;
static int bUseKqueue = 0;

+typedef void (CppCb)(const char, int, const char_, int);
+
extern "C" void ensure_eventmachine (const char *caller = "unknown caller")
{
if (!EventMachine) {
@@ -53,7 +55,8 @@ extern "C" void evma_initialize_library (void(cb)(const char, int, const char_
#else
throw std::runtime_error ("eventmachine already initialized: evma_initialize_library");
#endif

  •   EventMachine = new EventMachine_t (cb);
    
  •   //EventMachine = new EventMachine_t (reinterpret_cast<CppCb>(cb));
    
  •   EventMachine = new EventMachine_t ((CppCb)cb);
    if (bUseEpoll)
            EventMachine->_UseEpoll();
    if (bUseKqueue)
    

agupta@sirius ~/eventmachine $ ~/ruby/bin/ -I lib -I ext -e 'require "rubyeventmachine"'
ext/rubyeventmachine.so: ld.so.1: ruby: fatal: relocation error: file ext/rubyeventmachine.so: symbol _1cDstdMbasic_string4Ccn0ALchar_traits4Cc__n0AJallocator4Cc___J__nullref: referenced symbol not found - ext/rubyeventmachine.so (LoadError)
from -e:1

Some compiler warnings (from Trac)

Moved from Trac

Reported by: raggi Assigned to: raggi
Priority: minor Milestone:
Keywords: Cc:
Description ¶

g++ -I. -I. -I/usr/lib64/ruby/1.8/x86_64-linux -I. -DBUILD_FOR_RUBY -DHAVE_RB_TRAP_IMMEDIATE -DHAVE_RBTRAP -DOS_UNIX -DHAVE_SYS_EPOLL_H -DHAVE_EPOLL -DWITH_SSL -fPIC -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -g -fno-strict-aliasing -fPIC -c cmain.cpp
cmain.cpp:543:2: warning: "/" within comment
cmain.cpp: In function 'int evma_send_file_data_to_connection(const char
, const char*)':

cmain.cpp:569: warning: comparison between signed and unsigned integer expressions

ed.cpp: In constructor 'DatagramDescriptor::DatagramDescriptor(int, EventMachine_t*)':

ed.cpp:1091: warning: unused variable 'sob'

em.h: In constructor 'EventMachine_t::EventMachine_t(void ()(const char, int, const char_, int))':
em.h:161: warning: 'EventMachine_t::kqfd' will be initialized after
em.h:158: warning: 'int EventMachine_t::epfd'
em.cpp:82: warning: when initialized here
em.cpp: In static member function 'static int EventMachine_t::SetRlimitNofile(int)':
em.cpp:262: warning: comparison between signed and unsigned integer expressions
em.cpp: In member function 'void EventMachine_t::SignalLoopBreaker()':
em.cpp:286: warning: ignoring return value of 'ssize_t write(int, const void_, size_t)', declared with attribute warn_unused_result
em.cpp: In member function 'bool EventMachine_t::RunEpollOnce()':
em.cpp:525: warning: comparison between signed and unsigned integer expressions
em.cpp: In member function 'void EventMachine_t::ReadLoopBreaker()':
em.cpp:859: warning: ignoring return value of 'ssize_t read(int, void
, size_t)', declared with attribute warn_unused_result
em.cpp: In member function 'const char
EventMachine_t::InstallOneshotTimer(int)':

em.cpp:913: warning: comparison between signed and unsigned integer expressions

kb.cpp: In member function 'virtual void KeyboardDescriptor::Read()':
kb.cpp:79: warning: ignoring return value of 'ssize_t read(int, void*, size_t)', declared with attribute warn_unused_result

bus error in ssl.rb in 1.8.7/1.9 with eventmachine (from Trac)

Moved from Trac

Description ¶

$ ruby -rubygems -e" require 'openssl' "; echo $?
0

$ ruby -rubygems -e" require 'eventmachine'; require 'openssl' "; echo $?
/opt/ruby-fibers/lib/ruby/1.8/openssl/ssl.rb:31: [BUG] Bus Error
ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-darwin9.6.0]

Abort trap
134

04/18/09 17:06:48 changed by yakischloba ¶

Is this still going on? Unable to reproduce

~ $ ruby -rubygems -e" require 'eventmachine'; require 'openssl' "; echo $?
0
~ $ ruby19 -e" require 'eventmachine'; require 'openssl' "; echo $?
0

pending_connect_timeout use

I would like to use pending_connect_timeout to prevent connecting not opened port and wait for 50 seconds (default timeout) but with last copy of eventmachine (git clone this repo)

with this sample code:

require 'rubygems'
require 'eventmachine'

class FirewallCheck < EventMachine::Connection
  def post_init
    super
    puts DateTime.now.to_s + ": connecting to..."
    send_data "GET / HTTP/1.1\r\nHost: _\r\n\r\n"
    @data = ""
  end

  def receive_data(data)
    @data << data
    if  @data =~ /[\n][\r]*[\n]/m
      puts "RECEIVED HTTP HEADER:"
      $`.each {|line| puts ">>> #{line}" }
      puts "Now we'll terminate the loop, which will also close the connection"
      EventMachine::stop_event_loop
    end
  end

  def unbind
    super
    puts DateTime.now.to_s + ": a connection has terminated"
  end
end

raise ArgumentError, "firewall_check.rb host port" if ARGV.length < 2

EventMachine::run {
  EventMachine::connect(ARGV[0], ARGV[1], FirewallCheck) { |c|
    c.comm_inactivity_timeout = 10
    c.pending_connect_timeout = 5
  }
}
puts "The event loop has ended"

this error occurs:

2009-10-08T15:10:39+02:00: connecting to...
2009-10-08T15:10:39+02:00: a connection has terminated
./eventmachine/lib/em/connection.rb:489:in `set_pending_connect_timeout': undefined method `set_pending_connect_timeout' for EventMachine:Module (NoMethodError)
    from ./eventmachine/lib/em/connection.rb:483:in `pending_connect_timeout='
    from firewall_checker.rb:33
    from ./eventmachine/lib/eventmachine.rb:751:in `bind_connect'
    from ./eventmachine/lib/eventmachine.rb:708:in `connect'
    from firewall_checker.rb:31
    from ./eventmachine/lib/eventmachine.rb:259:in `call'
    from ./eventmachine/lib/eventmachine.rb:259:in `run_machine'
    from ./eventmachine/lib/eventmachine.rb:259:in `run'
    from firewall_checker.rb:30

In the last version of eventmachine pending_connect_timeout is defined but calls a set_pending_connect_timeout method that is missing somewhere else.

smtpserver crashing on HELP command (from Trac)

Moved from Trac

EventMachine::Protocols::SmtpServer#receive_line? may call process_help, which isn't defined anywhere, causing an exception.

08/08/08 07:13:34 changed by raggi ¶

* owner set to raggi.
* status changed from new to assigned.

Verified, and there are more!

* process_vrfy
* process_expn
* process_help 

08/08/08 07:17:42 changed by raggi ¶

* priority changed from critical to major.

Initial problem resolved (in [768]), by implementing methods as somewhat noops. Needs real work, but demoting priority from critical to major.
01/27/09 16:20:39 changed by raggi ¶

* priority changed from major to minor.

A Smarter Better Threadpool for Eventmachine (from Trac)

Moved from Trac

Reported by: mebaran Assigned to: raggi (accepted)
Priority: minor Milestone:
Keywords: defer threads pool Cc:
Description ¶

This is a monkey patch I designed to augment Eventmachine's simple but ineffective threadpooling.

Implemented:

A monitoring thread that maintains the health of the threadpool. An EM based mechanism to timeout threads safely by raising an exception The ability to dynamically increase or decrease the size of the pool. A simple carry to allow you to pass data between the caller and the callback.

Planned

A more general signaling mechanism. Canceling of jobs should be available as soon as I have time to delve inside the implementation of the Thread Queue class (which is curiously devoid of any instance variables....)

To Do:

Figure out some comprehensive tests Research a way to avoid the use of Thread.exclusive

The goodness is handled by a call to EM.schedule which transparently sets up the scheduler if necessary. Pass in a lambda and set the callback for the result, errback to work with exceptions if execution goes awry, and hash options. Current thread options include timeout to kill a thread if it hangs too long and carry which allows the caller to pass independent information to the callback.

Attachments

scheduler.rb (3.7 kB) - added by mebaran on 10/10/08 16:20:38.
Implemenation of an eventmachine based scheduler.

Change History
10/10/08 16:20:38 changed by mebaran

* attachment scheduler.rb added. http://rubyeventmachine.com/attachment/ticket/87/scheduler.rb

Implemenation of an eventmachine based scheduler.
01/27/09 20:15:17 changed by raggi ¶

* owner set to raggi.
* status changed from new to assigned.

Need to investigate

Having a problem with connecting with the server (using AMQP gem)

Connecting to server and getting a no connection

Any ideas? Thanks!

tcp_connect: inp=0xba201f8 err=EADDRINUSE

/Users/maleko/workspace/geo/vendor/gems/gems/eventmachine-0.12.8/lib/eventmachine.rb:811:in connect_server': no connection (RuntimeError) from /Users/maleko/workspace/geo/vendor/gems/gems/eventmachine-0.12.8/lib/eventmachine.rb:811:inreconnect'
from /Users/maleko/workspace/geo/vendor/gems/gems/amqp-0.6.0/lib/amqp/client.rb:172:in reconnect' from /Users/maleko/workspace/geo/vendor/gems/gems/amqp-0.6.0/lib/amqp/client.rb:85:incall'
from /Users/maleko/workspace/geo/vendor/gems/gems/amqp-0.6.0/lib/amqp/client.rb:85:in unbind' from /Users/maleko/workspace/geo/vendor/gems/gems/eventmachine-0.12.8/lib/eventmachine.rb:995:incall'
from /Users/maleko/workspace/geo/vendor/gems/gems/eventmachine-0.12.8/lib/eventmachine.rb:995:in run_deferred_callbacks' from /Users/maleko/workspace/geo/vendor/gems/gems/eventmachine-0.12.8/lib/eventmachine.rb:995:intimes'
from /Users/maleko/workspace/geo/vendor/gems/gems/eventmachine-0.12.8/lib/eventmachine.rb:995:in run_deferred_callbacks' from /Users/maleko/workspace/geo/vendor/gems/gems/eventmachine-0.12.8/lib/eventmachine.rb:242:inrun_machine'
from /Users/maleko/workspace/geo/vendor/gems/gems/eventmachine-0.12.8/lib/eventmachine.rb:242:in run' from /Users/maleko/workspace/geo/vendor/gems/gems/amqp-0.6.0/lib/amqp.rb:81:instart'

Event Machine 0.12.2 Windows XP, Failing to build native extensions. (from Trac)

Moved from Trac

Reported by: Wertster Assigned to:
Priority: major Milestone: EventMachine "Framework"
Keywords: build fail Cc:
Description ¶

(not sure if I'm raising this correctly...but...)

When installing the eventmaching gem (0.12.2) under windows xp, I encounter a build failure when building native extensions. I'm running Windows XP SP3, Ruby 1.8.6 (2007-09-24 patch level 111) and my c-compiler is Visual C++ 6.0. The gem build fails on line 1186 of em.cpp, with the error message:

em.cpp(1193) : error C2374: 'i' : redefinition; multiple initialization

em.cpp(1186) : see declaration of 'i'

NMAKE : fatal error U1077: 'cl' : return code '0x2'

If I locally modify the code on line 1186 to declare the size_t i in the line prior to the for loop the make completes successfully.

Before (make failing): for (size_t i = 0; i < Descriptors.size(); i++)

After: size_t i; for (i = 0; i < Descriptors.size(); i++)

Not sure if this is own to my own complier settings or whether this is a bug...

02/11/09 07:59:30 changed by raggi ¶

A build has been verified working from the repository by our devs, could you verify, and close if that's the case.

http://github.com/eventmachine/eventmachine

NullPointerException sending message with EmReactor

Hi!

I am using tmm1-amqp-0.6.4 and EventMachine 0.12.10 to send model updates from ActiveRecord? with JRuby 1.4.0. This runs fine for a while, 5-50 minutes, then fails with a NullPointerException? in EventableSocketChannel?:

java.lang.NullPointerException?: null 
com/rubyeventmachine/EventableSocketChannel.java:206:in `writeOutboundData'
com/rubyeventmachine/EmReactor.java:275:in `isWritable'
com/rubyeventmachine/EmReactor.java:200:in `processIO'
com/rubyeventmachine/EmReactor.java:110:in `run'
/Users/uwe/workspace/aifudis/aifudis.admin/platform/jruby-1.4.0RC3/lib/ruby/gems/1.8/gems/eventmachine-0.12.10-java/lib/jeventmachine.rb:112:in `run_machine'
/Users/uwe/workspace/aifudis/aifudis.admin/platform/jruby-1.4.0RC3/lib/ruby/gems/1.8/gems/eventmachine-0.12.10-java/lib/eventmachine.rb:261:in `run'

It seems LinkedList?<ByteBuffer?> outboundQ.getFirst() returns NULL, and this is not handled. Maybe a threading issue?

threads cease being scheduled correctly if you run out of file descriptors on OS X (from Trac)

Moved from Trac

It appears that, on OS X, if you ever use all available file descriptors and are multi-threaded, it is possible that either the thread running EM or another thread will never be scheduled again, causing you to think "why isn't EM running anymore??". This might well be a Ruby bug where it doesn't handle certain edge cases in OS X with select. I think I may have run into something possibly related before. Fix for now: use linux.

vaguely related problem may be that ruby itself freezes on OS X, at times [1]

A way to recreate this is the tests in http://rubyeventmachine.com/ticket/34

[1]http://www.ruby-forum.com/topic/153559

06/30/08 20:22:42 changed by raggi

Hmm, this may have been reported as a similar problem under epoll. Might be worth checking the logic around the event apis.

Modified LineAndTextProtocol to accept custom delimiters in the constructor (from Trac)

Moved from Trac

Reported by: cremes Assigned to:
Priority: minor Milestone: EventMachine "Framework"
Keywords: protocol delimiter Cc:
Description ¶

LineAndTextProtocol? had a hardcoded delimiter of "\n" (newline). Made a small modification to its constructor so it can accept a custom delimiter passed in a hash with key :delimiter.

Please pull the changes from my github fork (chuckremes/eventmachine).

05/08/09 19:58:02 changed by cremes ¶

Oh, and I included a test for it too.
05/14/09 23:44:30 changed by cremes ¶

Corrected the patch so that newlines "\n" are retained when the delimiter is different. The original behavior always stripped newlines which may not be correct behavior even in a line and text protocol when overriding the delimiter.

Included a test case as well.

EM::open_keyboard is line-buffered (from Trac)

Moved from Trac

KEYBOARD suggests that it should not be line-buffered by default, and that you should use EM::P::LineText?2 w/ receive_line for line-buffered access

03/17/09 02:07:41 changed by careo

This isn't strictly true. The problem is with the terminal settings on stdin. You can work around it one of two ways.

The first is shell out to stty like this:

save current terminal state and set terminal to "raw" mode

$terminal_state = stty -g
system "stty raw -echo"

use $stdin

restore terminal settings.

system "stty #{$terminal_state}"

That works, but feels like cheating (to me at least). You can do the same using the Termios library:

require 'termios'

save current terminal state and set terminal to "raw" mode

$terminal_state = Termios.getattr $stdin
new_settings = $terminal_state.dup
new_settings.c_lflag &= ~(Termios::ECHO | Termios::ICANON)
new_settings.c_cc[Termios::VMIN] = 1
Termios.setattr $stdin, Termios::TCSANOW, new_settings

use $stdin

restore terminal settings.

Termios.setattr($stdin, Termios::TCSANOW, $terminal_state)

Note that either way will give you every character, including C and friends, and that it will really hose the user's terminal if you exit without restoring the terminal settings.

0.12.10 with thin hangs (windows)

Using thin 1.2.5 (any version, really), the server starts and accepts connections but does not process requests. Downgrading to eventmachine 0.12.8 fixes the problem.

Testing with wget seems to work on 0.12.10 but a webbrowser does not, so I imagine the problem is only visible if you keep the connection fully open after making a request.

SmtpServer rejects valid MAIL FROM command (from Trac)

Moved from Trac

Quoting rfc 2821:

The MAIL command (or the obsolete SEND, SOML, or SAML commands)
begins a mail transaction. Once started, a mail transaction consists
of a transaction beginning command, one or more RCPT commands, and a
DATA command, in that order. A mail transaction may be aborted by
the RSET (or a new EHLO) command. There may be zero or more
transactions in a session. MAIL (or SEND, SOML, or SAML) MUST NOT be
sent if a mail transaction is already open, i.e., it should be sent
only if no mail transaction had been started in the session, or it
the previous one successfully concluded with a successful DATA
command, or if the previous one was aborted with a RSET.

SmtpServer#process_mail_from? currently violates the last paragraph, rejecting a second MAIL FROM command even after DATA succeded.

EM limited to 256 file descriptors in windows (from Trac)

Moved from Trac

10/08/08 12:53:42 changed by rogerdpack

IOCP overcomes it as well [though apparently it's hard to use IOCP as evented--it is possible--google "libevent IOCP"
12/03/08 09:51:18 changed by rogerdpack

the 256 limit may be caused by the use of msvcrt6 in the back.

Apparently possible to overcome by redefining FD_SETSIZE to be large.

Random failures when sending out lots of requests (using em-http) (from Trac)

Moved from Trac

When sending out many em-http requests at the same time (i.e. in the same EM tick) some of those requests return an errback without any apparent cause.

Tested this on Linux (Ubuntu 8.10 and Debian unstable)

The number of requests is less than the per-user limit (1024 on my machine), yet they still fail. The failure happens both on localhost, 127.0.0.1 and any other site out there (e.g. google.com).

Throttling the number of requests by sending out one per EM tick is fixing the problem entirely when i try localhost, but when trying other sites there are still failures (less, but still some).

A script showing the unthrottled behaviour is at http://gist.github.com/82287 I always have failures running it with --url=http://www.google.com/ --reqs=1000

03/20/09 05:03:38 changed by tmm1 ¶

Happens with and without epoll. Using strace makes it both faster and the errors go away:

aman@pluto:~$ ruby testhttp.rb --url http://amazon.com/ --reqs 1000
I, [2009-03-20T01:51:59.167738 #15821] INFO -- : All done: 997 ok, 3 failed, 0 conn-err. Elapsed: 8.154226

aman@pluto:~$ ruby testhttp.rb --url http://amazon.com/ --reqs 1000
I, [2009-03-20T01:52:23.156699 #15843] INFO -- : All done: 861 ok, 139 failed, 0 conn-err. Elapsed: 7.484148

aman@pluto:~$ strace -ttTo /tmp/http.strace ruby testhttp.rb --url http://amazon.com/ --reqs 1000
I, [2009-03-20T01:52:51.166085 #15852] INFO -- : All done: 1000 ok, 0 failed, 0 conn-err. Elapsed: 3.403963

Key collision bug in installOneshotTimer in JRuby Reactor causes timers to be overwritten (from Trac)

Moved from Trac

Reported by: cturner Assigned to:
Priority: major Milestone: Java/JRuby support
Keywords: timer key collision Cc:
Description ¶

Timers in the JRuby reactor are stored in a TreeMap? keyed by epoch time in milliseconds. If timer A is added at the same time timerB is scheduled to fire, timer B will be overwritten. The attached script (periodictimers.rb) typically loses timerB within 30m of starting it. Often earlier.

Keying the Timers TreeMap? on the scheduled firing time is efficient as it saves us from iterating over the entire structure to find the next scheduled timer. Rather than changing the TreeMap? key, I changed the TreeMap? value from a String to a TreeSet?. If a timer is added at the same time another is scheduled it is added to the existing TreeSet?.

I've run this code for several days without losing a timer. Java is not my first language so it's likely there's a better way to implement this, I just don't know what it is. Patch is attached.

05/23/09 23:24:09 changed by cturner

* attachment periodictimers.rb added.

run this under jruby for awhile. timer2 will disappear.
05/23/09 23:25:21 changed by cturner

* attachment EmReactor.patch added.

patch against 0.12.8
05/23/09 23:26:13 changed by cturner ¶

i should've noted - this patch was generated against eventmachine 0.12.8

http://rubyeventmachine.com/attachment/ticket/127/periodictimers.rb
http://rubyeventmachine.com/attachment/ticket/127/EmReactor.patch

eventmachine integer ... too big to convert

I get an error when I try to run my EventMachine-based Ruby Daemon:

/Library/Ruby/Gems/1.8/gems/eventmachine-0.12.8/lib/eventmachine.rb:242:in `receive_data': integer 4306228224 too big to convert to `int' (RangeError)
from /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.8/lib/eventmachine.rb:242:in `run_machine'
from /Library/Ruby/Gems/1.8/gems/eventmachine-0.12.8/lib/eventmachine.rb:242:in `run'
from bin/live.rb:13

Any ideas on how to fix it?

EM.set_sock_opt support

Feature request: Could you support set_sock_opt in EM?

Since I find the get_sock_opt method has been added to master, it seems legitimate to ask. :)

Here's the background: I'm implementing a STUN server as well as online gaming backend using EM, and we need to initiate a direct p2p punch-through session via UDP. In the development, we realized that some sort of NATs have stateful packet inspection (SPI) that blocks IPs for a while that sent an illegitimate packet to the NAT, rendering the whole idea of UDP hole punching moot. To avoid that, we needed to shoot a short-lived UDP packet (TTL=2 or 3) just to pass the local side of NAT (it should be gone before reaching to the other end's NAT), and then continue to the punched, normal p2p session (TTL=64 or 256, whatever). It actually works well.

We did something similar to the following:


socket = UDPSocket.new
socket.setsockopt(Socket::IPPROTO_IP, Socket::IP_TTL, [3].pack("i"))
3.times{|i|
 sleep(0.1)
 udp.send("short jab",ip,port)
}
sleep(1)
socket.setsockopt(Socket::IPPROTO_IP, Socket::IP_TTL, [128].pack("i"))
50.times {|i|
 sleep(0.1)
 udp.send("long smash",ip,port)
}

I'd be happy if I could do the same using EM's datagram socket.
Thanks.

EM.defer threadpool should set abort_on_exception (from Trac)

Moved from Trac

Reported by: tmm1 Assigned to: raggi francis
Priority: major Milestone: EventMachine "Framework"
Keywords: Cc:
Description ¶

Instead of silently swallowing errors..

Thread.abort_on_exception = true

01/27/09 20:11:25 changed by raggi ¶

I think this requires a design fix, app authors should do this for now.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.