  

Promethues + Node_Exporter 机器
监控
. Spring JVMMysqlRedisMongodb
监控
. 回顾场景和服务端监控
压测报告与结果分析
OtherNginx 解析 Get URL 方式压测
电商系统压测实战
JMeter 客户端异常搜集filebeat + elk
Jmeter 优化 Tips
ü Run From Command Line:
ü Avoid Listeners:
ü Increase JVM Heap Space:
ü Use the latest JMeter version:
ü Use Regexp Variable Extractors to extract data from responses:
ü Simulate a reasonable amount of threads per machine: avoid
simulating more than 1000 users per machine. Usually, the bottleneck
is the network connection (1Gbps on best Cloud instances). The JVM
doesn’t work well with more than 2000 threads.
ü Distribute load over average machines: avoid using few machines
with exceptional hardware (like 16 cores / 128GB RAM), stick to
average machines (4 cores, 16GB RAM) and use more machines
instead. JMeter cannot take advantage of so much RAM, because
JVMs doesn’t work well with Xmx greater than 16GB.
Jmeter 优化 Tips
ü Generate Reports after run: use the outputted JTL files to create reports once the load test is
finished. Building the report requires a great amount of CPU and memory resources.
ü Network is the bottleneck in most cases: Which means it’s better to have medium machines with
great network connectivity instead of powerful machines with low network capabilities.
ü Avoid BeanShell scripts: those scripts use way more CPU to execute than Groovy scripts
embedded in JSR223 samplers. Stick to JSR223 samplers if you need to run custom logic.
ü Do not run in distributed mode: distributed mode works well with 20-30 machines, maybe up to
40-50 machines if you have luck. This will limit you to 20-50k concurrent users. Instead, run each
JMeter instance independently by sending the JMX before starting the test, and retrieving the JTL
files after finish. The RMI protocol used by JMeter to communicate between the load generators and
the controller is not very efficient.
ü Monitor tested servers: The key to find performance bottlenecks is to monitor the tested backend
servers which running the load test. You will be able to correlate performance degradations with
server-side issues. This way, you can fix the performance issue on backend side quicker. Tools
like Perfmon are recommended.
ü Run load tests in-house first: this may sound weird, but the nearer the load generators are from
the tested servers, the less factors are likely to influence the performance testing results. On-
Premise load tests avoid internet connectivity issues and can use large internal networks (usually 1
to 10 Gbps). Once the servers are well-performing with on-premise testing, testing from the cloud
can reveal internet networking issues. This way, you can separate server issues from network
issues.
JMeter命令行测试
XX:MaxMetaspaceSize(jdk8的参数)
这个参数用于限制Metaspace增长的上限,防止因为
某些情况导致Metaspace无限的使用本地内存,如果超过
设定的值就会触发Full GC,此值默认没有限制,应取决于
系统内存的大小,JVM会动态地改变此值。例如:-
XX:MaxMetaspaceSize=4096M
-Xmx2048m
设置堆内存最大值为512m
-Xms1g
设置堆内存最小值1g(ps:-Xms-Xmx实际上是 -
XX:InitialHeapSize
-XX:MaxHeapSize 的缩写。例如:-
XX:InitialHeapSize=128m -XX:MaxHeapSize=2g )
JMeter 插件安装介绍
Plugins Manager https://jmeter-plugins.org/install/Install/
JMeter 插件安装介绍
Plugins Manager
JMeter 插件安装介绍
Concurrency Thread Group
10个线程
60 s 时间达到最大线程
其中有 3 次阶梯平均增长
并在最大线程持续 60s
JMeter 插件安装介绍
Ultimate Thread Group
10个线程
60 s 时间达到最大线程
其中有 3 次阶梯增长
最后一次阶梯增长 5 个线程
并在最大线程持续 60s
JMeter 插件安装介绍
Arrivals Thread Group
10 QPS
60 s 时间达到最大 QPS
其中有 3 次阶梯增长
最后一次阶梯增长 5 QPS
并在最大 QPS 持续 60s
JMeter 插件安装介绍
Free-Form Arrivals Thread Group
可随意定制的 QPS 控制器
JMeter 插件安装介绍
Autostop Listener:
尤其在 CI 运行中,或线上压测时,需即时止损
JMeter 日志搜集
分享课题:电商系统压测实战
01
ElasticSearch+FileBeats+
Kibana
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-oss-7.5.1-darwin-x86_64.tar.gz --no-
check-certificate
tar -xzf filebeat-oss-7.5.1-darwin-x86_64.tar.gz
Vi filebeat.yaml
Docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -idt -p 9200:9200 -p 5601:5601
nshou/elasticsearch-kibana
View Result in Kibana
几种方式的 Listener
Result Listener 记录日志。
JSR223 Listener
if(prev.getResponseCode() != 200)
{
log.error(prev.getResponseDataAsString());
}
ctx - ( JMeterContext) - gives access to the context
vars - ( JMeterVariables) - gives read/write access to variables: vars.get(key); vars.put(key,val); vars.putObject("OBJ1",new Object());
props - (JMeterProperties - class java.util.Properties) - e.g. props.get("START.HMS"); props.put("PROP1","1234");
prev - ( SampleResult) - gives access to the previous SampleResult (if any)
ctx http://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterContext.html
vars http://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterVariables.html
prevhttp://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html
Promethues 机器监控
分享课题:电商系统压测实战
02
电商系统压测实战
Promethues 安装
Docker Pull prom/prometheus
docker run --name prometheus -d -p 9090:9090 --privileged=true -v
/home/hogwarts/mydata/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
http://47.93.32.161:9090/targets
电商系统压测实战
Node Exporter 安装
wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-
0.18.1.linux-amd64.tar.gz --no-check-certificate
docker cp ../node_exporter-0.18.1.linux-amd64 <docker name>:/
http://47.93.32.161:9100/metrics
node_cpu:系统CPU使用量
node_disk*:磁盘IO
node_filesystem*:文件系统用量
node_load1:系统负载
node_memeory*:内存使用量
node_network*:网络带宽
node_time:当前系统时间
go_*node exportergo相关指标
process_*node exporter自身进程相关运行指标
安装使用 Node Exporter 并查看配置报表
Spring JVMMysqlRedisMongodb
分享课题:电商系统压测实战
03
电商系统压测实战- Spring 监控
application-prod.yml
电商系统压测实战- Spring 监控
Add Mvn Package,
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.3.5</version>
</dependency>
Mvn package
Push Images 到远程仓库
Docker Image 暴露对外端口:
docker run -p 9100:9100 -p 8001:8001 -p 8085:8085 --name mall-portal --link mall-mysql:db --
link mall-redis:redis --link mongo:mongo --link rabbitmq:rabbit -v /etc/localtime:/etc/localtime -v
/mydata/app/portal/logs:/var/logs -d mall/mall-portal:1.0-SNAPSHOT
电商系统压测实战- Spring 监控
电商系统压测实战- Mysql 监控
GRANT REPLICATION CLIENT, PROCESS ON *.* to 'exporter'@'%' identified by 'exporter';GRANT SELECT ON
performance_schema.* TO 'exporter'@'%';flush privileges;docker run -d
--restart=always --name mysqld-exporter -p 9104:9104
-e DATA_SOURCE_NAME="exporter:exporter@(47.93.32.161:8306)/" prom/mysqld-exporter
电商系统压测实战- Consul 实时加载
Consul 方式,无需重启加载新指标
docker run --restart=always --name consul -d -p 8500:8500 consul
curl -X PUT -d '{"id": "mysql01","name": "mysql01","address": "47.93.32.161","port": 9104,"tags": ["mall"],"checks": [{"http
http://localhost:8500/v1/agent/service/registerhttp://47.93.32.161:9121/curl -X PUT -d '{"id": "redis01","name": "redis01","address": "47.93.32.161","port": 9121,"tags": ["
"http://47.93.32.161:9121/","interval": "5s"}]}' http://localhost:8500/v1/agent/service/registercurl -X PUT -d '{"id": "mongo01","name": "mongo01","address": "47.93.32.161","port": 9001,"tags": ["
"http://47.93.32.161:9001/","interval": "5s"}]}' http://localhost:8500/v1/agent/service/registercurl -X PUT -d '{"id": "node01","name": "node01","address": "47.93.32.161","port": 9100,"tags": ["
"http://47.93.32.161:9100/","interval": "5s"}]}' http://localhost:8500/v1/agent/service/registercurl -X PUT -d '{"id": "spring01","name": "spring01","address": "47.93.32.161","port": 8001,"tags": ["
"http://47.93.32.161:8001/actuator/prometheus","interval": "5s"}]}' http://localhost:8500/v1/agent/service/register
电商系统压测实战- redis 监控
wget https://github.com/prometheus/prometheus/releases/download/v2.1.0/prometheus-2.1.0.linux-amd64.tar.gz
https://grafana.com/grafana/dashboards/4074
./mongodb_exporter -mongodb.uri mongodb://47.93.32.161:27017/admin
压测场景分析及演练
分享课题:电商系统压测实战
04
电商系统压测实战
场景一:
单模块级别压测:
用户登陆场景
场景二:
用户历史记录的浏览场景
聚合实例场景:
用户聚合场景
电商实战用户注册模块
用户获取验证码 -> GET /sso/getAuthCode
使用注册码发起注册 -> POST /sso/register
用户使用匹配账户密码登陆 -> POST /sso/login
其中接口场景比例为 1:1:1 关系
获取的鉴权信息需保存后为后续请求做测试数据支持
电商实战用户注册模块
用户获取验证码 -> GET /sso/getAuthCode
使用注册码发起注册 -> POST /sso/register
Show Java Code
用户使用匹配账户密码登陆 -> POST /sso/login
其中接口场景比例为 1:1:1 关系
获取的鉴权信息需保存后为后续请求做测试数据支持
FrondEnd
Nginx Server
Nginx Server Mysql
Redis
Redis
FrondEnd
电商系统之日常场景
从业务角度抽离基础日常场景:
1.用户登陆 (GET /sso/refreshToken). 20
2.浏览首页 20
GET /home/content
GET /home/productCateList/{parentId}
GET /home/recommendProductList
GET /home/subjectList
2.1 增加浏览POST /member/readHistory/create
记录 (自动触发) 10
3.添加商品/购物车 4
POST /cart/add
4.下订单,结算 2
GET /cart/list
GET /cart/list/promotion
POST /order/generateConfirmOrder
POST /order/generateOrder
5. 退出 (退出不代表登出)
比例模型按预计比例预估
系统压测报告
分享课题:电商系统压测实战
05
电商系统压测实战
场景一:
单模块级别压测:
用户登陆场景
场景二:
用户历史记录的浏览场景
聚合实例场景:
用户聚合场景
Nginx 快速生成压测内容
分享课题:电商系统压测实战
06
电商系统压测实战
报告展示和生成
全链路压测介绍
分享课题:电商系统压测实战
07
电商系统压测实战
展示 Nginx 日志 快速反解
󰍿󰆡󰂷
󰍿󰆡󰂷



󰂈
󰅣󰉝
󰑚
󰍿󰆡󰂷
󰐩󰋿󰑎
感谢参与,欢迎填写调查问卷领取公开课PPT
请添加小助手,回复「公开课」