drewbrew [Tue, 3 Jun 2014 18:22:08 +0000 (13:22 -0500)]
ioloop.py: use itertools.count() as tiebreaker to preserve FIFO in case of tie
Current implementation does not function as a FIFO. When adding multiple
timeouts with the same deadline, order is currently consistently mangled in the
event of a garbage collect.
As suggested by Ben Darnell at
https://groups.google.com/forum/#!topic/python-tornado/w8aKm6ZabUQ/discussion,
we need to add a sequence number to the Timeout class to serve as tiebreaker.
This code uses the model suggested by
https://docs.python.org/2/library/heapq.html#priority-queue-implementation-notes,
which uses itertools.count() to serve as our counter.
Ben Darnell [Sun, 25 May 2014 16:50:51 +0000 (12:50 -0400)]
Stream large response bodies from StaticFileHandler.
The get_content interface is still synchronous so it's not a complete
solution, but this will keep the server from buffering the whole file in
memory while writing it out to the client.
Return Futures from the wsgi interface, allowing @gen.coroutine to be
used there in limited circumstances.
Ben Darnell [Sun, 25 May 2014 15:39:12 +0000 (11:39 -0400)]
Remove HTTP method check from HTTPServerRequest._parse_body.
The semantics of a body are not well-defined for some methods,
but if a client sends a body with the correct content-type,
we might as well parse it no matter what the method.
Ben Darnell [Mon, 19 May 2014 03:19:41 +0000 (23:19 -0400)]
Make gen.Task a function returning a Future instead of a YieldPoint subclass.
This improves performance of applications that mix Tasks and Futures
by only entering a stack context for the duration of the Tasks. It
also fixes an obscure regression (#1058). This might get reverted before
the final release if any backwards-compatibility issues turn up, but
since the status quo also had a regression it's worth a try.
Ben Darnell [Mon, 19 May 2014 01:57:27 +0000 (21:57 -0400)]
Remove test_websocket_network_timeout.
It wasn't testing what it appeared to be (it was hitting exactly the
same code paths as test_websocket_network_fail on posix, but was failing
on windows).
Ben Darnell [Mon, 19 May 2014 00:20:29 +0000 (20:20 -0400)]
Raise StreamClosedError instead of IOError for ECONNRESET.
This allows application code to only catch one kind of exception
(an ECONNRESET exception is raised from
tornado.test.httpserver_test.KeepAliveTest.test_pipeline_cancel
on linux but not on mac)
Ben Darnell [Sat, 17 May 2014 14:56:35 +0000 (10:56 -0400)]
Fix Tornado on Google App Engine.
Imports of tornado.ioloop have crept into more places, so the old
app engine policy of never importing these modules doesn't work.
Instead, we add guards around imports of unavailable modules
(fcntl, ssl, multiprocessing) so that everything is at least importable.
Stefan Tjarks [Fri, 16 May 2014 23:03:01 +0000 (16:03 -0700)]
Extended gen_test decorator to pass args and kwargs.
A use case might be a decorated test class that passes arguments to each class method, like mock.patch for instance.
Ben Darnell [Mon, 12 May 2014 03:43:55 +0000 (23:43 -0400)]
Decouple read_from_buffer's search for the endpoint from consuming the data.
This lets us call find_read_pos from read_to_buffer_loop, avoiding some
unnecessary reads (e.g. it previously took a minimum of two recv calls
to serve an http request, but now we can do it in one).
Ben Darnell [Mon, 12 May 2014 00:23:33 +0000 (20:23 -0400)]
IOStream: do not listen for close events if there is no close_callback.
HTTP1Connection now only registers its close callback when it is done
reading. This improves performance for synchronous handlers, which no
longer interact with the IOLoop as often.
Ben Darnell [Sun, 11 May 2014 22:49:40 +0000 (18:49 -0400)]
Add gen.moment, a yieldable object that resumes after one IOLoop iteration.
Use this between requests in HTTP1ServerConnection to keep one connection
from monopolizing the IOLoop when there are pipelined (or just fast) requests
available. This was causing increased variance in benchmarks using "ab -k"
(it also increased throughput, for reasons that are not yet clear, so this
change reduces observed speed in these benchmarks).
Ben Darnell [Sat, 10 May 2014 17:27:46 +0000 (13:27 -0400)]
Improve performance by using Future interface when writing HTTP responses.
Previously, we passed a callback to IOStream.write() and also checked
IOStream.writing() to see if the write completed synchronously (which is
the common case). If it did, we would complete the request immediately
but the write callback would remain on the IOLoop until its next iteration,
keeping the request state from being garbage collected.
In benchmarks, this would manifest as as something like a memory leak,
since benchmarks often handle many requests in one IOLoop iteration.
This slowed things down (by about 10% in my benchmarks) by increasing
pressure on the garbage collector.
Ben Darnell [Mon, 5 May 2014 02:59:12 +0000 (22:59 -0400)]
Add a v2 secure cookie format.
This format fixes some weaknesses in the original format that would allow
characters to be shifted from the "value" field to the "name" or "timestamp"
fields. It also upgrades the signature from HMAC-SHA1 to HMAC-SHA256,
adds an explicit version field, and adds an as-yet-unused field to
support key rotation in the future.
moijes12 [Sun, 4 May 2014 18:22:05 +0000 (23:52 +0530)]
Changed tornado/simple_httpclient.py to raise the error instead of
storing the error message and then raising an HTTPError.
Changed the websocket tests for network_fail and network timeout to
expect an IOError instead of an HTTPError.