hertz
hertz copied to clipboard
perf: revert NewChunkedBodyWriter
What type of PR is this?
Check the PR title.
- [x] This PR title match the format: <type>(optional scope): <description>
- [x] The description of this PR title is user-oriented and clear enough for others to understand.
- [ ] Attach the PR updating the user documentation if the current PR requires user awareness at the usage level. User docs repo
(Optional) Translate the PR title into Chinese.
(Optional) More detailed description for this PR(en: English/zh: Chinese).
en: zh(optional): 取消池化 NewChunkedBodyWriter
cpu 时间出现较大差异
0.7.1 和 0.6.1 版本的 hertz 进行比较, cpu 时间相差 8 倍
性能出现劣化
=======================================================
hertz 0.6.1
=======================================================
Running 1m test @ http://localhost:3000/sse
8 threads and 512 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 23.68ms 17.15ms 307.82ms 83.41%
Req/Sec 1.86k 1.01k 4.68k 60.13%
Latency Distribution
50% 19.53ms
75% 28.76ms
90% 42.53ms
99% 88.00ms
776720 requests in 1.00m, 705.20MB read
Socket errors: connect 212, read 0, write 0, timeout 0
Requests/sec: 12923.79
Transfer/sec: 11.73MB
=======================================================
hertz 0.7.1
=======================================================
Running 1m test @ http://localhost:3000/sse
8 threads and 512 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 29.03ms 21.50ms 312.42ms 79.90%
Req/Sec 1.76k 816.53 4.57k 65.35%
Latency Distribution
50% 23.47ms
75% 37.21ms
90% 55.44ms
99% 109.00ms
630186 requests in 1.00m, 572.16MB read
Socket errors: connect 212, read 0, write 0, timeout 0
Requests/sec: 10488.32
Transfer/sec: 9.52MB
从上面的 wrk 压测结果看出, 0.7.1 版本的 hertz 的各项指标均出现劣化
runtime.SetFinalizer 使用的并不恰当
添加 runtime.SetFinalizer 的原意是用于兜底回收, 但实际上带来了性能劣化
https://lemire.me/blog/2023/05/19/the-absurd-cost-of-finalizers-in-go/
在上面的博客中谈到, 使用 finalizer 会显著增加对象的创建和销毁的时间,大约是不使用 finalizer 的 430 倍。他建议避免使用 finalizer,除非有非常强烈的理由