about summary refs log tree commit homepage
path: root/lib/rainbows/event_machine.rb
DateCommit message (Collapse)
2017-01-09eventmachine: wait for deferred actions to finish em-deferred
Since EventMachine 1.0.0 in 2012, the EM.defers_finish? API exists to check for the existence of deferred actions. Support it if it exists in the running version of EM and update the note in our SIGNALS document. Thanks to <alex0375@gmail.com> on the mailing list for bringing this up: https://bogomips.org/rainbows-public/CAKwvcL-VH3we4qA1pkNAstTmWvqNA=Rir2N_YiWztV_qbaLQvA@mail.gmail.com/
2014-01-29event_machine: update for unicorn 4.8.x
unicorn 4.8.x shutdown handling is different and no longer removes items from the event loop. So we must do that ourselves to enable graceful shutdown. Otherwise, we'll time out on shutdowns and the master will forcibly kill us.
2013-01-11event_machine: join reactor_thread if it is already running
...rather than falling through worker_loop Prior to the application of this patch, if an EventMachine reactor_thread has already been started elsewhere before the worker_loop is entered, the worker_loop exits as a second call to EM.run does not block the current thread. This patch causes the worker_loop thread to join the reactor_thread if it is running. [ew: commit message formatting] Signed-off-by: Eric Wong <normalperson@yhbt.net>
2011-08-19event_machine: update rdoc for new Cramp homepage
Cramp has a homepage and mailing list now, yay!
2011-08-05event_machine: APP needs to be in the main Client class
Oops, testing against new changes against cramp.git here
2011-08-05event_machine: add :em_client_class option
This can allow Cramp (and potentially other libraries) to subclass or implement duck-type compatible versions of Rainbows::EventMachine::Client.
2011-05-21try_defer: enable documentation
It should hopefully give this more visibility even though it's an internal feature.
2011-05-20event_machine: disconnect idle clients at on SIGQUIT
Since it's cheap to maintain keepalive clients with EM, we need a way of disconnecting them in a timely fashion on rare SIGQUIT events.
2011-05-16document RubyGem requirements
Hopefully makes things easier to try out.
2011-01-20ev_core: simplify setup steps
ev_core is always loaded after forking, so eliminate the need for extra setup steps for each concurrency model that uses it
2011-01-06eliminate G constant and just use the Rainbows! module
Code organization is hard :<
2011-01-04globally refactor Range handling for responses
Rack::Utils::HeaderHash is still very expensive in Rack 1.2, especially for simple things that we want to run as fast as possible with minimal interference. HeaderHash is unnecessary for most requests that do not send Content-Range in responses.
2010-12-26event_machine: split out server and client classes
This should make things easier to find
2010-12-26rainbows/rev/* require/autoload cleanup
One line of code saved! We'll also avoid loading DeferredChunkResponse which is rarely needed (unlike DeferredResponse).
2010-12-26avoid HttpParser#keepalive? and HttpParser#reset
The HttpParser#next? method will come with keepalive protection for Rainbows!, which can prevent clients from monopolizing a server with excessive pipelining/keepalive requests.
2010-12-09respect client_body_buffer_size in Unicorn 3.1.0
This is only needed for concurrency options that do not use TeeInput, since TeeInput automatically handles this for us.
2010-10-28rev+event_machine: small cleanups with new parser API
These allow for small reductions in the amount of variables we have to manage, more changes coming with later Unicorns.
2010-10-22unindent most files
This simplifies and disambiguates most constant resolution issues as well as lowering our identation level. Hopefully this makes code easier to understand.
2010-09-28start using kgio library
It removes the burden of byte slicing and setting file descriptor flags. In some cases, we can remove unnecessary peeraddr calls, too.
2010-09-17event_machine: remove unnecessary "return"
Noise is bad.
2010-08-28"keepalive_timeout 0" (really) disables keepalive
Although this behavior is mentioned on the documentation, this was broken under EventMachine, Rev*, and Revactor. Furthermore, we set the "Connection: close" header to allow the client to optimize is handling of non-keepalive connections.
2010-08-26split out accept() callers to acceptor module
Trying to avoid adding singleton methods since it's too easily accessible by the public and not needed by the general public. This also allows us (or just Zbatery) to more easily add support systems without FD_CLOEXEC or fcntl, and also to optimize away a fcntl call for systems that inherit FD_CLOEXEC.
2010-08-02event_machine: protect IO#close from EBADF
EventMachine may close the underlying file descriptor on us if there are unrecoverable errors during write. So IO#closed? is a pointless check because EM does not invalidate the underlying file descriptor.
2010-07-28event_machine: better handling of staggered pipelines
Since TCP sockets stream, HTTP requests do not come in at well-defined boundaries and it's possible for pipelined requests to come in in a staggered form. We need to ensure our receive_data callback doesn't fire any actions at all while responding with a deferrable @body. We still need to be careful about buffering, since EM does not appear to allow temporarily disabling read events (without pausing writes), so we shutdown the read end of the socket if it reaches a maximum header size limit.
2010-07-27event_machine: prevent double close of client socket
Not sure where this is happening, but this can trigger Errno::EBADF under heavy load.
2010-07-27event_machine: fix pipelining of static files
EM::FileStreamer writes may be intermingled with the headers in the subsequent response if we enable processing of the second pipelined response right away, so wait until the first response is complete before hitting the second one. This also avoids potential deep stack recursion in the unlikely case where too many requests are pipelined.
2010-07-20event_machine: avoid redundant open() for static files
This is cheaper for serving static files and only slightly more expensive for pipes and sockets (extra path lookup for File.stat).
2010-07-19ensure client aborted file/stream response bodies are closed
We need to remember to close response bodies even if a client aborts the connection, since body.close can trigger interesting things like logging and such...
2010-07-19event_machine: close body descriptor before streaming file
EM::FileStreamer must be passed a path, so should release our newly opened descriptor first :<
2010-07-19ensure file response bodies are properly closed
Middlewares like Clogger may wrap Rack::File responses with another body that responds to to_path and still rely on #close to trigger an action (writing out the log file).
2010-07-19ensure stream response bodies get closed
Some middlewares such as Clogger rely on wrapping the body having the close method called on it for logging.
2010-07-19event_machine: don't set @body unless it's EM::Deferrable
We also properly fail on EM::FileStreamer responses, too
2010-07-19event_machine: small simplification for async responses
Extraneous returns are harder to follow.
2010-07-19event_machine: split out uncommonly used modules
Some applications may not use Response*Pipe and TryDefer at all, so there's no reason to pollute the runtime with extra nodes to mark during GC.
2010-07-19rev + em: enable keepalive for pipe/socket responses
This makes it easier to write proxies for slow clients that benefit from keep-alive. We also need to be careful about non-HTTP/1.1 connections that can't do keepalive, now.
2010-07-19rev + em: more easily allow Content-Length in pipe responses
If a response proxying a pipe (or socket) includes a Content-Length, do not attempt to outsmart the application and just use the given Content-Length. This helps avoid exposing applications to weird internals such as env["rainbows.autochunk"] and X-Rainbows-* response headers.
2010-07-19event_machine: ResponseChunkPipe style cleanup
No need to double up on begin blocks since we know @client.write won't raise exceptions @io.read_nonblock does. Also prefer @client.write to @client.send_data since it looks more in line with other IO interfaces.
2010-07-19event_machine: garbage avoidance for pipe responses
Since the EM loop runs entirely in one thread, we can get away with using a single buffer across all pipe/socket responses.
2010-07-19event_machine: avoid race in unchunked fast pipe responses
Using EM.enable_proxy with EM.attach seems to cause EM::Connection#receive_data callbacks to be fired before the proxy has a chance to act, leading the first few chunks of data being lost in the default receive_data handler. Instead just rely on EM.watch like the chunked pipe.
2010-07-19remove unnecessary header munging for static file serving
Rack::File already sets the Content-Length header for us, so there's no reason to ever set this ourselves.
2010-07-19refactor response handling for each concurrency model
This will give each concurrency model more control over particular code paths and serving static files.
2010-07-10doc: avoid documenting internals on RDoc website
Since we suck at building websites, we just rely on RDoc as a website builder. And since Rainbows! is an application server (and not a programming library), our internal API should be of little interest to end users. Anybody interested in Rainbows! (or any other project) internals should be reading the source.
2010-07-09event_machine: rename response_write => em_write_response
For consistency with rev_write_response (and the existing "write_response").
2010-07-08restore Rainbows::HttpResponse.write for Cramp
Cramp monkey patches Rainbows internals for WebSockets support and we forgot about it. Add a new integration test to ensure this continues to work in the future (and force us to update the test for newer Cramp).
2010-07-04refactor response body handling for sendfile(2)
This hopefully allows the "sendfile" gem to be required anywhere in the Rainbows!/Unicorn config file, and not have to be required via RUBYOPT or the '-r' command-line switch. We also modularize HttpResponse and avoids singleton methods in the response path. This (hopefully) makes it easier for individual concurrency models to share code and override individual methods.
2010-06-18avoid needless HeaderHash#to_hash calls
HeaderHash objects can only be used as headers without violating Rack::Lint in Rack 1.1.0 or later.
2010-06-18prefer Array#[] lookup to Array#first/Array#last
Array#[] lookups are slightly faster under both rbx and 1.9, and easier to read.
2010-06-06centralize body => IO conversion logic
Since EventMachine and Rev shared the same logic for optimizing and avoiding extra file opens for IO/File-ish response bodies, so centralize that. For Ruby 1.9 users, we've also enabled this logic so ThreadPool, ThreadSpawn, WriterThreadPool, and WriterThreadSpawn can take advantage of Rainbows::DevFdResponse-generated bodies while proxying sockets.
2010-05-04eventmachine: "rack.multithread" is always true when deferring
Since deferred requests run in a separate thread, this affects the root (non-deferred) thread as well since it may share data with other threads.
2010-05-04eventmachine: add app.deferred?(env) support as middleware
Merb (and possibly other) frameworks that support conditionally deferred app dispatch can now use it just like Ebb and Thin. http://brainspl.at/articles/2008/04/18/deferred-requests-with-merb-ebb-and-thin