eventmachine 0.12.10-x86-mswin32-60 → 1.0.0.beta.2-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/Gemfile +1 -0
- data/README +80 -81
- data/Rakefile +7 -370
- data/docs/COPYING +60 -60
- data/docs/ChangeLog +211 -211
- data/docs/DEFERRABLES +246 -133
- data/docs/EPOLL +141 -141
- data/docs/GNU +281 -281
- data/docs/INSTALL +13 -13
- data/docs/KEYBOARD +42 -38
- data/docs/LEGAL +25 -25
- data/docs/LIGHTWEIGHT_CONCURRENCY +130 -70
- data/docs/PURE_RUBY +75 -75
- data/docs/RELEASE_NOTES +94 -94
- data/docs/SMTP +4 -2
- data/docs/SPAWNED_PROCESSES +148 -89
- data/docs/TODO +8 -8
- data/eventmachine.gemspec +19 -26
- data/examples/ex_channel.rb +42 -42
- data/examples/ex_queue.rb +2 -2
- data/examples/ex_tick_loop_array.rb +15 -0
- data/examples/ex_tick_loop_counter.rb +32 -0
- data/examples/helper.rb +1 -1
- data/ext/binder.cpp +0 -1
- data/ext/cmain.cpp +36 -25
- data/ext/ed.cpp +104 -113
- data/ext/ed.h +24 -30
- data/ext/em.cpp +349 -283
- data/ext/em.h +25 -29
- data/ext/eventmachine.h +5 -4
- data/ext/extconf.rb +58 -49
- data/ext/fastfilereader/extconf.rb +5 -3
- data/ext/fastfilereader/mapper.cpp +214 -214
- data/ext/fastfilereader/mapper.h +59 -59
- data/ext/fastfilereader/rubymain.cpp +127 -127
- data/ext/kb.cpp +1 -3
- data/ext/page.cpp +107 -107
- data/ext/page.h +51 -51
- data/ext/pipe.cpp +9 -11
- data/ext/project.h +12 -8
- data/ext/rubymain.cpp +138 -104
- data/java/.classpath +8 -8
- data/java/.project +17 -17
- data/java/src/com/rubyeventmachine/EmReactor.java +1 -0
- data/java/src/com/rubyeventmachine/EmReactorException.java +40 -40
- data/lib/em/buftok.rb +138 -138
- data/lib/em/callback.rb +25 -25
- data/lib/em/channel.rb +1 -1
- data/lib/em/connection.rb +6 -1
- data/lib/em/deferrable.rb +16 -2
- data/lib/em/file_watch.rb +53 -53
- data/lib/em/future.rb +61 -61
- data/lib/em/iterator.rb +270 -0
- data/lib/em/messages.rb +66 -66
- data/lib/em/process_watch.rb +43 -43
- data/lib/em/protocols.rb +1 -1
- data/lib/em/protocols/header_and_content.rb +138 -138
- data/lib/em/protocols/httpclient.rb +267 -262
- data/lib/em/protocols/line_protocol.rb +28 -0
- data/lib/em/protocols/memcache.rb +322 -322
- data/lib/em/protocols/postgres3.rb +247 -247
- data/lib/em/protocols/saslauth.rb +175 -175
- data/lib/em/protocols/smtpserver.rb +640 -547
- data/lib/em/protocols/stomp.rb +200 -200
- data/lib/em/protocols/tcptest.rb +52 -52
- data/lib/{pr_eventmachine.rb → em/pure_ruby.rb} +1013 -1022
- data/lib/em/queue.rb +1 -0
- data/lib/em/spawnable.rb +85 -85
- data/lib/em/streamer.rb +130 -130
- data/lib/em/tick_loop.rb +85 -0
- data/lib/em/timers.rb +2 -1
- data/lib/em/version.rb +1 -1
- data/lib/eventmachine.rb +40 -84
- data/lib/jeventmachine.rb +2 -1
- data/lib/rubyeventmachine.rb +2 -0
- data/setup.rb +1585 -1585
- data/tasks/doc.rake +30 -0
- data/tasks/package.rake +85 -0
- data/tasks/test.rake +6 -0
- data/tests/client.crt +31 -31
- data/tests/client.key +51 -51
- data/tests/test_attach.rb +13 -3
- data/tests/test_basic.rb +60 -95
- data/tests/test_channel.rb +3 -2
- data/tests/test_defer.rb +49 -47
- data/tests/test_deferrable.rb +35 -0
- data/tests/test_error_handler.rb +35 -35
- data/tests/test_errors.rb +82 -82
- data/tests/test_exc.rb +55 -55
- data/tests/test_file_watch.rb +49 -49
- data/tests/test_futures.rb +198 -198
- data/tests/test_handler_check.rb +36 -36
- data/tests/test_hc.rb +190 -218
- data/tests/test_httpclient.rb +227 -218
- data/tests/test_httpclient2.rb +3 -2
- data/tests/test_inactivity_timeout.rb +3 -3
- data/tests/test_kb.rb +60 -60
- data/tests/test_ltp.rb +13 -5
- data/tests/test_ltp2.rb +317 -317
- data/tests/test_next_tick.rb +1 -1
- data/tests/test_object_protocol.rb +36 -36
- data/tests/test_pending_connect_timeout.rb +2 -2
- data/tests/test_process_watch.rb +50 -48
- data/tests/test_proxy_connection.rb +52 -0
- data/tests/test_pure.rb +134 -125
- data/tests/test_queue.rb +44 -44
- data/tests/test_running.rb +42 -42
- data/tests/test_sasl.rb +72 -72
- data/tests/test_send_file.rb +251 -242
- data/tests/test_servers.rb +76 -76
- data/tests/test_smtpclient.rb +83 -83
- data/tests/test_smtpserver.rb +85 -85
- data/tests/test_spawn.rb +322 -322
- data/tests/test_ssl_methods.rb +49 -49
- data/tests/test_ssl_verify.rb +82 -82
- data/tests/test_tick_loop.rb +59 -0
- data/tests/test_timers.rb +13 -15
- data/tests/test_ud.rb +36 -36
- data/tests/testem.rb +31 -31
- metadata +66 -51
- data/ext/cplusplus.cpp +0 -202
- data/ext/emwin.cpp +0 -300
- data/ext/emwin.h +0 -94
- data/ext/epoll.cpp +0 -26
- data/ext/epoll.h +0 -25
- data/ext/eventmachine_cpp.h +0 -96
- data/ext/files.cpp +0 -94
- data/ext/files.h +0 -65
- data/ext/sigs.cpp +0 -89
- data/ext/sigs.h +0 -32
- data/java/src/com/rubyeventmachine/application/Application.java +0 -194
- data/java/src/com/rubyeventmachine/application/Connection.java +0 -74
- data/java/src/com/rubyeventmachine/application/ConnectionFactory.java +0 -37
- data/java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java +0 -46
- data/java/src/com/rubyeventmachine/application/PeriodicTimer.java +0 -38
- data/java/src/com/rubyeventmachine/application/Timer.java +0 -54
- data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +0 -109
- data/java/src/com/rubyeventmachine/tests/ConnectTest.java +0 -148
- data/java/src/com/rubyeventmachine/tests/EMTest.java +0 -80
- data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +0 -53
- data/java/src/com/rubyeventmachine/tests/TestServers.java +0 -75
- data/java/src/com/rubyeventmachine/tests/TestTimers.java +0 -90
- data/lib/evma.rb +0 -32
- data/lib/evma/callback.rb +0 -32
- data/lib/evma/container.rb +0 -75
- data/lib/evma/factory.rb +0 -77
- data/lib/evma/protocol.rb +0 -87
- data/lib/evma/reactor.rb +0 -48
- data/web/whatis +0 -7
data/docs/INSTALL
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
If you have obtained an EventMachine source-tarball (.tar.gz):
|
2
|
-
unzip and untar the tarball, and enter the directory that is
|
3
|
-
created. In that directory, say:
|
4
|
-
ruby setup.rb
|
5
|
-
(You may need to be root to execute this command.)
|
6
|
-
|
7
|
-
To create documentation for EventMachine, simply type:
|
8
|
-
rake rdoc
|
9
|
-
in the distro directory. Rdocs will be created in subdirectory rdoc.
|
10
|
-
|
11
|
-
If you have obtained a gem version of EventMachine, install it in the
|
12
|
-
usual way (gem install eventmachine). You may need superuser privileges
|
13
|
-
to execute this command.
|
1
|
+
If you have obtained an EventMachine source-tarball (.tar.gz):
|
2
|
+
unzip and untar the tarball, and enter the directory that is
|
3
|
+
created. In that directory, say:
|
4
|
+
ruby setup.rb
|
5
|
+
(You may need to be root to execute this command.)
|
6
|
+
|
7
|
+
To create documentation for EventMachine, simply type:
|
8
|
+
rake rdoc
|
9
|
+
in the distro directory. Rdocs will be created in subdirectory rdoc.
|
10
|
+
|
11
|
+
If you have obtained a gem version of EventMachine, install it in the
|
12
|
+
usual way (gem install eventmachine). You may need superuser privileges
|
13
|
+
to execute this command.
|
data/docs/KEYBOARD
CHANGED
@@ -1,38 +1,42 @@
|
|
1
|
-
EventMachine (EM) can respond to keyboard events. This gives your event-driven
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
require '
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
1
|
+
EventMachine (EM) can respond to keyboard events. This gives your event-driven
|
2
|
+
programs the ability to respond to input from local users.
|
3
|
+
|
4
|
+
Programming EM to handle keyboard input in Ruby is simplicity itself. Just use
|
5
|
+
EventMachine#open_keyboard, and supply the name of a Ruby module or class that
|
6
|
+
will receive the input:
|
7
|
+
|
8
|
+
require 'rubygems'
|
9
|
+
require 'eventmachine'
|
10
|
+
|
11
|
+
module MyKeyboardHandler
|
12
|
+
def receive_data keystrokes
|
13
|
+
puts "I received the following data from the keyboard: #{keystrokes}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
EM.run {
|
18
|
+
EM.open_keyboard(MyKeyboardHandler)
|
19
|
+
}
|
20
|
+
|
21
|
+
If you want EM to send line-buffered keyboard input to your program, just
|
22
|
+
include the LineText2 protocol module in your handler class or module:
|
23
|
+
|
24
|
+
require 'rubygems'
|
25
|
+
require 'eventmachine'
|
26
|
+
|
27
|
+
module MyKeyboardHandler
|
28
|
+
include EM::Protocols::LineText2
|
29
|
+
def receive_line data
|
30
|
+
puts "I received the following line from the keyboard: #{data}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
EM.run {
|
35
|
+
EM.open_keyboard(MyKeyboardHandler)
|
36
|
+
}
|
37
|
+
|
38
|
+
As we said, simplicity itself. You can call EventMachine#open_keyboard at any
|
39
|
+
time while the EM reactor loop is running. In other words, the method
|
40
|
+
invocation may appear anywhere in an EventMachine#run block, or in any code
|
41
|
+
invoked in the #run block.
|
42
|
+
|
data/docs/LEGAL
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
LEGAL NOTICE INFORMATION
|
2
|
-
------------------------
|
3
|
-
|
4
|
-
EventMachine is Copyright (C) 2006-07 by Francis Cianfrocca.
|
5
|
-
|
6
|
-
EventMachine is copyrighted software owned by Francis Cianfrocca
|
7
|
-
(blackhedd ... gmail.com). You may redistribute and/or modify this
|
8
|
-
software as long as you comply with either the terms of the GPL
|
9
|
-
(see the file GPL), or Ruby's license (see the file COPYING).
|
10
|
-
|
11
|
-
Your use of all the files in this distribution is controlled by these
|
12
|
-
license terms, except for those files specifically mentioned below:
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
setup.rb
|
17
|
-
This file is Copyright (C) 2000-2005 by Minero Aoki
|
18
|
-
You can distribute/modify this file under the terms of
|
19
|
-
the GNU LGPL, Lesser General Public License version 2.1.
|
20
|
-
|
21
|
-
|
22
|
-
lib/em/buftok.rb
|
23
|
-
This file is Copyright (C) 2007 by Tony Arcieri. This file is
|
24
|
-
covered by the terms of Ruby's License (see the file COPYING).
|
25
|
-
|
1
|
+
LEGAL NOTICE INFORMATION
|
2
|
+
------------------------
|
3
|
+
|
4
|
+
EventMachine is Copyright (C) 2006-07 by Francis Cianfrocca.
|
5
|
+
|
6
|
+
EventMachine is copyrighted software owned by Francis Cianfrocca
|
7
|
+
(blackhedd ... gmail.com). You may redistribute and/or modify this
|
8
|
+
software as long as you comply with either the terms of the GPL
|
9
|
+
(see the file GPL), or Ruby's license (see the file COPYING).
|
10
|
+
|
11
|
+
Your use of all the files in this distribution is controlled by these
|
12
|
+
license terms, except for those files specifically mentioned below:
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
setup.rb
|
17
|
+
This file is Copyright (C) 2000-2005 by Minero Aoki
|
18
|
+
You can distribute/modify this file under the terms of
|
19
|
+
the GNU LGPL, Lesser General Public License version 2.1.
|
20
|
+
|
21
|
+
|
22
|
+
lib/em/buftok.rb
|
23
|
+
This file is Copyright (C) 2007 by Tony Arcieri. This file is
|
24
|
+
covered by the terms of Ruby's License (see the file COPYING).
|
25
|
+
|
@@ -1,70 +1,130 @@
|
|
1
|
-
EventMachine (EM) adds two different formalisms for lightweight concurrency to
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
1
|
+
EventMachine (EM) adds two different formalisms for lightweight concurrency to
|
2
|
+
the Ruby programmer's toolbox: spawned processes and deferrables. This note
|
3
|
+
will show you how to use them.
|
4
|
+
|
5
|
+
|
6
|
+
=== What is Lightweight Concurrency?
|
7
|
+
|
8
|
+
We use the term "Lightweight Concurrency" (LC) to refer to concurrency
|
9
|
+
mechanisms that are lighter than Ruby threads. By "lighter," we mean: less
|
10
|
+
resource-intensive in one or more dimensions, usually including memory and
|
11
|
+
CPU usage. In general, you turn to LC in the hope of improving the
|
12
|
+
performance and scalability of your programs.
|
13
|
+
|
14
|
+
In addition to the two EventMachine mechanisms we will discuss here, Ruby
|
15
|
+
has at least one other LC construct: Fibers, which are currently under
|
16
|
+
development in Ruby 1.9.
|
17
|
+
|
18
|
+
The technical feature that makes all of these LC mechanisms different from
|
19
|
+
standard Ruby threads is that they are not scheduled automatically.
|
20
|
+
|
21
|
+
When you create and run Ruby threads, you can assume (within certain
|
22
|
+
constraints) that your threads will all be scheduled fairly by Ruby's runtime.
|
23
|
+
Ruby itself is responsible for giving each of your threads its own share of
|
24
|
+
the total runtime.
|
25
|
+
|
26
|
+
But with LC, your program is responsible for causing different execution
|
27
|
+
paths to run. In effect, your program has to act as a "thread scheduler."
|
28
|
+
Scheduled entities in LC run to completion and are never preempted. The
|
29
|
+
runtime system has far less work to do since it has no need to interrupt
|
30
|
+
threads or to schedule them fairly. This is what makes LC lighter and faster.
|
31
|
+
|
32
|
+
You'll learn exactly how LC scheduling works in practice as we work through
|
33
|
+
specific examples.
|
34
|
+
|
35
|
+
|
36
|
+
=== EventMachine Lightweight Concurrency
|
37
|
+
|
38
|
+
Recall that EM provides a reactor loop that must be running in order for
|
39
|
+
your programs to perform event-driven logic. An EM program typically has a
|
40
|
+
structure like this:
|
41
|
+
|
42
|
+
require 'eventmachine'
|
43
|
+
|
44
|
+
# your initializations
|
45
|
+
|
46
|
+
EM.run {
|
47
|
+
# perform event-driven I/O here, including network clients,
|
48
|
+
# servers, timers, and thread-pool operations.
|
49
|
+
}
|
50
|
+
|
51
|
+
# your cleanup
|
52
|
+
# end of the program
|
53
|
+
|
54
|
+
|
55
|
+
EventMachine#run executes the reactor loop, which causes your code to be
|
56
|
+
called as events of interest to your program occur. The block you pass to
|
57
|
+
EventMachine#run is executed right after the reactor loop starts, and is
|
58
|
+
the right place to start socket acceptors, etc.
|
59
|
+
|
60
|
+
Because the reactor loop runs constantly in an EM program (until it is
|
61
|
+
stopped by a call to EventMachine#stop), it has the ability to schedule
|
62
|
+
blocks of code for asynchronous execution. Unlike a pre-emptive thread
|
63
|
+
scheduler, it's NOT able to interrupt code blocks while they execute. But
|
64
|
+
the scheduling capability it does have is enough to enable lightweight
|
65
|
+
concurrency.
|
66
|
+
|
67
|
+
|
68
|
+
For information on Spawned Processes, see the separate document
|
69
|
+
SPAWNED_PROCESSES.
|
70
|
+
|
71
|
+
For information on Deferrables, see the separate document DEFERRABLES.
|
72
|
+
|
73
|
+
|
74
|
+
=== [SIDEBAR]: I Heard That EventMachine Doesn't Work With Ruby Threads.
|
75
|
+
|
76
|
+
This is incorrect. EM is fully interoperable with all versions of Ruby
|
77
|
+
threads, and has been since its earliest releases.
|
78
|
+
|
79
|
+
It's very true that EM encourages an "evented" (non-threaded) programming
|
80
|
+
style. The specific benefits of event-driven programming are far better
|
81
|
+
performance and scalability for well-written programs, and far easier
|
82
|
+
debugging.
|
83
|
+
|
84
|
+
The benefit of using threads for similar applications is a possibly more
|
85
|
+
intuitive programming model, as well as the fact that threads are already
|
86
|
+
familiar to most programmers. Also, bugs in threaded programs often fail
|
87
|
+
to show up until programs go into production. These factors create the
|
88
|
+
illusion that threaded programs are easier to write.
|
89
|
+
|
90
|
+
However, some operations that occur frequently in professional-caliber
|
91
|
+
applications simply can't be done without threads. (The classic example
|
92
|
+
is making calls to database client-libraries that block on network I/O
|
93
|
+
until they complete.)
|
94
|
+
|
95
|
+
EventMachine not only allows the use of Ruby threads in these cases, but
|
96
|
+
it even provides a built-in thread-pool object to make them easier to
|
97
|
+
work with.
|
98
|
+
|
99
|
+
You may have heard a persistent criticism that evented I/O is fundamentally
|
100
|
+
incompatible with Ruby threads. It is true that some well-publicized attempts
|
101
|
+
to incorporate event-handling libraries into Ruby were not successful. But
|
102
|
+
EventMachine was designed from the ground up with Ruby compatibility in mind,
|
103
|
+
so EM never suffered from the problems that defeated the earlier attempts.
|
104
|
+
|
105
|
+
|
106
|
+
=== [SIDEBAR]: I Heard That EventMachine Doesn't Work Very Well On Windows.
|
107
|
+
|
108
|
+
This too is incorrect. EventMachine is an extension written in C++ and Java,
|
109
|
+
and therefore it requires compilation. Many Windows computers (and some Unix
|
110
|
+
computers, especially in production environments) don't have a build stack.
|
111
|
+
Attempting to install EventMachine on a machine without a compiler usually
|
112
|
+
produces a confusing error.
|
113
|
+
|
114
|
+
In addition, Ruby has a much-debated issue with Windows compiler versions.
|
115
|
+
Ruby on Windows works best with Visual Studio 6, a compiler version that is
|
116
|
+
long out-of-print, no longer supported by Microsoft, and difficult to obtain.
|
117
|
+
(This problem is not specific to EventMachine.)
|
118
|
+
|
119
|
+
Shortly after EventMachine was first released, the compiler issues led to
|
120
|
+
criticism that EM was incompatible with Windows. Since that time, every
|
121
|
+
EventMachine release has been supplied in a precompiled binary form for
|
122
|
+
Windows users, that does not require you to compile the code yourself. EM
|
123
|
+
binary Gems for Windows are compiled using Visual Studio 6.
|
124
|
+
|
125
|
+
EventMachine does supply some advanced features (such as Linux EPOLL support,
|
126
|
+
reduced-privilege operation, UNIX-domain sockets, etc.) that have no
|
127
|
+
meaningful implementation on Windows. Apart from these special cases, all EM
|
128
|
+
functionality (including lightweight concurrency) works perfectly well on
|
129
|
+
Windows.
|
130
|
+
|
data/docs/PURE_RUBY
CHANGED
@@ -1,75 +1,75 @@
|
|
1
|
-
EventMachine is supplied in three alternative versions.
|
2
|
-
|
3
|
-
1) A version that includes a Ruby extension written in C++. This version requires compilation;
|
4
|
-
2) A version for JRuby that contains a precompiled JAR file written in Java;
|
5
|
-
3) A pure Ruby version that has no external dependencies and can run in any Ruby environment.
|
6
|
-
|
7
|
-
The Java version of EventMachine is packaged in a distinct manner and must be installed using a
|
8
|
-
special procedure. This version is described fully in a different document, and not considered
|
9
|
-
further here.
|
10
|
-
|
11
|
-
The C++ and pure-Ruby versions, however, are shipped in the same distribution. You use the same
|
12
|
-
files (either tarball or Ruby gem) to install both of these versions.
|
13
|
-
|
14
|
-
If you intend to use the C++ version, you must successfully compile EventMachine after you install it.
|
15
|
-
(The gem installation attempts to perform this step automatically.)
|
16
|
-
|
17
|
-
If you choose not to compile the EventMachine C++ extension, or if your compilation fails for any
|
18
|
-
reason, you still have a fully-functional installation of the pure-Ruby version of EM.
|
19
|
-
|
20
|
-
However, for technical reasons, a default EM installation (whether or not the compilation succeeds)
|
21
|
-
will always assume that the compiled ("extension") implementation should be used.
|
22
|
-
|
23
|
-
If you want your EM program to use the pure Ruby version, you must specifically request it. There
|
24
|
-
are two ways to do this: by setting either a Ruby global variable, or an environment string.
|
25
|
-
|
26
|
-
The following code will invoke the pure-Ruby implementation of EM:
|
27
|
-
|
28
|
-
$eventmachine_library = :pure_ruby
|
29
|
-
require 'eventmachine'
|
30
|
-
|
31
|
-
EM.library_type #=> "pure_ruby"
|
32
|
-
|
33
|
-
Notice that this requires a code change and is not the preferred way to select pure Ruby, unless
|
34
|
-
for some reason you are absolutely sure you will never want the compiled implementation.
|
35
|
-
|
36
|
-
Setting the following environment string has the same effect:
|
37
|
-
|
38
|
-
export EVENTMACHINE_LIBRARY="pure_ruby"
|
39
|
-
|
40
|
-
This technique gives you the flexibility to select either version at runtime with no code changes.
|
41
|
-
|
42
|
-
Support
|
43
|
-
|
44
|
-
The EventMachine development team has committed to support precisely the same APIs for all the
|
45
|
-
various implementations of EM.
|
46
|
-
|
47
|
-
This means that you can expect any EM program to behave identically, whether you use pure Ruby,
|
48
|
-
the compiled C++ extension, or JRuby. Deviations from this behavior are to be considered bugs
|
49
|
-
and should be reported as such.
|
50
|
-
|
51
|
-
There is a small number of exceptions to this rule, which arise from underlying platform
|
52
|
-
distinctions. Notably, EM#epoll is a silent no-op in the pure Ruby implementation.
|
53
|
-
|
54
|
-
|
55
|
-
When Should You Use the Pure-Ruby Implementation of EM?
|
56
|
-
|
57
|
-
|
58
|
-
Use the pure Ruby implementation of EM when you must support a platform for which no C++ compiler
|
59
|
-
is available, or on which the standard EM C++ code can't be compiled.
|
60
|
-
|
61
|
-
Keep in mind that you don't need a C++ compiler in order to deploy EM applications that rely on
|
62
|
-
the compiled version, so long as appropriate C++ runtime libraries are available on the target platform.
|
63
|
-
|
64
|
-
In extreme cases, you may find that you can develop software with the compiled EM version, but are
|
65
|
-
not allowed to install required runtime libraries on the deployment system(s). This would be another
|
66
|
-
case in which the pure Ruby implementation can be useful.
|
67
|
-
|
68
|
-
In general you should avoid the pure Ruby version of EM when performance and scalability are important.
|
69
|
-
EM in pure Ruby will necessarily run slower than the compiled version. Depending on your application
|
70
|
-
this may or may not be a key issue.
|
71
|
-
|
72
|
-
Also, since EPOLL is not supported in pure Ruby, your applications will be affected by Ruby's built-in
|
73
|
-
limit of 1024 file and socket descriptors that may be open in a single process. For maximum scalability
|
74
|
-
and performance, always use EPOLL if possible.
|
75
|
-
|
1
|
+
EventMachine is supplied in three alternative versions.
|
2
|
+
|
3
|
+
1) A version that includes a Ruby extension written in C++. This version requires compilation;
|
4
|
+
2) A version for JRuby that contains a precompiled JAR file written in Java;
|
5
|
+
3) A pure Ruby version that has no external dependencies and can run in any Ruby environment.
|
6
|
+
|
7
|
+
The Java version of EventMachine is packaged in a distinct manner and must be installed using a
|
8
|
+
special procedure. This version is described fully in a different document, and not considered
|
9
|
+
further here.
|
10
|
+
|
11
|
+
The C++ and pure-Ruby versions, however, are shipped in the same distribution. You use the same
|
12
|
+
files (either tarball or Ruby gem) to install both of these versions.
|
13
|
+
|
14
|
+
If you intend to use the C++ version, you must successfully compile EventMachine after you install it.
|
15
|
+
(The gem installation attempts to perform this step automatically.)
|
16
|
+
|
17
|
+
If you choose not to compile the EventMachine C++ extension, or if your compilation fails for any
|
18
|
+
reason, you still have a fully-functional installation of the pure-Ruby version of EM.
|
19
|
+
|
20
|
+
However, for technical reasons, a default EM installation (whether or not the compilation succeeds)
|
21
|
+
will always assume that the compiled ("extension") implementation should be used.
|
22
|
+
|
23
|
+
If you want your EM program to use the pure Ruby version, you must specifically request it. There
|
24
|
+
are two ways to do this: by setting either a Ruby global variable, or an environment string.
|
25
|
+
|
26
|
+
The following code will invoke the pure-Ruby implementation of EM:
|
27
|
+
|
28
|
+
$eventmachine_library = :pure_ruby
|
29
|
+
require 'eventmachine'
|
30
|
+
|
31
|
+
EM.library_type #=> "pure_ruby"
|
32
|
+
|
33
|
+
Notice that this requires a code change and is not the preferred way to select pure Ruby, unless
|
34
|
+
for some reason you are absolutely sure you will never want the compiled implementation.
|
35
|
+
|
36
|
+
Setting the following environment string has the same effect:
|
37
|
+
|
38
|
+
export EVENTMACHINE_LIBRARY="pure_ruby"
|
39
|
+
|
40
|
+
This technique gives you the flexibility to select either version at runtime with no code changes.
|
41
|
+
|
42
|
+
Support
|
43
|
+
|
44
|
+
The EventMachine development team has committed to support precisely the same APIs for all the
|
45
|
+
various implementations of EM.
|
46
|
+
|
47
|
+
This means that you can expect any EM program to behave identically, whether you use pure Ruby,
|
48
|
+
the compiled C++ extension, or JRuby. Deviations from this behavior are to be considered bugs
|
49
|
+
and should be reported as such.
|
50
|
+
|
51
|
+
There is a small number of exceptions to this rule, which arise from underlying platform
|
52
|
+
distinctions. Notably, EM#epoll is a silent no-op in the pure Ruby implementation.
|
53
|
+
|
54
|
+
|
55
|
+
When Should You Use the Pure-Ruby Implementation of EM?
|
56
|
+
|
57
|
+
|
58
|
+
Use the pure Ruby implementation of EM when you must support a platform for which no C++ compiler
|
59
|
+
is available, or on which the standard EM C++ code can't be compiled.
|
60
|
+
|
61
|
+
Keep in mind that you don't need a C++ compiler in order to deploy EM applications that rely on
|
62
|
+
the compiled version, so long as appropriate C++ runtime libraries are available on the target platform.
|
63
|
+
|
64
|
+
In extreme cases, you may find that you can develop software with the compiled EM version, but are
|
65
|
+
not allowed to install required runtime libraries on the deployment system(s). This would be another
|
66
|
+
case in which the pure Ruby implementation can be useful.
|
67
|
+
|
68
|
+
In general you should avoid the pure Ruby version of EM when performance and scalability are important.
|
69
|
+
EM in pure Ruby will necessarily run slower than the compiled version. Depending on your application
|
70
|
+
this may or may not be a key issue.
|
71
|
+
|
72
|
+
Also, since EPOLL is not supported in pure Ruby, your applications will be affected by Ruby's built-in
|
73
|
+
limit of 1024 file and socket descriptors that may be open in a single process. For maximum scalability
|
74
|
+
and performance, always use EPOLL if possible.
|
75
|
+
|