github vapor/vapor 4.13.1
Immediate body streaming

latest releases: 4.100.0, 4.99.3, 4.99.2...
3 years ago
This patch was authored and released by @tanner0101.

Refactors HTTP request body decoding to immediately make streaming bodies available via req.body.drain (#2413).

Previously, Vapor's HTTP request decoder would wait for a second body chunk to arrive before initiating body streaming. This was done as a performance optimization for single-chunk bodies since streaming has overhead. However, this behavior made it difficult to implement real time streaming handlers, like a ping/pong handler.

The HTTP request decoder has been updated to initiate body streaming immediately upon receiving the first chunk. To avoid impacting performance on small, non-streaming request bodies, a check for content-length has been added. If the request's body is contained entirely in a single chunk, streaming overhead is avoided.

Below are performance numbers on Ubuntu 20.04 in req/s.

Method Body Strategy Previous New Delta
GET .collect 229979.85 229333.16 0.28%
POST .collect 198949.90 196567.85 1.21%
POST .stream 197916.54 196178.48 0.89%

The numbers show a negligible change in performance.

Don't miss a new vapor release

NewReleases is sending notifications on new releases.