aboutsummaryrefslogtreecommitdiffstats
path: root/doc/src/manual/cowboy_http.asciidoc
AgeCommit message (Collapse)Author
2025-02-10Provide better control over which HTTP protocols are enabledLoïc Hoguin
Over cleartext TCP the `protocols` option lists the enabled protocols. The default is to allow both HTTP/1.1 and HTTP/2. Over TLS the default protocol to use when ALPN is not used can now be configured via the `alpn_default_protocol` option. Performing an HTTP/1.1 upgrade to HTTP/2 over TLS is now rejected with an error as connecting to HTTP/2 over TLS requires the use of ALPN (or that HTTP/2 be the default when connecting over TLS).
2025-02-07Deprecate the inactivity_timeout optionsLoïc Hoguin
When idle_timeout is configured we do not need a separate timer to detect inactivity. Disabling idle_timeout is not recommended and should not be necessary.
2025-02-07Add hibernate option to cowboy_http and cowboy_http2Loïc Hoguin
When enabled the connection process will automatically hibernate. Because hibernation triggers GC, this can be used as a way to keep memory usage lower, at the cost of performance.
2025-02-05Lower the lower dynamic buffer value to 1024Loïc Hoguin
There's not a big performance difference between 8192 and 1024 so let's use less memory at the start of the connection.
2025-02-05Implement dynamic socket buffer sizesLoïc Hoguin
Cowboy will set the socket's buffer size dynamically to better fit the current workload. When the incoming data is small, a low buffer size reduces the memory footprint and improves responsiveness and therefore performance. When the incoming data is large, such as large HTTP request bodies, a larger buffer size helps us avoid doing too many binary appends and related allocations. Setting a large buffer size for all use cases is sub-optimal because allocating more than needed necessarily results in a performance hit (not just increased memory usage). By default Cowboy starts with a buffer size of 8192 bytes. It then doubles or halves the buffer size depending on the size of the data it receives from the socket. It stops decreasing at 8192 and increasing at 131072 by default. To keep track of the size of the incoming data Cowboy maintains a moving average. It allows Cowboy to avoid changing the buffer too often but still react quickly when necessary. Cowboy will increase the buffer size when the moving average is above 90% of the current buffer size, and decrease when the moving average is below 40% of the current buffer size. The current buffer size and moving average are propagated when switching protocols. The dynamic buffer is implemented in HTTP/1, HTTP/2 and HTTP/1 Websocket. HTTP/2 Websocket has it disabled because it doesn't interact directly with the socket; in that case it is HTTP/2 that has a dynamic buffer. The dynamic buffer provides a very large performance improvement in many scenarios, at minimal cost for others. Because it largely depend on the underlying protocol the improvements are no all equal. TLS and compression also impact the results. The improvement when reading a large request body, with the requests repeated in a fast loop are: * HTTP: 6x to 20x faster * HTTPS: 2x to 6x faster * H2: 4x to 5x faster * H2C: 20x to 40x faster I am not sure why H2C's performance was so bad, especially compared to H2, when using default buffer sizes. Dynamic buffers make H2C a lot more viable with default settings. The performance impact on "hello world" type requests is minimal, it goes from -5% to +5% roughly. Websocket improvements vary again depending on the protocol, but also depending on whether compression is enabled: * HTTP echo: roughly 2x faster * HTTP send: roughly 4x faster * H2C echo: roughly 2x faster * H2C send: 3x to 4x faster In the echo test we reply back, and Gun doesn't have the dynamic buffer optimisation, so that probably explains the x2 difference. With compression however there isn't much improvement. The results are roughly within -10% to +10% of each other. Zlib compression seems to be a bottleneck, or at least to modify the performance profile to such an extent that the size of the buffer does not matter. This happens to randomly generated binary data as well so it is probably not caused by the test data.
2024-01-23Document reset_idle_timeout_on_send optionLoïc Hoguin
2020-05-20Increase the default max_keepalive HTTP option to 1000Loïc Hoguin
100 is very low for current deployments. 1000 is more appropriate as a default value.
2020-01-06Use active,NLoïc Hoguin
This reduces the number of times we need to ask for more packets, and as a result we get a fairly large boost in performance, especially with HTTP/1.1. Unfortunately this makes Cowboy require at least Erlang/OTP 21.3+ because the ssl application did not have active,N. For simplicity the version required will be Erlang/OTP 22+. In addition this change improves hibernate handling in cowboy_websocket. Hibernate will now work for HTTP/2 transport as well, and stray or unrelated messages will no longer cancel hibernate (the process will handle the message and go back into hibernation). Thanks go to Stressgrid for benchmarking an early version of this commit: https://stressgrid.com/blog/cowboy_performance_part_2/
2019-10-09Implement flow control for HTTP/1.1Loïc Hoguin
We now stop reading from the socket unless asked to, when we reach the request body. The option initial_stream_flow_size controls how much data we read without being asked, as an optimization. We may also have received additional data along with the request headers. This commit also reworks the timeout handling for HTTP/1.1 because the stray timeout message was easily reproducible after implementing the flow control. The issue should be gone for good this time.
2019-10-07Document the set_options stream handler commandLoïc Hoguin
2019-10-07Document the logger optionLoïc Hoguin
2018-11-18Document cowboy_stream_h/cowboy_compress_hLoïc Hoguin
2018-11-18Add the chunked option for HTTP/1.1Loïc Hoguin
It allows disabling the chunked transfer-encoding. It can also be disabled on a per-request basis, although it will be ignored for responses that are not streamed.
2018-11-14Add some missing items to a few module changelogsLoïc Hoguin
2018-11-14Allow disabling keep-alive for HTTP/1.0 connectionsLoïc Hoguin
2018-11-14Document the proxy_header protocol optionLoïc Hoguin
2018-11-03Add an option to disable sendfile for a listenerLoïc Hoguin
2018-05-16Add option linger_timeout to cowboy_httpLoïc Hoguin
2017-12-07Add more rfc7231 tests and a new max_skip_body_length optionLoïc Hoguin
The option controls how much body we accept to skip for HTTP/1.1 connections when the user code did not consume the body fully. It defaults to 1MB.
2017-06-07Remove NumAcceptors argument from start_clear/tlsLoïc Hoguin
They are now cowboy:start_clear/3 and cowboy:start_tls/3. The NumAcceptors argument can be specified via the num_acceptor transport option. Ranch has been updated to 1.4.0 to that effect.
2017-05-05Add inactivity_timeout and other options improvementsLoïc Hoguin
2017-05-03Add the idle_timeout HTTP/1.1 protocol optionLoïc Hoguin
This fixes the connection being dropped because of request_timeout despite there being some active streams.
2016-12-22Updates cowboy_http documents changelogSasan Hezarkhani
The changelog had a wrong reference to an option that was updated. `max_header_request_line_length` -> `max_request_line_length`
2016-12-22Update cowboy_websocket_manualLoïc Hoguin
2016-12-22Add cowboy_http manualLoïc Hoguin
Updates and replaces the cowboy_protocol manual.