How to get TCP flow control work with TCPServer

212 views
Skip to first unread message

wang danqi

unread,
Nov 14, 2014, 10:25:23 AM11/14/14
to python-...@googlegroups.com
I am creating a server by deriving a class from TCPServer. Sometimes I will get "Reached the maximum read buffer size" error. I looked into the implementation of iostream and it seems tornado will read data from socket to its buffer as much as possible. When my client sends data too fast, the buffer limit will be exceeded.

Actually I don't quite get the idea of reading from socket as long as any data is available. This effectively disables the benefits of TCP flow control. Although we can increase the buffer limit by max_buffer_size parameter, it doesn't solve the problem.

I am wondering that, when the buffer limit is reached, whether tornado can wait till some data in current read buffer is consumed? 

Thanks.
Danqi

Ben Darnell

unread,
Nov 14, 2014, 6:40:37 PM11/14/14
to Tornado Mailing List
What version of Tornado are you using? Support for flow control was greatly improved in 4.0 (http://www.tornadoweb.org/en/stable/releases/v4.0.0.html); we should no longer be reading unlimited amounts of data from the socket when the application has not requested a read.

-Ben

--
You received this message because you are subscribed to the Google Groups "Tornado Web Server" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-tornad...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

wang danqi

unread,
Nov 15, 2014, 10:12:02 AM11/15/14
to python-...@googlegroups.com, b...@bendarnell.com
I am using the latest 4.0.2 installed by pip. 

I have added the example code which caused the error. I ran it as follows:

python server.py 10000
python client.py localhost 10000

then I got the following output from the terminal running server.py:

INFO:root:104857600 bytes data received from ::1:52517.
ERROR:tornado.general:Reached maximum read buffer size
WARNING:tornado.general:error on read
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tornado/iostream.py", line 601, in _handle_read
    pos = self._read_to_buffer_loop()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tornado/iostream.py", line 571, in _read_to_buffer_loop
    if self._read_to_buffer() == 0:
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tornado/iostream.py", line 701, in _read_to_buffer
    raise StreamBufferFullError("Reached maximum read buffer size")
StreamBufferFullError: Reached maximum read buffer size

OS: Mac OSX 10.0.5
python: 2.7.8

I got the similar results on Ubuntu Linux.

Thanks.
Danqi
server.py
client.py

Ben Darnell

unread,
Nov 15, 2014, 12:02:46 PM11/15/14
to wang danqi, Tornado Mailing List
This appears to be a bug with the kqueue IOLoop implementation - I see the same error on a mac but it works as expected on linux (with epoll). 

It looks like the problem is this line:

In epoll, you can listen for read, write, or error, but in kqueue you can only listen for read or write, so we add the read flag whenever the application is only interested in errors. This of course defeats any efforts at flow control; we're probably better off getting rid of this. I've long had a suspicion that even for epoll, listening for errors doesn't really do anything useful for us (especially now that we've removed EPOLL_RDHUP from the bitmask), so it might make sense to deprecate IOLoop.ERROR entirely.

-Ben

wang danqi

unread,
Nov 15, 2014, 7:46:17 PM11/15/14
to python-...@googlegroups.com, beyo...@gmail.com, b...@bendarnell.com
Interesting. I have never dug into the details of kqueue and epoll.

However, actually the first time I got this error is on a Ubuntu Linux, not the latest version but definitely have epoll support (kernel version should be greater than 3). Unfortunately I don't have access to that machine anymore.

Let me get a latest Linux installed and test on it. I'll get back to you later.

Thanks.
Reply all
Reply to author
Forward
0 new messages