0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 12:20:24 +00:00

Implement backpressure on cowboy_req:stream_body

This should limit the amount of memory that Cowboy is using
when a handler is sending data much faster than the network.

The new max_stream_buffer_size is a soft limit and only has
an effect when the cowboy_stream_h handler is used.
This commit is contained in:
Loïc Hoguin 2019-09-13 14:20:04 +02:00
parent 4427108b69
commit 49af57d546
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764
6 changed files with 91 additions and 25 deletions

View file

@ -221,6 +221,11 @@ do(<<"stream_body">>, Req0, Opts) ->
cowboy_req:stream_body(<<"world">>, nofin, Req),
cowboy_req:stream_body(<<"!">>, fin, Req),
{ok, Req, Opts};
<<"loop">> ->
Req = cowboy_req:stream_reply(200, Req0),
_ = [cowboy_req:stream_body(<<0:1000000/unit:8>>, nofin, Req)
|| _ <- lists:seq(1, 32)],
{ok, Req, Opts};
<<"nofin">> ->
Req = cowboy_req:stream_reply(200, Req0),
cowboy_req:stream_body(<<"Hello world!">>, nofin, Req),