Skip to content

Commit

Permalink
Merge pull request #26 from zhangtony239/master
Browse files Browse the repository at this point in the history
Added paragraph about server priority
  • Loading branch information
tobyxdd authored Jun 25, 2024
2 parents be09962 + e3752ab commit 3e33a80
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
38 changes: 37 additions & 1 deletion docs/docs/advanced/Performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ The following factors are common contributors to bottlenecks in your transfer sp
- The processing power of your CPU, NIC, etc.
- System buffer sizes
- Flow control receive window sizes
- Process priority

> It's worth noting that QUIC, being a much newer and more complex protocol running in userspace, will inherently require more processing power than the mature, highly optimized kernel-level implementation of TCP. If you want to achieve high transfer speeds, you should not host your server on low-power hardware such as a Raspberry Pi or an extremely low-cost, CPU-throttled VPS.
While the first two are beyond the scope of this documentation, the last two can be tuned to improve performance.
While the first two are beyond the scope of this documentation, the last three can be optimized to improve performance.

## System buffer sizes

Expand Down Expand Up @@ -47,3 +48,38 @@ quic:
4. There is an auto-tuning mechanism for the receive window size that will increase the window size as needed, but will not exceed this value. The default is 20 MB.
You can increase these values if they are too low for your use case, or decrease them if you need to save memory. **We strongly recommend that you maintain a stream-to-connection receive window ratio close to 2/5.** This prevents one or two blocked streams from hogging the entire connection.
## Process priority
On devices with limited CPU resources, high load can cause latency jitter. This can be mitigated by increasing the process priority.
### systemd
For Linux.
Create `/etc/systemd/system/hysteria-server.service.d/priority.conf` and add the following:

```ini
[Service]
CPUSchedulingPolicy=rr
CPUSchedulingPriority=99
```

Reload the systemd config files and restart the service using the following commands:

```bash
systemctl daemon-reload
systemctl restart hysteria-server.service
```

### chrt

For both Linux and FreeBSD. On FreeBSD, you need to install `util-linux`, and the highest priority is 31 instead of 99.

```bash
# Execute after each service start
chrt -r 99 $(pidof hysteria)
# Or, use the following command to start the service
chrt -r 99 hysteria server -c /path/to/config.yaml
```
38 changes: 37 additions & 1 deletion docs/docs/advanced/Performance.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
- CPU、网卡等的处理能力
- 系统缓冲区大小
- 流控制接收窗口大小
- 进程优先级

> QUIC 作为一种更新、更复杂、在用户态执行的协议,自然会比成熟、高度优化的内核 TCP 实现需要更多的处理能力。如果想提高传输速度,不要运行在树莓派或极便宜的 VPS 上。
前两点超出了本文档的范围,但后两点可以通过调优来提高性能
前两点超出了本文档的范围,但后三点可以通过调优来提高性能

## 系统缓冲区大小

Expand Down Expand Up @@ -47,3 +48,38 @@ quic:
4. 接收窗口大小有一个自动调节机制,该机制会根据需要增加窗口大小,但不会超过此值。默认值是 20 MB。
可以根据你的使用情景提高或者降低这些值。**强烈建议保持接近 2/5 的流/连接接收窗口比例。** 这样可以防止一个或两个阻塞的流卡死整个连接。
## 进程优先级
在 CPU 资源紧缺的设备上, 高负载下可能会出现延迟抖动, 可通过提高进程优先级来缓解。
### 通过 systemd
适用于 Linux。
创建 `/etc/systemd/system/hysteria-server.service.d/priority.conf` 并填入以下内容。

```ini
[Service]
CPUSchedulingPolicy=rr
CPUSchedulingPriority=99
```

使用以下命令重载 systemd 配置文件并重启服务。

```bash
systemctl daemon-reload
systemctl restart hysteria-server.service
```

### 通过 chrt

适用于 Linux 和 FreeBSD。 在 FreeBSD 上需安装 `util-linux` 且最高优先级为 31 而不是 99。

```bash
# 在每次服务启动之后执行
chrt -r 99 $(pidof hysteria)
# 或者, 使用下面的命令启动服务
chrt -r 99 hysteria server -c /path/to/config.yaml
```

0 comments on commit 3e33a80

Please sign in to comment.