前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >强!6.7K Star!推荐一款Rust开源HTTP性能测试工具,超炫酷!

强!6.7K Star!推荐一款Rust开源HTTP性能测试工具,超炫酷!

作者头像
测试开发技术
发布2024-12-24 18:39:02
发布2024-12-24 18:39:02
17500
代码可运行
举报
文章被收录于专栏:测试开发技术
运行总次数:0
代码可运行

在软件开发和测试领域,HTTP性能测试是确保Web服务器稳定和高效运行的关键步骤。今天,给大家推荐一款基于Rust语言开发的开源HTTP性能测试工具——oha,凭借其出色的性能和炫酷的输出界面,在GitHub上脱颖而出赢得了6.7K Star的关注。

一、项目简介

oha是一款小巧而强大的测试工具,使用Rust语言编写,依托tokio和ratatui库,实现了高效且美观的测试界面。它可用于向Web应用发送负载,并实时显示带有TUI(Text User Interface)动画的测试结果。这款工具受到了rakyll/hey的启发,并在其基础上进行了改进和创新。

二、功能与特点

1、实时TUI显示:

  • oha在测试过程中会实时显示测试结果,包括请求数、并发数、响应时间等关键指标。
  • TUI界面美观且直观,使得测试结果的查看和分析变得更加方便。

2、灵活的配置选项:

  • oha提供了丰富的配置选项,允许用户根据测试需求进行定制。
  • 用户可以指定请求数、并发数、HTTP版本、请求方法、自定义HTTP头等参数。

3、支持HTTP/1和HTTP/2:

  • oha支持HTTP/1和HTTP/2协议,能够满足不同Web应用的测试需求。
  • 在HTTP/2下,oha能够更高效地处理并发请求,提升测试性能。

4、动态URL生成:

  • oha支持使用正则表达式动态生成URL,使得测试场景更加多样化,例如:oha --rand-regex-url http://127.0.0.1/[a-z][a-z][0-9]
  • 用户可以通过配置选项来限制生成URL的最大重复次数,以避免无效的测试请求。

5、性能优化与结果分析:

  • oha通过优化查询调度和减少资源占用,提高了测试性能。
  • 测试结束后,oha会生成详细的测试结果报告,包括响应时间分布、成功率等信息,便于用户进行结果分析。

6、跨平台支持:

  • oha支持Linux、Windows和macOS等多个操作系统,方便用户在不同平台上进行测试。

三、安装与使用

oha的安装过程非常简单,用户可以通过cargo、Homebrew、winget等多种方式进行安装。安装完成后,用户可以通过命令行使用oha进行测试。

代码语言:javascript
代码运行次数:0
复制
# Linux/macOS,使用Cargo安装(需要先安装Rust工具链)
cargo install oha

# 使用Homebrew安装(适用于macOS)
brew install oha

# Windows,使用winget安装
winget install hatoo.oha

安装完成后,你可以运行基本测试,比如发送100个请求到目标URL:

代码语言:javascript
代码运行次数:0
复制
oha -n 100 https://127.0.0.1:5000

如果你想设置并发连接数为50,可以这样做:

代码语言:javascript
代码运行次数:0
复制
oha -c 50 https://127.0.0.1:5000

或者,如果你想运行持续时间为30秒的测试:

代码语言:javascript
代码运行次数:0
复制
oha -z 30s https://127.0.0.1:5000

当然,这样参数也可以组合使用,例如,要发送100个请求,并发数为50,持续时间30s,可以使用以下命令:

代码语言:javascript
代码运行次数:0
复制
oha -n 200 -c 50 -z 30s https://127.0.0.1:5000

执行完成后,oha能够实时显示请求的发送数量、响应时间、错误率等关键指标,让你对系统的性能表现一目了然。

此外,用户还可以根据需要配置其他选项,如指定HTTP方法、自定义HTTP头、设置请求超时等。

更多参数用法,可参考:

代码语言:javascript
代码运行次数:0
复制
Usage: oha [OPTIONS] <URL>

Arguments:
  <URL>  Target URL.

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.
      --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

四、小结

总之,oha 作为一款 Rust 开源 HTTP 性能测试工具,以其强大的功能、易用的特性、高效可靠的性能,为广大开发者和测试人员提供了一个出色的 HTTP 性能测试工具。

无论是在项目开发的初期进行性能预估,还是在上线前进行压力测试,亦或是在日常运维中对系统性能进行监控和优化,oha 都将是您手中的得力助手。

如果你正在寻找一款能够帮助你提升Web服务性能的测试工具,不妨试试oha,它可能会给你带来意想不到的惊喜。

项目开源地址:https://github.com/hatoo/oha

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2024-12-23,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 测试开发技术 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、项目简介
  • 二、功能与特点
  • 三、安装与使用
  • 四、小结
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档