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个请求。
-
[root@localhost ~]# cd /home/nginx/conf/
-
[root@localhost conf]#
-
[root@localhost conf]# ls
-
conf.d nginx.conf
-
[root@localhost conf]# vim nginx.conf
-
[root@localhost conf]# cat nginx.conf
-
-
user nginx;
-
worker_processes auto;
-
-
error_log /var/log/nginx/error.log notice;
-
pid /var/run/nginx.pid;
-
-
-
events {
-
worker_connections 1024;
-
}
-
-
-
http {
-
-
limit_req_zone $binary_remote_addr zone=mylimit:10m rate=2r/s;
-
limit_conn_zone $binary_remote_addr zone=perid:10m;
-
limit_conn_zone $server_name zone=preserver:10m;
-
-
include /etc/nginx/mime.types;
-
default_type application/octet-stream;
-
-
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
-
'$status $body_bytes_sent "$http_referer" '
-
'"$http_user_agent" "$http_x_forwarded_for"';
-
-
access_log /var/log/nginx/access.log main;
-
-
sendfile on;
-
#tcp_nopush on;
-
-
keepalive_timeout 65;
-
-
#gzip on;
-
-
include /etc/nginx/conf.d/*.conf;
-
}
-
[root@localhost conf.d]# cd /home/nginx/conf/conf.d
-
[root@localhost conf.d]# ls
-
default.conf
-
[root@localhost conf.d]# cat default.conf
-
server {
-
listen 80;
-
listen [::]:80;
-
server_name localhost;
-
-
#access_log /var/log/nginx/host.access.log main;
-
-
location / {
-
root /usr/share/nginx/html;
-
index index.html index.htm;
-
-
limit_req zone=mylimit burst=1 nodelay;
-
limit_conn perid 20;
-
limit_conn preserver 10000;
-
}
-
-
#error_page 404 /404.html;
-
-
# redirect server error pages to the static page /50x.html
-
#
-
error_page 500 502 503 504 /50x.html;
-
location = /50x.html {
-
root /usr/share/nginx/html;
-
}
-
-
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
-
#
-
#location ~ \.php$ {
-
# proxy_pass http://127.0.0.1;
-
#}
-
-
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
-
#
-
#location ~ \.php$ {
-
# root html;
-
# fastcgi_pass 127.0.0.1:9000;
-
# fastcgi_index index.php;
-
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
-
# include fastcgi_params;
-
#}
-
-
# deny access to .htaccess files, if Apache's document root
-
# concurs with nginx's one
-
#
-
#location ~ /\.ht {
-
# deny all;
-
#}
-
}
启动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。。。
-
package com.example.pressuretest;
-
-
import java.io.IOException;
-
-
public class Test22 {
-
public static void main(String[] args) throws IOException, InterruptedException {
-
-
for (int i = 0; i < 30; i ) {
-
new Thread(() -> {
-
String s = null;
-
try {
-
s = HttpClientUtil.get2("http://192.168.136.101:9002");
-
} catch (IOException e) {
-
throw new RuntimeException(e);
-
}
-
System.out.println("code" s);
-
}).start();
-
-
-
//每过40MS发出一个请求
-
Thread.sleep(40);
-
}
-
}
-
}
看来只能解读我我网速太好了吧。。
================================================================
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
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
微信运动停用后别人还能看到步数吗
PHP中文网 07-22 -
excel打印预览压线压字怎么办
PHP中文网 06-22