整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:

http接口压测工具wrk

http接口压测工具wrk

rk是一款简单的HTTP压测工具,当运行在单个多核CPU上时,它能够产生巨大的负载。

github:https://github.com/wg/wrk

国内镜像: https://gitee.com/mirrors/wrk

安装:

git clone https://github.com/wg/wrk.git
cd wrk
make
# 将可执行文件移动到 /usr/local/bin 位置
sudo cp wrk /usr/local/bin

查看版本:

[root@node1 wrk]# wrk -v

wrk 4.1.0-8-ga211dd5 [epoll] Copyright (C) 2012 Will Glozer

Usage: wrk <options> <url>

Options:

-c, --connections <N> Connections to keep open

-d, --duration <T> Duration of test

-t, --threads <N> Number of threads to use

-s, --script <S> Load Lua script file

-H, --header <H> Add header to request

--latency Print latency statistics

--timeout <T> Socket/request timeout

-v, --version Print version details

Numeric arguments may include a SI unit (1k, 1M, 1G)

Time arguments may include a time unit (2s, 2m, 2h)

可以看到wrk的用法,相对来说比较简单;

接下来使用wrk来压测下百度首页,

使用20个线程100个连接进行30s的压测:

wrk -t20 -c100 -d30s http://www.baidu.com

压测下本地的接口:

wrk -t20 -c100 -d30s --latency http://127.0.0.1:9000

以上是wrk的基本用法,还可以使用lua脚本进行个性化压测,有兴趣的可以研究下。


原文链接:https://river106.cn/posts/3e707d63.html

介:随着互联网安全规范的普及,使用 HTTPS 技术进行通信加密,实现网站和 APP 的可信访问,已经成为公认的安全标准。本文将介绍针对 HTTPS 协议做压力测试的关注点,以及使用 PTS 做 HTTPS 压测的技术优势和最佳实践。

作者:拂衣

引言

随着互联网安全规范的普及,使用 HTTPS 技术进行通信加密,实现网站和 APP 的可信访问,已经成为公认的安全标准。本文将介绍针对 HTTPS 协议做压力测试的关注点,以及使用 PTS 做 HTTPS 压测的技术优势和最佳实践。

常见的网站或者 APP 中需要做压测的 3 种场景:

  • 新开发的系统或功能上线前需要了解其性能水位情况。
  • 对系统进行技术调优、系统扩容前后通过压测进行性能比对。
  • 参加平台活动前对系统进行性能评估。

什么是 HTTPS

HTTPS 的英文全称是:Hyper Text Transfer Protocol over Secure Socket Layer,它是以安全为目标的 HTTP 通道。从全称上可以看出,它其实不是一种新的应用层协议,只是 HTTP 协议将通信接口用 SSL 替代了 TCP。HTTP 协议中,应用层 HTTP 直接与传输层 TCP 通信,在 HTTPS 协议中 ,应用层 HTTP 与 SSL 通信,SSL 再与传输层的 TCP 通信,具体如图:

?HTTPS 通过 SSL 层的加密,可以防止网站被篡改和劫持。下面我们简单看下 HTTPS 是如何进行加密解密的:

首先客户端和服务端会协商加密算法和协议版本。协商结束后,服务端发送公钥给客户端,客户端拿到公钥后,生成一个随机密码串(Pre-master secret),并通过公钥加密返回给服务端。服务端使用私钥解密密文后,得到此随机密码串(Pre-master secret),之后通过协商的随机数和加密算法,生成对称加密密钥。至此,双方得到了同一个密钥,后续使用此密钥实现对称加密解密。

?我们知道对称加密性能更好,但只要持有密钥,就能将劫持的密文解密,无法解决被劫持的问题。非对称加密相对更安全,但同时加密解密性能开销大。可以看出 HTTPS 在握手阶段使用了非对称加密,在后续的通信中使用了对称加密,既保证了安全性,又最大限度保证了性能。

HTTPS 压测的关注点

SSL 握手策略

HTTPS 在握手阶段有加密解密的过程,所以相比 HTTP 更消耗计算资源。压测引擎为了模拟海量用户执行请求,往往底层会在全局或线程维度,复用 TCP 连接和 SSL 握手信息。这提高了施压机的性能,但对希望每次循环模拟不同客户端行为的场景来说,施压机只模拟了足够的流量压力,并没有模拟足够的 SSL 握手计算压力,可能造成压力模拟不够准确的问题,如下图所示:

?因此,在 HTTPS 压测中,需要根据压测场景的具体业务逻辑,指定每次循环是否重置 SSL 握手状态,准确模拟 SSL 握手计算压力。

SSL 协议版本

HTTPS 压测,在客户端(施压机)和服务端进行 SSL 握手的第一步,客户端会告知给服务端自己支持的最高 SSL 协议版本,然后服务端会从自己和客户端支持版本的交集中,取最高的版本作为实际使用的 SSL 版本。

在压测时,需要评估出真实客户端的主流版本,并配置到施压引擎上。避免因 SSL 版本不同,造成 SSL 握手计算压力模拟不准确。

Why PTS—PTS 做 HTTPS 压测的优势

JMeter、Gatling、K6 等开源压测工具对 HTTPS 有不同程度的支持。JMeter[1]支持配置循环是否重置 SSL 握手状态,并且支持配置客户端 SSL 协议版本,但是默认不支持 HTTP2 协议。Gatling[2]默认每个虚拟用户共享 SSL 上下文,不支持控制循环重置 SSL 握手状态。K6[3]目前只支持设置 SSL 协议版本。

PTS 作为云上压测工具,支持如下 HTTPS 相关特性:

  • 支持 HTTP2
    HTTP2 相比较 HTTP1.1 性能大幅提升,且目前主流浏览器均已支持 HTTP2 协议。为了模拟真实客户端,建议使用 HTTP2 协议。
  • 支持设置 SSL 握手策略
    支持配置循环是否重置 SSL 握手状态,可以根据业务场景,选择是否重置。
  • 支持指定 SSL 协议版本

使用 PTS 压测,可以更真实的模拟客户端发起的 HTTPS 压力,使压测结果更可信。

How to—如何用 PTS 做 HTTPS 压测

设置 SSL 握手策略

?对于 HTTPS 压测,在串联链路每次循环时,需要选择是否重置 SSL 连接状态。如果选择重置,在串联链路每一次循环执行时,会重新初始化 SSL 状态,这样可以更准确模拟每次循环代表不同用户的压测场景,同时会对施压机带来一定的性能开销。

使用场景

  • 场景一:HTTPS 压测,希望模拟 100 个用户登录,同时保持这 100 个用户不断重复访问系统。此时串联链路每次循环执行,模拟的是同一个虚拟用户的行为。应将此开关置为“否”,然后设置并发数为 100。
  • 场景二:HTTPS 压测,希望模拟 5 分钟内,每个时刻都有 100 个不同用户对系统访问。此时串联链路每次循环执行,模拟的是不同虚拟用户的行为。为了保证压力模拟真实性,应将此开关置为“是”,然后设置并发数为 100。同时因为打开此开关后,施压机有额外的性能开销,建议扩展施压机IP数。

设置 SSL 协议版本

这里列出一些常用浏览器对 SSL 版本的支持情况供您参考:

?可以看出,主流浏览器在 2018~2020 年前后都支持了 TLSv1.3。因此,如果您的压测场景模拟的客户端较新,建议您选择 TLSv1.3 作为 SSL 版本;相反,如果您的压测场景需要模拟旧版本的浏览器客户端,建议您选择 TLSv1.2 作为 SSL 版本。

如何录制 HTTPS 流量

各压测工具都提供了基于代理的流量录制工具,方便录制下客户端的流量,并快速构建压测脚本。对于 HTTPS 协议的录制,除了配置代理,还需要信任证书,操作比较复杂。

PTS 提供了免配置证书的录制方案:浏览器插件,支持快速录制 HTTPS 流量,解密并转换为 PTS 压测场景,同时支持导出为 JMeter 脚本,欢迎下载[4]使用,详细操作可参考文档[5]

?同时针对移动流量录制,PTS 提供了云真机和本地设备 2 种方案。其中云真机已预置 PTS 代理配置,支持在浏览器操作手机,录制流量,无需配置代理和证书,详细操作可参考文档[6]

?总结

综上,本文主要阐述了:

  • 什么是 HTTPS
  • HTTPS 压测中的注意点
  • 如何用 PTS 做 HTTPS 压测

更多交流,欢迎进钉钉群沟通,PTS 用户交流群号:11774967

同时,PTS 全新售卖方式来袭,基础版价格直降 50%!百万并发价格只需 6200!更有新用户 0.99 体验版、VPC 压测专属版,欢迎大家选购!

参考文档

[1] JMeter(官方文档):

https://jmeter.apache.org/usermanual/component_reference.html?spm=a2c6h.12873639.article-detail.4.6d4a7ca0EKzFeR#HTTP_Request

[2] Gatling(官方文档):

https://gatling.io/docs/gatling/reference/current/http/ssl/

[3] K6:

https://k6.io/docs/using-k6/options/#tls-version

[4] 下载(PTS HTTPS录制器插件):

https://chrome.google.com/webstore/detail/alibaba-cloud-pts%E5%BD%95%E5%88%B6%E5%99%A8/noonnhdncblnaknhoebaglpcihelliff

[5] 文档(PTS 录制器使用文档—Chrome 浏览器场景):

https://help.aliyun.com/document_detail/187749.html

[6] 文档(PTS 录制器使用文档—Android 手机端场景):

https://help.aliyun.com/document_detail/72519.html

[7] PTS HTTPS设置文档:

https://help.aliyun.com/document_detail/143194.html

原文链接:301 Moved Permanently

本文为阿里云原创内容,未经允许不得转载。

heck Web Performance 测试下网络性能

下面都是一些在线的站点,可以尝试看看,个人感觉还不错。测试下网络性能:

https://www.17ce.com
https://www.tingyun.com/tingyun_network.html
https://gtmetrix.com
https://tools.pingdom.com
https://www.dotcom-tools.com/website-speed-test.aspx
https://webspeedtest.cloudinary.com
https://www.webpagetest.org
https://www.dareboost.com/en/analysis

学习两个压测命令:

ab是apachebench命令的缩写, 默认mac下都已经安装了

?  ~ /usr/sbin/ab --help
/usr/sbin/ab: wrong number of arguments
Usage: /usr/sbin/ab [options] [http[s]://]hostname[:port]/path
Options are:
    -n requests     Number of requests to perform
    -c concurrency  Number of multiple requests to make at a time
    -t timelimit    Seconds to max. to spend on benchmarking
                    This implies -n 50000
    -s timeout      Seconds to max. wait for each response
                    Default is 30 seconds
    -b windowsize   Size of TCP send/receive buffer, in bytes
    -B address      Address to bind to when making outgoing connections
    -p postfile     File containing data to POST. Remember also to set -T
    -u putfile      File containing data to PUT. Remember also to set -T
    -T content-type Content-type header to use for POST/PUT data, eg.
                    'application/x-www-form-urlencoded'
                    Default is 'text/plain'
    -v verbosity    How much troubleshooting info to print
    -w              Print out results in HTML tables
    -i              Use HEAD instead of GET
    -x attributes   String to insert as table attributes
    -y attributes   String to insert as tr attributes
    -z attributes   String to insert as td or th attributes
    -C attribute    Add cookie, eg. 'Apache=1234'. (repeatable)
    -H attribute    Add Arbitrary header line, eg. 'Accept-Encoding: gzip'
                    Inserted after all normal header lines. (repeatable)
    -A attribute    Add Basic WWW Authentication, the attributes
                    are a colon separated username and password.
    -P attribute    Add Basic Proxy Authentication, the attributes
                    are a colon separated username and password.
    -X proxy:port   Proxyserver and port number to use
    -V              Print version number and exit
    -k              Use HTTP KeepAlive feature
    -d              Do not show percentiles served table.
    -S              Do not show confidence estimators and warnings.
    -q              Do not show progress when doing more than 150 requests
    -l              Accept variable document length (use this for dynamic pages)
    -g filename     Output collected data to gnuplot format file.
    -e filename     Output CSV file with percentages served
    -r              Don't exit on socket receive errors.
    -m method       Method name
    -h              Display usage information (this message)
    -I              Disable TLS Server Name Indication (SNI) extension
    -Z ciphersuite  Specify SSL/TLS cipher suite (See openssl ciphers)
    -f protocol     Specify SSL/TLS protocol
                    (TLS1, TLS1.1, TLS1.2 or ALL)
    -E certfile     Specify optional client certificate chain and private key
    

? ~ /usr/sbin/ab -n 100 -c 5 http://www.baidu.com/

This is ApacheBench, Version 2.3 <$Revision: 1843412 $>

Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/

Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.baidu.com (be patient).....done

Server Software: BWS/1.1

Server Hostname: www.baidu.com

Server Port: 80

Document Path: /

Document Length: 280696 bytes

Concurrency Level: 5

Time taken for tests: 6.152 seconds

Complete requests: 100

Failed requests: 96

(Connect: 0, Receive: 0, Length: 96, Exceptions: 0)

Total transferred: 28187420 bytes

HTML transferred: 28071381 bytes

Requests per second: 16.25 [#/sec] (mean)

Time per request: 307.617 [ms] (mean)

Time per request: 61.523 [ms] (mean, across all concurrent requests)

Transfer rate: 4474.20 [Kbytes/sec] received

Connection Times (ms)

min mean[+/-sd] median max

Connect: 34 52 19.6 46 152

Processing: 151 248 60.5 233 443

Waiting: 37 57 20.6 51 151

Total: 186 300 67.6 286 504

Percentage of the requests served within a certain time (ms)

50% 286

66% 323

75% 341

80% 354

90% 392

95% 443

98% 502

99% 504

100% 504 (longest request)

推荐另一个个人感觉这个更好用一些

brew search wrk

==> Formulae

wrk ? wrk-trello

brew install wrk 来安装