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


    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. user nginx;
    8. worker_processes auto;
    9. error_log /var/log/nginx/error.log notice;
    10. pid /var/run/nginx.pid;
    11. events {
    12. worker_connections 1024;
    13. }
    14. http {
    15. limit_req_zone $binary_remote_addr zone=mylimit:10m rate=2r/s;
    16. limit_conn_zone $binary_remote_addr zone=perid:10m;
    17. limit_conn_zone $server_name zone=preserver:10m;
    18. include /etc/nginx/mime.types;
    19. default_type application/octet-stream;
    20. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    21. '$status $body_bytes_sent "$http_referer" '
    22. '"$http_user_agent" "$http_x_forwarded_for"';
    23. access_log /var/log/nginx/access.log main;
    24. sendfile on;
    25. #tcp_nopush on;
    26. keepalive_timeout 65;
    27. #gzip on;
    28. include /etc/nginx/conf.d/*.conf;
    29. }

    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. #access_log /var/log/nginx/host.access.log main;
    10. location / {
    11. root /usr/share/nginx/html;
    12. index index.html index.htm;
    13. limit_req zone=mylimit burst=1 nodelay;
    14. limit_conn perid 20;
    15. limit_conn preserver 10000;
    16. }
    17. #error_page 404 /404.html;
    18. # redirect server error pages to the static page /50x.html
    19. #
    20. error_page 500 502 503 504 /50x.html;
    21. location = /50x.html {
    22. root /usr/share/nginx/html;
    23. }
    24. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    25. #
    26. #location ~ \.php$ {
    27. # proxy_pass http://127.0.0.1;
    28. #}
    29. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    30. #
    31. #location ~ \.php$ {
    32. # root html;
    33. # fastcgi_pass 127.0.0.1:9000;
    34. # fastcgi_index index.php;
    35. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    36. # include fastcgi_params;
    37. #}
    38. # deny access to .htaccess files, if Apache's document root
    39. # concurs with nginx's one
    40. #
    41. #location ~ /\.ht {
    42. # deny all;
    43. #}
    44. }

     

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

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

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

    Ramp-up Period(in seconds)

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

     

     

     

  • 相关阅读:
    112. 路径总和
    R语言ggplot2可视化:使用ggpubr包的ggdonutchart函数可视化甜甜圈图(donut chart)、为甜甜圈图不同区域添加标签
    记录一次线上fullgc问题排查过程
    《非线性成长》阅读笔记
    Vue3.0 所采用的 Composition Api 与 Vue2.x 使用的 Options Api 有什么不同?
    40个高质量SSM毕设项目分享【源码+论文】(五)
    npm和yarn使用(官网、安装、命令行、上传自己的包、包版本号详解、更新卸载包、查看所有版本、同等依赖peer、可选依赖optional)
    【软件与系统安全笔记】三、基础技术
    pyqt5的组合式部件制作(一)
    Java学习笔记 --- 自定义泛型
  • 原文地址:https://blog.csdn.net/hebian1994/article/details/126891372