• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

jmeter==docker安装nginx , jmeter压力测试并发20个请求在1秒内发出

武飞扬头像
一个java开发
帮助3

docker安装nginx

docker pull nginx

# 创建挂载目录
mkdir -p /home/nginx/conf
mkdir -p /home/nginx/log
mkdir -p /home/nginx/html

# 生成容器
docker run --name nginx -p 9001:80 -d nginx
# 将容器nginx.conf文件复制到宿主机
docker cp nginx:/etc/nginx/nginx.conf /home/nginx/conf/nginx.conf
# 将容器conf.d文件夹下内容复制到宿主机
docker cp nginx:/etc/nginx/conf.d /home/nginx/conf/conf.d
# 将容器中的html文件夹复制到宿主机
docker cp nginx:/usr/share/nginx/html /home/nginx/

# 直接执行docker rm nginx或者以容器id方式关闭容器
# 找到nginx对应的容器id
docker ps -a
# 关闭该容器
docker stop nginx
# 删除该容器
docker rm nginx
 
修改NGINX配置文件,使得一秒可以接受2个请求,1个请求缓冲区。所以一秒可以接受3个请求。

  1.  
    [root@localhost ~]# cd /home/nginx/conf/
  2.  
    [root@localhost conf]#
  3.  
    [root@localhost conf]# ls
  4.  
    conf.d nginx.conf
  5.  
    [root@localhost conf]# vim nginx.conf
  6.  
    [root@localhost conf]# cat nginx.conf
  7.  
     
  8.  
    user nginx;
  9.  
    worker_processes auto;
  10.  
     
  11.  
    error_log /var/log/nginx/error.log notice;
  12.  
    pid /var/run/nginx.pid;
  13.  
     
  14.  
     
  15.  
    events {
  16.  
    worker_connections 1024;
  17.  
    }
  18.  
     
  19.  
     
  20.  
    http {
  21.  
     
  22.  
    limit_req_zone $binary_remote_addr zone=mylimit:10m rate=2r/s;
  23.  
    limit_conn_zone $binary_remote_addr zone=perid:10m;
  24.  
    limit_conn_zone $server_name zone=preserver:10m;
  25.  
     
  26.  
    include /etc/nginx/mime.types;
  27.  
    default_type application/octet-stream;
  28.  
     
  29.  
    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  30.  
    '$status $body_bytes_sent "$http_referer" '
  31.  
    '"$http_user_agent" "$http_x_forwarded_for"';
  32.  
     
  33.  
    access_log /var/log/nginx/access.log main;
  34.  
     
  35.  
    sendfile on;
  36.  
    #tcp_nopush on;
  37.  
     
  38.  
    keepalive_timeout 65;
  39.  
     
  40.  
    #gzip on;
  41.  
     
  42.  
    include /etc/nginx/conf.d/*.conf;
  43.  
    }
  1.  
    [root@localhost conf.d]# cd /home/nginx/conf/conf.d
  2.  
    [root@localhost conf.d]# ls
  3.  
    default.conf
  4.  
    [root@localhost conf.d]# cat default.conf
  5.  
    server {
  6.  
    listen 80;
  7.  
    listen [::]:80;
  8.  
    server_name localhost;
  9.  
     
  10.  
    #access_log /var/log/nginx/host.access.log main;
  11.  
     
  12.  
    location / {
  13.  
    root /usr/share/nginx/html;
  14.  
    index index.html index.htm;
  15.  
     
  16.  
    limit_req zone=mylimit burst=1 nodelay;
  17.  
    limit_conn perid 20;
  18.  
    limit_conn preserver 10000;
  19.  
    }
  20.  
     
  21.  
    #error_page 404 /404.html;
  22.  
     
  23.  
    # redirect server error pages to the static page /50x.html
  24.  
    #
  25.  
    error_page 500 502 503 504 /50x.html;
  26.  
    location = /50x.html {
  27.  
    root /usr/share/nginx/html;
  28.  
    }
  29.  
     
  30.  
    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  31.  
    #
  32.  
    #location ~ \.php$ {
  33.  
    # proxy_pass http://127.0.0.1;
  34.  
    #}
  35.  
     
  36.  
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  37.  
    #
  38.  
    #location ~ \.php$ {
  39.  
    # root html;
  40.  
    # fastcgi_pass 127.0.0.1:9000;
  41.  
    # fastcgi_index index.php;
  42.  
    # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  43.  
    # include fastcgi_params;
  44.  
    #}
  45.  
     
  46.  
    # deny access to .htaccess files, if Apache's document root
  47.  
    # concurs with nginx's one
  48.  
    #
  49.  
    #location ~ /\.ht {
  50.  
    # deny all;
  51.  
    #}
  52.  
    }

 启动NGINX

docker run -p 9002:80 --name nginx -v /home/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /home/nginx/conf/conf.d:/etc/nginx/conf.d -v /home/nginx/log:/var/log/nginx -v /home/nginx/html:/usr/share/nginx/html -d nginx:latest

curl 127.0.0.1:9002

学新通

学新通 

=========================================================

jemter测试

学新通

 在一秒内发出10个请求===========

添加线程组,设置参数10 1 1

学新通

 学新通

添加HTTP请求并设置协议 地址端口 路径 编码

 学新通

给HTTP请求添加监听器: 第一个为结果树,第二个为汇总报告

学新通

学新通

 点击绿三角启动访问

学新通

查看结果树,一秒内发出的10个请求绿了3个

学新通

查看汇总报告,10个请求,70%异常,也就是30%正常,刚好3个正常。 

 学新通

=======================================================

选中结果树和汇总报告,直接delete,然后新建

将线程组的线程数改成100和1000, 发现100个异常了97%,也就是正常请求到了3个。

学新通

 1000个异常了99.5%,正常的就是5个,因为有个缓冲区,本来应该是3个,可能多放过去了2个。也可能是电脑性能导致这1000个不是在1秒内到达NGINX的。

=============================================================

修改NGINX配置文件,取消缓冲区。

学新通

重启NGINX

将线程组个数设置成10或者20,删掉再添加结果数,可以发现成功个数都是2,不是之前的3个了。

 学新通

==================================================

然后修改nginx.conf,设置rate=50r/s ,并且重启nginx

然后jmeter线程组设置成50,发现成功数目小于50,这是为什么?

学新通

之前用的nginx是在本机虚拟机上部署的,可能是网速太好了,将nginx设置到一个网速不那么好的机子上。也是一样的结果,设置的50,为什么一秒内发送50个请求过去没有完全成功呢?

50r/s 实际上是限制:每1S/50=20毫秒处理一个请求。这意味着,自上一个请求处理完后,若后续120毫秒内又有请求到达,将拒绝处理该请求。

可能是换的这台机子网速也不是那么不好吧,导致请求之间没有合适的时间间隔。

自己用java写了个有时间间隔的请求,发现也是一堆503。。。

  1.  
    package com.example.pressuretest;
  2.  
     
  3.  
    import java.io.IOException;
  4.  
     
  5.  
    public class Test22 {
  6.  
    public static void main(String[] args) throws IOException, InterruptedException {
  7.  
     
  8.  
    for (int i = 0; i < 30; i ) {
  9.  
    new Thread(() -> {
  10.  
    String s = null;
  11.  
    try {
  12.  
    s = HttpClientUtil.get2("http://192.168.136.101:9002");
  13.  
    } catch (IOException e) {
  14.  
    throw new RuntimeException(e);
  15.  
    }
  16.  
    System.out.println("code" s);
  17.  
    }).start();
  18.  
     
  19.  
     
  20.  
    //每过40MS发出一个请求
  21.  
    Thread.sleep(40);
  22.  
    }
  23.  
    }
  24.  
    }

看来只能解读我我网速太好了吧。。

================================================================

Ramp-up Period(in seconds)

【1】决定多长时间启动所有线程。如果使用10个线程,ramp-up period是100秒,那么JMeter用100秒使所有10个线程启动并运行。每个线程会在上一个线程启动后10秒(100/10)启动。Ramp-up需要要充足长以避免在启动测试时有一个太大的工作负载,并且要充足小以至于最后一个线程在第一个完成前启动。  一般设置ramp-up=线程数启动,并上下调整到所需的。
 

学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhfggjfb
系列文章
更多 icon
同类精品
更多 icon
继续加载