You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
Scalable event-driven servers. Examples: Thin or Goliath.
Scalable asynchronous clients for various protocols, RESTful APIs and so on. Examples: em-http-request or amqp gem.
Efficient network proxies with custom logic. Examples: Proxymachine.
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).
Here's a fully-functional echo server written with EventMachine:
require'eventmachine'moduleEchoServerdefpost_initputs"-- someone connected to the echo server!"enddefreceive_datadatasend_data">>>you sent: #{data}"close_connectionifdata =~ /quit/ienddefunbindputs"-- someone disconnected from the echo server!"endend# Note that this will block current thread.EventMachine.run{EventMachine.start_server"127.0.0.1",8081,EchoServer}