线上第八期_性能测试实战
1. Jmeter Docker 分布式压测
Jmeter_Base_Image DockerFile
FROM openjdk:8-jre-slim
MAINTAINER PerfTest
# JMeter version
ARG JMETER_VERSION=5.0
# Install few utilities
RUN apt-get clean && \\
apt-get update && \\
apt-get -qy install \\
wget \\
telnet \\
iputils-ping \\
unzip
# Install JMeter
RUN mkdir /jmeter \\
&& cd /jmeter/ \\
&& wget https://archive.apache.org/dist/jmeter/binaries/apache-jmeter-$JMETER_VERSION.tgz \\
&& tar -xzf apache-jmeter-$JMETER_VERSION.tgz \\
&& rm apache-jmeter-$JMETER_VERSION.tgz
# Set JMeter Home
ENV JMETER_HOME /jmeter/apache-jmeter-$JMETER_VERSION/
# Add JMeter to the Path
ENV PATH $JMETER_HOME/bin:$PATH
Docker 相关命令
Docker build -t jmeterBaseImage . # 构建镜像
docker run -idt --name jmetermaster thperf/master /bin/bash
docker cp Testerhome/DockerRequest.jmx jmetermaster:/tmp/
docker run -idt --name jmeterslave1 thperf/slave /bin/bash docker run -idt --name jmeterslave2 thperf/slave /bin/bash
docker ps -a docker logs jmeterslave1
docker inspect --format '{{ .Name }} => {{ .NetworkSettings.IPAddress }}' $( docker ps -a - q)
Docker exec –it jmetermaster /bin/bash
jmeter -n -t /tmp/DockerRequest.jmx
jmeter -n -t /tmp/DockerRequest.jmx -R172.17.0.3,172.17.0.4
2. Jmeter 报表展示
基础报表展示
jmeter -n -t Desktop/TesterHome/DubboRequest.jmx -l result.jtl -e -o ./result
result 目录下查看 index.html
InfluxDB + Grafana 报告存储及展示
docker run -d -p 8083:8083 -p 8086:8086 -e ADMIN_USER="root" -e INFLUXDB_INIT_PWD="root" -e PRE_CREATE_DB="testerhome" --name influxdb tutum/influxdb:latest
docker run -d --name=grafana --link influxdb:influxdb -p 3000:3000 grafana/grafana
Jmeter → BackEndListener → InfluxDB: 设置 influxdb IP, 端口,数据库名
http://localhost:8083 网页可视化管理查看 InfluxDB 中时序数据。
http://localhost:8086 Restful API 操作 InfluxDB。
http://localhost:3000 Grafana 报表展示。
添加 InfluxDB datasource
Import Dashboard https://grafana.com/dashboards/5496
RPC 协议性能测试, Dubbo
https://github.com/dubbo/jmeter-plugins-for-apache-dubbo/tree/master/dist
Copy jmeter-plugins-dubbo-2.7.1-jar-with-dependencies.jar 到 Jmeter目录/lib/ext/ 下
使用 Dubbo Sample 完成 Zookeeper,直连方式测试。
zookeeper docker 命令
docker run -dit --name zookeeper --hostname zookeeper-host -p 2181:2181 jplock/zookeeper:latest
RPC 协议性能测试, Thrift
使用 0.9.3 版本 thrift 完成
brew install thrift@0.9
or Index of /dist/thrift/0.9.3
Demo.thrift 协议文件
namespace java com.hgwz.eight.service
// ComputeType
enum ComputeType {
ADD = 0;
SUB = 1;
MUL = 2;
DIV = 3;
}
// ComputeRequest
struct ComputeRequest {
1:required i64 x;
2:required i64 y;
3:required ComputeType computeType;
}
// Service Response
struct ComputeResponse {
1:required i32 errorNo;
2:optional string errorMsg;
3:required i64 computeRet;
}
service ComputeServer {
ComputeResponse getComputeResult(1:ComputeRequest request);
}
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_core</artifactId>
<version>5.0</version>
</dependency>
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_java</artifactId>
<version>5.0</version>
</dependency>