HJ3-24.9 电商压测实战

JMeter 命令行测试

  • XX:MaxMetaspaceSize(jdk8的参数)
    这个参数用于限制 Metaspace 增长的上线,防止因为某些情况导致 Metaspace 无限的使用本地内存,如果超过设定的值就会触发 Full GC,此值默认没有限制,应取决于系统内存的大小,JVM会动态地改变此值。例如:-XX:MaxMetaspaceSize=4096M
  • -Xmx2048m
    设置堆内存最大值为 512m
  • Xms 1g
    设置堆内存最小值1g(ps:-Xms 和 -Xmx 实际上是 -XX:InitialHeapSize 和 -XX:MaxHeapSize 的缩写。例如:-XX:InitialHeapSize=128m -XX:MaxHeapSize=2g)

JMeter 插件安装介绍

Plugins Manager https://jmeter-plugins.org/install/Install/

JMeter Install Plugins
Plugins Manager
Custom Thread Groups
Auto-Stop Listener
HTTP/2 Plugin
PerfMon
Random CSV Data Set
Redis Data Set
添加 Concurrency Thread Group
Concurrency Thread Group
添加 Ultimate Thread Group
Ultimate Thread Group
添加 Arrivals Thread Group
Arrivals Thread Group
添加 Free-Form Arrivals Thread Group
Free-Form Arrivals Thread Group
添加 AutoStop Listener

AutoStop Listener:尤其在 CI 运行中,或线上压测时,需即时止损


AutoStop Listener

1、JMeter 客户端异常搜集 filebeat + elk

ElasticSearch + FileBeats + Kibana

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

几种方式的 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
props-(JMeterProperties - class java.util.Properties)-e.g. props.get("START.HMS");props.put("PROP1","123")
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
prev:
http://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html

2、Promethues + Node_Exporter 机器监控

Promethues 安装
Docker Pull prom/promethues

docker run --name prometheus -d -p 9090:9090 --privileged=true -v
/home/mydata/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus

http://47.93.32.161:9090/targets
scrape_configs
  job_name:prometheus
  static_configs:
    targets:['localhost:9090']
    labels:
      instance:prometheus

  job_name:linux
  static_configs:
    targets:['47.93.32.161:9100']
    labels:
      instance:node

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 :/

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 exporter 中 go 相关指标
process_
:node exporter 自身进程相关运行指标

3、Spring JVM、Mysql、Redis、Mongodb 监控

Add Mvn Package


  io.micrometer
  micrometer-registry-prometheus
  1.3.5

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/protal/logs:/var/logs -d mall/mall-portal:1.0-SNAPSHOT

Mysql 监控

GRANT REPLICATION CLIENT,PROCESS ON *.* too 'exporter'@'%' identified by 'exporter';
GRANT SELECT ON performance_schme.* 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 服务发现方式,无需重启加载新指标

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://47.93.32.161:9104/,interval:""5s"}]}' https://localhost:8500/v1/agent/service/register
curl -X PUT -d '{"id":"redis01","name":"redis01","address":"47.93.32.161","port":9121,"tags":["mall"],"checks":[{"http":"http://47.93.32.161:9121/,interval:""5s"}]}' https://localhost:8500/v1/agent/service/register
curl -X PUT -d '{"id":"mongo01","name":"mongo01","address":"47.93.32.161","port":9001,"tags":["mall"],"checks":[{"http":"http://47.93.32.161:9001/,interval:""5s"}]}' https://localhost:8500/v1/agent/service/register
curl -X PUT -d '{"id":"node01","name":"node01","address":"47.93.32.161","port":9100,"tags":["mall"],"checks":[{"http":"http://47.93.32.161:9100/,interval:""5s"}]}' https://localhost:8500/v1/agent/service/register
curl -X PUT -d '{"id":"spring01","name":"spring01","address":"47.93.32.161","port":8001,"tags":["mall"],"checks":[{"http":"http://47.93.32.161:8001/,interval:""5s"}]}' https://localhost:8500/v1/agent/service/register
# mongoldb/redis
./redis_exporter -redis.addr 47.93.32.161:6379 & -web.listenaddress 0.0.0.0:9122
./mongodb_exporter-linux-arm64 -mongodb.uri mongoldb://47.93.32.161:27017/admin

https://github/prometheus/mysqld_exporter/releases
https://github/oliver006/redis_exporter/releases
https://github.com/percona/mongodb_exporter/releases

4、回顾场景和服务端监控

5、压测报告与结果分析

6、Nginx 解析 Get URL 方式压测

你可能感兴趣的:(HJ3-24.9 电商压测实战)