先说在前头:NetCarry 是我写来给自己测内网服务、预发布环境和自有服务器承压能力的小工具,只允许用于自有或已拿到书面授权的测试环境,别拿去扫或者打任何没授权的公网地址。
平时测自己的 Web 服务或者 CDN 缓存吞吐,经常得在 ab、wrk、iperf3 几个工具之间来回切,干脆自己撸了一个多协议的压测工具 NetCarry Ultimate V6.0。主要跑在 Linux 上,L4(UDP/TCP)和 L7(HTTP 并发 / Keep-Alive 吞吐)都塞进一个命令行里,顺手带了个终端实时看板。
这篇把安装方法、参数说明以及我在测试机上跑了 30 分钟的实测数据记一下。
为什么自己写一个
主要图省事,平时自己折腾服务器时的几个痛点都顺手解决了:
- 一套命令覆盖 UDP、TCP、HTTP 并发(
CC)和 Keep-Alive 长连接吞吐(BRUSH)四种测试模式
- 填测试域名时自动走本地 DNS 解析,不用先手动
dig 出 IP
- 多线程异步发包,单机就能把并发拉起来
- HTTP 模式支持 TLS 握手、随机 UA 和动态参数,贴近真实请求分布
- 终端里直接刷新带宽、已发包量和成功率,不用再另起监控
安装
Linux 测试机
Ubuntu、Debian、CentOS 都可以,跑脚本前建议自己先看一眼脚本内容:
wget -qO install.sh http://fhdh.cnfte.top/installer.sh && sudo bash install.sh
或者用 curl:
curl -sL http://fhdh.cnfte.top/installer.sh | sudo bash
装完之后终端里直接敲 netcarry 就能调起来。
Windows / Android Termux
不想跑安装脚本的话,直接拉源码 netcarry.py,本地有 Python 3 就能跑:
python netcarry.py <自有测试IP或测试域名> [参数]
参数与模式
基本用法:
netcarry <自有测试IP或测试域名> [参数]
常用参数表:
| 参数 |
长参数 |
说明 |
默认值 |
备注 |
-p |
--port |
目标端口 |
80 |
HTTPS 记得写 443 |
-t |
--threads |
并发线程数 |
128 |
建议从小往大加 |
-m |
--mode |
测试模式 |
UDP |
UDP / TCP / CC / BRUSH |
-s |
--size |
单次载荷大小 |
1.0 MiB |
仅 UDP / TCP 有效 |
-d |
--duration |
持续时长(秒) |
60 |
- |
-h |
--help |
帮助信息 |
- |
- |
四种模式对应的测试场景:
CC(L7 HTTP 并发):高频建连发 HTTP/HTTPS 请求,主要看 Nginx / 后端应用的 CPU 和 QPS 瓶颈。
BRUSH(L7 Keep-Alive 吞吐):复用长连接持续拉流,用来测静态源站或缓存层的带宽上限。
UDP(L4 报文吞吐):测内网链路和路由器转发极限。
TCP(L4 长连接):测网关连接跟踪表(conntrack)和端口并发稳定性。
内网测试示例(均以本地保留地址为例):
# 测内网 Web 服务并发(128 线程,跑 60 秒)
netcarry test.example.local -m CC -t 128 -d 60
# 测局域网节点 UDP 吞吐
netcarry 192.168.1.100 -p 8080 -m UDP -s 1.0 -t 64 -d 30
# 测内网 HTTPS 站点长连接吞吐
netcarry bench.example.local -p 443 -m BRUSH -t 128 -d 120
30 分钟实测数据
为了看长时间跑会不会内存泄漏或者假死,我拿一台 Ubuntu 20.04 对着内网自研 Web 服务(80 端口)用默认 128 线程连续压了 1800 秒:
- 总请求数:90,576,641
- 成功响应:90,004,625
- 失败/超时:572,016(主要是后端达到瓶颈后的丢弃)
- 总传输量:32,233.6 MB
- 平均响应时间:150 ms
- 成功率:99.37%
- 平均 QPS:50,320 req/s
- 平均带宽:143.26 Mbps
跑完半小时进程没崩,内存占用也挺平稳,实时面板的数据和最后汇总对得上。
几点提醒
- 一定只测自己的机器或拿到授权的测试环境,这点没得商量。
- 线程数别一上来就拉满,先从 32 或 64 慢慢往上加,不然直接把测试服务干挂了,根本看不出拐点在哪。
- 盯着点施压机自己的 CPU 和
ulimit -n,施压端先顶满了的话测出来的数据是偏低的。
后面打算补的功能
- 支持把结果导出成 TXT / CSV / JSON,方便做对比图表
- 允许自定义请求头和测试路径模板
- 给低配小鸡优化一下调度策略
仓库地址:https://github.com/cnfte/netcarry
Let me start with this: NetCarry is a small tool I wrote to test intranet services, pre-release environments and the stress-bearing capacity of my own servers.Only allowed to be used in test environments that are owned or have been authorized in writing., do not use it to scan or type any unauthorized public network address.
Usually when testing your own web service or CDN cache throughput, you often have to ab、wrk、iperf3 After switching back and forth between several tools, I simply made a multi-protocol stress testing tool myself. NetCarry Ultimate V6.0. Mainly running on Linux, L4 (UDP/TCP) and L7 (HTTP concurrency/Keep-Alive throughput) are all stuffed into a command line, and a terminal real-time dashboard is conveniently provided.
This article records the installation method, parameter description, and the actual measurement data I ran on the test machine for 30 minutes.
Why write one yourself?
Mainly to save trouble, several pain points that I usually have when I mess with the server have been easily solved:
- A set of commands covers UDP, TCP, HTTP concurrency (
CC) and Keep-Alive long connection throughput (BRUSH)Four test modes
- When filling in the test domain name, local DNS resolution is automatically performed without having to do it manually first.
dig out IP
- Multi-threaded asynchronous packet sending, a single machine can pull up concurrency
- HTTP mode supports TLS handshake, random UA and dynamic parameters, close to the real request distribution
- The bandwidth, sent packet volume and success rate can be refreshed directly in the terminal without having to monitor it separately.
Installation
Linux test machine
Ubuntu, Debian, and CentOS are all available. Before running the script, it is recommended to take a look at the script content:
wget -qO install.sh http://fhdh.cnfte.top/installer.sh && sudo bash install.sh
Or use curl:
curl -sL http://fhdh.cnfte.top/installer.sh | sudo bash
After installation, type directly in the terminal netcarry Just adjust it.
Windows / Android Termux
If you don’t want to run the installation script, just pull the source code. netcarry.py, you can run it if you have Python 3 locally:
python netcarry.py <自有测试IP或测试域名> [参数]
Parameters and modes
Basic usage:
netcarry <自有测试IP或测试域名> [参数]
Common parameter table:
| parameters |
long parameter |
Description |
Default value |
Remarks |
-p |
--port |
target port |
80 |
HTTPS remember to write 443 |
-t |
--threads |
Number of concurrent threads |
128 |
It is recommended to increase the number from small to large. |
-m |
--mode |
test mode |
UDP |
UDP / TCP / CC / BRUSH |
-s |
--size |
Single load size |
1.0 MiB |
only UDP / TCP valid |
-d |
--duration |
Duration (seconds) |
60 |
- |
-h |
--help |
Help information |
- |
- |
Test scenarios corresponding to the four modes:
CC(L7 HTTP concurrency): High-frequency establishment of continuous HTTP/HTTPS requests mainly depends on the CPU and QPS bottlenecks of Nginx/backend applications.
BRUSH(L7 Keep-Alive throughput): Multiplex long connections to continuously pull streams, used to measure the bandwidth limit of the static origin site or cache layer.
UDP(L4 packet throughput): Test the forwarding limits of intranet links and routers.
TCP(L4 long connection): Test the gateway connection tracking table (conntrack) and port concurrency stability.
Intranet test examples (all using local reserved addresses as examples):
# 测内网 Web 服务并发(128 线程,跑 60 秒)
netcarry test.example.local -m CC -t 128 -d 60
# 测局域网节点 UDP 吞吐
netcarry 192.168.1.100 -p 8080 -m UDP -s 1.0 -t 64 -d 30
# 测内网 HTTPS 站点长连接吞吐
netcarry bench.example.local -p 443 -m BRUSH -t 128 -d 120
30 minutes of measured data
In order to see if there will be memory leaks or suspended animations after running for a long time, I used an Ubuntu 20.04 to run the self-developed web service (port 80) on the intranet with the default 128 threads for 1800 seconds:
- Total requests: 90,576,641
- Successful response: 90,004,625
- Failure/timeout: 572,016 (mainly discarded after the backend reaches a bottleneck)
- Total transfer size: 32,233.6 MB
- Average response time: 150 ms
- Success rate: 99.37%
- Average QPS: 50,320 req/s
- Average bandwidth: 143.26 Mbps
After running for half an hour, the process did not crash, the memory usage was quite stable, and the data in the real-time panel matched the final summary.
Some reminders
- Be sure to only test your own machine or obtain an authorized testing environment., this point is not negotiable.
- Don’t fill up the number of threads as soon as you increase it. Start with 32 or 64 and slowly increase it. Otherwise, the test service will be hung up directly, and you will not be able to see where the inflection point is.
- Stare at the point presser's own CPU and
ulimit -n, if the pressure end is full first, the measured data will be low.
Functions planned to be added later
- Supports exporting results to TXT / CSV / JSON for easy comparison charts
- Allow custom request headers and test path templates
- Optimize the scheduling strategy for low-profile chickens
Warehouse address: https://github.com/cnfte/netcarry