Skip to content

Backpressure in AsyncHandler #544

Description

@jroper

AsyncHandler provides no mechanism to send back pressure on receiving the body parts.

Imagine you have a server that stores large files on Amazon S3, and streams them out to clients, using async http client to connect to S3. Now imagine you have a very slow client, that connects and downloads a file. The slow client pushes back on the server via TCP. However, async http client will keep on calling onBodyPartReceived as fast as S3 provides it with data. The AsyncHandler implementation will have three choices:

  1. Block. Then it's blocking a worker thread, preventing other concurrent operations from happening. This is not an option.
  2. Buffer. Eventually this will cause an OutOfMemoryError. This is not an option.
  3. Drop. Then the client gets a corrupted file. This is not an option.

AsyncHandler therefore needs a mechanism to propagate back pressure when handling body parts. One possibility here is to provide a method to say whether you are interested in receiving more data or not. This would correspond to a Channel.setReadable(true/false) in the netty provider, which will push back via TCP flow control. This could either be provided by injecting some sort of "channel" object into the AsyncHandler, or, since HttpResponseBodyPart already provides mechanisms for talking back to the channel (eg closeUnderlyingConnection()), it could be provided there.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions