6.8K star!开源 Rust 测试工具,超炫酷!
项目简介
Oha
是一个由Rust语言编写的轻量级HTTP负载生成器,它的灵感来源于rakyll/hey,但在此基础上增加了TUI(文本用户界面)动画,让测试结果更加直观和生动。oha利用了tokio和ratatui库,能够在高并发场景下保持优异的性能表现。同时,它还支持多种HTTP协议(HTTP/1.1、HTTP/2和HTTP/3),满足不同的测试需求。
目前在Github上收获了6.8K star!
性能特色
高效的负载生成:Oha能够快速生成大量HTTP请求,支持并发连接和HTTP/2协议,适用于各种性能测试场景。
实时TUI显示:通过TUI动画,用户可以实时监控请求的发送和响应情况,直观地了解系统的性能表现。
多平台支持:Oha支持Linux、Windows和macOS平台,用户可以在不同操作系统上无缝使用。
灵活的配置选项:用户可以通过命令行参数灵活配置请求数量、并发连接数、请求持续时间等,满足不同测试需求。
快速安装使用
安装oha非常简单,你可以根据自己的操作系统选择不同的安装方式。对于Linux和macOS用户,可以使用包管理器进行安装;而Windows用户则可以使用winget进行安装。
# Linux/macOS,使用Cargo安装(需要先安装Rust工具链)
cargo install oha
# 使用Homebrew安装(适用于macOS)
brew install oha
# Windows,使用winget安装
winget install hatoo.oha
或者到项目release页面下载对应系统的安装包即可。
安装完成后,你可以运行基本测试,比如发送200个请求到目标URL:
oha -n 200 https://baidu.com
如果你想设置并发连接数为50,可以这样做:
oha -c 50 https://baidu.com
或者,如果你想运行持续时间为30秒的测试:
oha -z 30s https://baidu.com
oha能够实时显示请求的发送数量、响应时间、错误率等关键指标,让你对系统的性能表现一目了然。
更多使用参数可以参考文档
Ohayou(おはよう), HTTP load generator, inspired by rakyll/hey with tui animation.
Usage: oha [OPTIONS] <URL>
Arguments:
<URL> Target URL or file with multiple URLs.
Options:
-n <N_REQUESTS>
Number of requests to run. [default: 200]
-c <N_CONNECTIONS>
Number of connections to run concurrently. You may should increase limit to number of open files for larger `-c`. [default: 50]
-p <N_HTTP2_PARALLEL>
Number of parallel requests to send on HTTP/2. `oha` will run c * p concurrent workers in total. [default: 1]
-z <DURATION>
Duration of application to send requests. If duration is specified, n is ignored.
On HTTP/1, When the duration is reached, ongoing requests are aborted and counted as "aborted due to deadline"
You can change this behavior with `-w` option.
Currently, on HTTP/2, When the duration is reached, ongoing requests are waited. `-w` option is ignored.
Examples: -z 10s -z 3m.
-w, --wait-ongoing-requests-after-deadline
When the duration is reached, ongoing requests are waited
-q <QUERY_PER_SECOND>
Rate limit for all, in queries per second (QPS)
--burst-delay <BURST_DURATION>
Introduce delay between a predefined number of requests.
Note: If qps is specified, burst will be ignored
--burst-rate <BURST_REQUESTS>
Rates of requests for burst. Default is 1
Note: If qps is specified, burst will be ignored
--rand-regex-url
Generate URL by rand_regex crate but dot is disabled for each query e.g. http://127.0.0.1/[a-z][a-z][0-9]. Currently dynamic scheme, host and port with keep-alive do not work well. See https://docs.rs/rand_regex/latest/rand_regex/struct.Regex.html for details of syntax.
--urls-from-file
Read the URLs to query from a file
--max-repeat <MAX_REPEAT>
A parameter for the '--rand-regex-url'. The max_repeat parameter gives the maximum extra repeat counts the x*, x+ and x{n,} operators will become. [default: 4]
--dump-urls <DUMP_URLS>
Dump target Urls <DUMP_URLS> times to debug --rand-regex-url
--latency-correction
Correct latency to avoid coordinated omission problem. It's ignored if -q is not set.
--no-tui
No realtime tui
-j, --json
Print results as JSON
--fps <FPS>
Frame per second for tui. [default: 16]
-m, --method <METHOD>
HTTP method [default: GET]
-H <HEADERS>
Custom HTTP header. Examples: -H "foo: bar"
-t <TIMEOUT>
Timeout for each request. Default to infinite.
-A <ACCEPT_HEADER>
HTTP Accept Header.
-d <BODY_STRING>
HTTP request body.
-D <BODY_PATH>
HTTP request body from file.
-T <CONTENT_TYPE>
Content-Type.
-a <BASIC_AUTH>
Basic authentication, username:password
-x <PROXY>
HTTP proxy
--proxy-http-version <PROXY_HTTP_VERSION>
HTTP version to connect to proxy. Available values 0.9, 1.0, 1.1, 2.
--proxy-http2
Use HTTP/2 to connect to proxy. Shorthand for --proxy-http-version=2
--http-version <HTTP_VERSION>
HTTP version. Available values 0.9, 1.0, 1.1, 2.
--http2
Use HTTP/2. Shorthand for --http-version=2
--host <HOST>
HTTP Host header
--disable-compression
Disable compression.
-r, --redirect <REDIRECT>
Limit for number of Redirect. Set 0 for no redirection. Redirection isn't supported for HTTP/2. [default: 10]
--disable-keepalive
Disable keep-alive, prevents re-use of TCP connections between different HTTP requests. This isn't supported for HTTP/2.
--no-pre-lookup
*Not* perform a DNS lookup at beginning to cache it
--ipv6
Lookup only ipv6.
--ipv4
Lookup only ipv4.
--insecure
Accept invalid certs.
--connect-to <CONNECT_TO>
Override DNS resolution and default port numbers with strings like 'example.org:443:localhost:8443'
--disable-color
Disable the color scheme.
--unix-socket <UNIX_SOCKET>
Connect to a unix socket instead of the domain in the URL. Only for non-HTTPS URLs.
--stats-success-breakdown
Include a response status code successful or not successful breakdown for the time histogram and distribution statistics
--db-url <DB_URL>
Write succeeded requests to sqlite database url E.G test.db
--debug
Perform a single request and dump the request and response
-h, --help
Print help
-V, --version
Print version
本文是原创文章,采用 CC BY-NC-ND 4.0 协议,完整转载请注明来自 ijoy.store
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果