Jmeter stress test Http reqest and JDBC request

Jmeter Overview

scenes to be used

  • Web - HTTP, HTTPS (Java, NodeJS, PHP, ASP.NET, …)
  • Database via JDBC
  • SOAP / REST Webservices
  • FTP
  • LDAP Lightweight Directory Access Protocol
  • Message-oriented middleware (MOM) via JMS
  • Mail - SMTP(S), POP3(S) and IMAP(S)
  • TCP etc.

installation

  • http://jmeter.apache.org/download_jmeter.cgi(win download zip, linux download tgz)
  • We recommended to install JDK environment, keytool tool although JRE can, but measured pressure inside the https requires JDK

Jmeter catalog file

  • bin: core executable file that contains configuration

    • jmeter.bat: windows startup file:
    • jmeter: mac or linux boot files:
    • jmeter-server: mac boot file or distributed pressure sensing using Liunx
    • jmeter-server.bat: mac boot file or distributed pressure sensing using Liunx
    • jmeter.properties: core profile
  • extras: Plug expansion pack

  • lib: core dependencies

  • ext: core package

  • junit: Unit test pack

Jmeter languages ​​English switch

  • Console modification
    • menu -> options -> choose language
  • Modify the configuration file
    • bin directory -> jmeter.properties
    • Default # language = en changed language = zh_CN

Jmeter common functions

Thread Group
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

Common components Http request
Here Insert Picture Description
Here Insert Picture Description
JDBC requests
Here Insert Picture Description
Here Insert Picture Description

Jmeter test Http request

  • Step one: Add -> threads-> thread group (control the overall concurrency)

    • Threads: the number of virtual users. A virtual user occupies one process or thread
    • 准备时长(Ramp-Up Period(in seconds)):全部线程启动的时长,比如100个线程,20秒,则表示20秒内100个线程都要启动完成,每秒启动5个线程
    • 循环次数:每个线程发送的次数,假如值为5,100个线程,则会发送500次请求,可以勾选永远循环
  • 步骤二:线程组->添加-> Sampler(采样器) -> Http请求 (一个线程组下面可以增加几个Sampler)

    • 名称:采样器名称

    • 注释:对这个采样器的描述

    • web服务器:

      • 默认协议是http
      • 默认端口是80
      • 服务器名称或IP :请求的目标服务器名称或IP地址
    • http请求:

      • 路径:服务器URL(相对路径,例如 /user)
    • 要发送请求体时

      Here Insert Picture Description

  • 步骤三:线程组->添加->监听器->察看结果树(查看每条测试结果)

  • 步骤四:线程组->添加->监听器->聚合报告(查看统计的测试结果)

    lable: sampler的名称
    Samples: 一共发出去多少请求,例如10个用户,循环10次,则是 100
    Average: 平均响应时间
    Median: 中位数,也就是 50% 用户的响应时间
    90% Line : 90% 用户的响应不会超过该时间 (90% of the samples took no more than this time. The remaining samples at least as long as this)
    95% Line : 95% 用户的响应不会超过该时间
    99% Line : 99% 用户的响应不会超过该时间
    min : 最小响应时间
    max : 最大响应时间			
    Error%:错误的请求的数量/请求的总数
    Throughput: 吞吐量——默认情况下表示每秒完成的请求数(Request per Second) 可类比为qps
    KB/Sec: 每秒接收数据量
    

使用断言

  • 增加断言: Http请求 -> 添加 -> 断言 -> 响应断言

    • apply to(应用范围):
      • Main sample only: 仅当前父取样器 进行断言,一般一个请求,如果发一个请求会触发多个,则就有sub sample(比较少用)
    • 要测试的响应字段:
      • 响应文本:即响应的数据,比如json等文本
      • 响应代码:http的响应状态码,比如200,302,404这些
      • 响应信息:http响应代码对应的响应信息,例如:OK, Found
      • Response Header: 响应头
    • 模式匹配规则:
      • 包括:包含在里面就成功
      • 匹配:响应内容完全匹配,不区分大小写
      • equals:完全匹配,区分大小写
  • 断言结果监听器: Http请求-> 添加 -> 监听器 -> 断言结果

    • 里面的内容是sampler采样器的名称
    • 断言失败,查看结果树任务结果颜色标红(通过结果数里面双击不通过的记录,可以看到错误信息)
  • 每个sample下面可以加单独的结果树,然后同时加多个断言,最外层可以加个结果树进行汇总

自定义变量

  • 定义变量:线程组->add -> Config Element(配置原件)-> User Definde Variable(用户定义的变量)

  • 引用方式 ${XXX},在接口中变量中使用

CSV可变参数

  • 添加csv文件:线程组->add -> Config Element(配置原件)-> CSV data set config (CSV数据文件设置)

    • 也可以时txt文件,但必须把分割符设置好
    • 如果是多个参数需要同时引用,则在CSV数据文件里面设置加多个字段
      Variabled names(comma-delitited): csv_name,csv_pwd
  • 引用方式 ${XXX},在接口中变量中使用

数据库压测

  • 步骤一:Thread Group -> add -> sampler -> jdbc request

  • 步骤二:在测试计划添加mysql-connector-java-5.1.30.jar(jar包添加)
    Here Insert Picture Description

  • 步骤三:线程组->添加->监听器->察看结果树(查看每条测试结果)

  • 步骤四:线程组->添加->监听器->聚合报告(查看统计的测试结果)

  • 步骤五:线程组->添加->取样器->调试取样器(查看自定的结果集)

  • 步骤五:JDBC request -> add -> Config Element -> JDBC connection Configuration(配置数据库连接)

    • 核心配置
      1、Max Number of connections : 最大连接数
      2、MAX wait :最大等待时间
      3、Auto Commit: 是否自动提交事务
      4、DataBase URL : 数据库连接地址 jdbc:mysql://127.0.0.1:3306/blog
      5、JDBC Driver Class : 数据库驱动,选择对应的mysql
      6、username:数据库用户名
      7、password:数据库密码
  • 步骤:配置JDBC request

    • Parameter Description:
      1, variable name of the pool declared in JDBC Connection the Configuration (and configuration files with the same name in order to show support)
      2, Query Type: query type
      3, parameter values: Parameter Value (when Query Type is Perpared ...)
      4, the Parameter types: parameter type (and parameter values corresponding to)
      . 5, variable names: SQL execution result to be packaged as a result set variable names
      6, result variable name: all results as an object store name
      7, query timeouts: query timeout
      8, handle results : result set
    • note
      • The end of the sql not increase ";"
      • variable names, result variable names, handle results To view the results through the debugger sampler
Published 109 original articles · won praise 47 · views 30000 +

Guess you like

Origin blog.csdn.net/weixin_43934607/article/details/104228883