Search code examples
pythonwebsockettornadolarge-files

Increase max_buffer_size limit of BaseIOStream in Tornado


Tornado websocket server is used for bidirectional communication with clients where large payloads may be sent. I have already increased the size of the socket message using:

tornado.web.Application(tuples, websocket_max_message_size = 256 * 1024 * 1024), 

according to:answer. However, I get an exception if the message exceeds 100MiB (Read buffer size exceeded).

Tried:
I believe I have traced that exception in BaseIoStream where max_buffer_size is set to 100MiB value. How can I increase that buffer size as well (or anything else, so I can receive messages > 100MiB) ?


Solution

  • You can increase the IOStream's buffer limit from your WebSocketHandler subclass like this:

    class YourWebSocketHandler(websocket.WebSocketHandler):
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
            self.request.connection.stream.max_buffer_size = 256 * 1024 * 1024
    

    This also works for RequestHandler subclasses.