about summary refs log tree commit homepage
path: root/lib/rainbows/event_machine.rb
AgeCommit message (Collapse)AuthorFilesLines
2017-01-09eventmachine: wait for deferred actions to finish em-deferredEric Wong1-1/+9
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.xEric Wong1-1/+11
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 runningMark J. Titorenko1-0/+1
...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 homepageEric Wong1-2/+2
Cramp has a homepage and mailing list now, yay!
2011-08-05event_machine: APP needs to be in the main Client classEric Wong1-1/+1
Oops, testing against new changes against cramp.git here
2011-08-05event_machine: add :em_client_class optionEric Wong1-1/+16
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 documentationEric Wong1-3/+1
It should hopefully give this more visibility even though it's an internal feature.
2011-05-20event_machine: disconnect idle clients at on SIGQUITEric Wong1-4/+4
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 requirementsEric Wong1-0/+4
Hopefully makes things easier to try out.
2011-01-20ev_core: simplify setup stepsEric Wong1-6/+0
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! moduleEric Wong1-4/+5
Code organization is hard :<
2011-01-04globally refactor Range handling for responsesEric Wong1-1/+1
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 classesEric Wong1-135/+12
This should make things easier to find
2010-12-26rainbows/rev/* require/autoload cleanupEric Wong1-1/+0
One line of code saved! We'll also avoid loading DeferredChunkResponse which is rarely needed (unlike DeferredResponse).
2010-12-26avoid HttpParser#keepalive? and HttpParser#resetEric Wong1-2/+1
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.0Eric Wong1-0/+1
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 APIEric Wong1-1/+0
These allow for small reductions in the amount of variables we have to manage, more changes coming with later Unicorns.
2010-10-22unindent most filesEric Wong1-194/+188
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 libraryEric Wong1-4/+2
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"Eric Wong1-1/+1
Noise is bad.
2010-08-28"keepalive_timeout 0" (really) disables keepaliveEric Wong1-1/+2
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 moduleEric Wong1-1/+2
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 EBADFEric Wong1-1/+8
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 pipelinesEric Wong1-10/+17
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 socketEric Wong1-1/+1
Not sure where this is happening, but this can trigger Errno::EBADF under heavy load.
2010-07-27event_machine: fix pipelining of static filesEric Wong1-32/+39
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 filesEric Wong1-4/+3
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 closedEric Wong1-5/+6
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 fileEric Wong1-0/+1
EM::FileStreamer must be passed a path, so should release our newly opened descriptor first :<
2010-07-19ensure file response bodies are properly closedEric Wong1-1/+4
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 closedEric Wong1-1/+1
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::DeferrableEric Wong1-2/+2
We also properly fail on EM::FileStreamer responses, too
2010-07-19event_machine: small simplification for async responsesEric Wong1-5/+2
Extraneous returns are harder to follow.
2010-07-19event_machine: split out uncommonly used modulesEric Wong1-77/+3
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 responsesEric Wong1-20/+14
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 responsesEric Wong1-9/+1
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 cleanupEric Wong1-13/+11
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 responsesEric Wong1-2/+6
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 responsesEric Wong1-5/+15
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 servingEric Wong1-2/+0
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 modelEric Wong1-39/+52
This will give each concurrency model more control over particular code paths and serving static files.
2010-07-10doc: avoid documenting internals on RDoc websiteEric Wong1-7/+7
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_responseEric Wong1-3/+3
For consistency with rev_write_response (and the existing "write_response").
2010-07-08restore Rainbows::HttpResponse.write for CrampEric Wong1-2/+2
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)Eric Wong1-8/+13
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 callsEric Wong1-2/+2
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#lastEric Wong1-4/+4
Array#[] lookups are slightly faster under both rbx and 1.9, and easier to read.
2010-06-06centralize body => IO conversion logicEric Wong1-6/+3
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 deferringEric Wong1-0/+8
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 middlewareEric Wong1-0/+23
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