Updated Parameter Tuning (markdown)

klzgrad
2020-10-02 02:46:51 +08:00
parent 8d14fb53e5
commit 683870682c
2 changed files with 62 additions and 35 deletions

@@ -1,35 +0,0 @@
## Linux kernel
HTTP/2 uses a single connection per host. Most of TCP tuning is no longer needed.
* Use a kernel as new as possible.
* Use BBR congestion control (recommended).
```
sudo sysctl -w net.ipv4.tcp_congestion_control=bbr
```
* Turn off `tcp_slow_start_after_idle` (optional). This improves persistent single connection performance slightly.
```
sudo sysctl -w net.ipv4.tcp_slow_start_after_idle=0
```
That's it!
The above two options are not important at server side, so it's OK if you cannot set them.
Do not turn on TCP Fast Open. Its Linux implementation is too conservative to be useful, and its usage is rare in practice thus creating a distinct traffic feature.
References: [[1]](https://hpbn.co/building-blocks-of-tcp/) [[2]](https://github.com/http2/http2-spec/wiki/Ops).
## Chromium
Chromium limits the number of connections per proxy to 32. New connections that exceed this limit will be stalled, but multi-tab browsing often needs more than 32 connections. Create a policy to override this limit.
For Chromium on Linux:
```
sudo mkdir -p /etc/chromium/policies/managed
echo '{ "MaxConnectionsPerProxy": 99 }' | sudo tee /etc/chromium/policies/managed/proxy.json
```
99 is the maximum maximum allowed by Chromium. You are recommended to use an ad-blocker to save on connections.
For Chrome or other OSes, see [[1]](https://www.chromium.org/administrators/policy-templates) [[2]](https://www.chromium.org/administrators/policy-list-3#MaxConnectionsPerProxy).

62
Performance-Tuning.md Normal file

@@ -0,0 +1,62 @@
## Linux kernel
### Use a kernel as new as possible
HTTP/2 uses a single connection per host. Most of TCP tuning is no longer needed (e.g. `net.ipv4.tcp_wmem`).
### Use BBR congestion control
```
sudo sysctl -w net.ipv4.tcp_congestion_control=bbr
```
### Turn off tcp_slow_start_after_idle
```
sudo sysctl -w net.ipv4.tcp_slow_start_after_idle=0
```
This setting can improve persistent single connection performance slightly.
* https://hpbn.co/building-blocks-of-tcp/
* https://github.com/http2/http2-spec/wiki/Ops
* https://dropbox.tech/infrastructure/optimizing-web-servers-for-high-throughput-and-low-latency
### (Server only) Consider setting tcp_notsent_lowat
```
sudo sysctl -w net.ipv4.tcp_notsent_lowat=16384
```
This setting can improve interactive latency by optimizing send buffer handling. Note that this kernel setting is useful for HTTP/2 and may be detrimental to other applications, as it applies to all applications on the server.
Be cautious with this setting. Small values tend to increase server CPU usage and negatively affect throughput. You need to benchmark it to determine good settings. You can check the HTTP/2 load time in https://http2.akamai.com/demo while also downloading a large file with and without this setting.
Common values range from 16KB to 128KB.
* https://blog.cloudflare.com/http-2-prioritization-with-nginx/
* https://web.archive.org/web/20170924184144/https://insouciant.org/tech/prioritization-only-works-when-theres-pending-data-to-prioritize/
* (Benchmarking HTTP/2 Priorities) https://docs.google.com/document/d/1oLhNg1skaWD4_DtaoCxdSRN5erEXrH-KnLrMwEpOtFY/preview
### Do not turn on TCP Fast Open
Its Linux implementation is too conservative to be useful, and its usage is rare in practice thus creating a distinct traffic feature.
* https://github.com/klzgrad/naiveproxy#why-not-use-go-node-etc-for-performance
* https://blog.donatas.net/blog/2017/03/09/tfo/
* https://squeeze.isobar.com/2019/04/11/the-sad-story-of-tcp-fast-open/
## Chromium
Chromium limits the number of connections per proxy to 32. New connections that exceed this limit will be stalled, but multi-tab browsing often needs more than 32 connections. Create a policy to override this limit.
Note: This is a browser setting, not applicable to any proxies.
For Chromium on Linux:
```
sudo mkdir -p /etc/chromium/policies/managed
echo '{ "MaxConnectionsPerProxy": 99 }' | sudo tee /etc/chromium/policies/managed/proxy.json
```
You should be able to see it in chrome://policy once set up.
99 is the maximum value for MaxConnectionsPerProxy allowed by Chromium. It is still too low. You are recommended to use an ad-blocker to save on connections.
For Chrome or other OSes, see:
* https://www.chromium.org/administrators/policy-templates
* https://cloud.google.com/docs/chrome-enterprise/policies/?policy=MaxConnectionsPerProxy