ab测试nginx Nginx性能优化
转自:https://www.cnblogs.com/nulige/p/9369700.html
1.性能优化概述
在做性能优化前, 我们需要对如下进行考虑
- 1.当前系统结构瓶颈
- 观察指标
- 压力测试
- 2.了解业务模式
- 接口业务类型
- 系统层次化结构
- 3.性能与安全
- 性能好安全弱
- 安全好性能低
2.压力测试工具
1.安装压力测试工具ab
[root@nginx-lua ~]# yum install httpd-tools -y
2.了解压测工具使用方式
[root@nginx-lua ~]# ab -n 200 -c 2 http://127.0.0.1/
//-n总的请求次数
//-c并发请求数
//-k是否开启长连接
3.配置Nginx静态网站与tomcat动态网站环境
[root@nginx-lua conf.d]# cat jsp.conf
server {
server_name localhost;
listen 80;
location / {
root /soft/code;
try_files $uri @java_page;
index index.jsp index.html;
}
location @java_page{
proxy_pass http://192.168.56.20:8080;
}
}
//分别给Nginx准备静态网站
[root@nginx-lua ~]# cat /soft/code/bgx.html
<h1> Ab Load </h1>
//给Tomcat准备静态网站文件
[root@tomcat-node1-20 ROOT]# cat /soft/tomcat-8080/webapps/ROOT/bgx.html
<h1> Ab Load </h1>
4.使用ab工具进行压力测试
//进行压力测试
[root@Nginx conf.d]# ab -n2000 -c2 http://127.0.0.1/bgx.html
...
Server Software: nginx/1.12.2
Server Hostname: 127.0.0.1
Server Port: 80
Document Path: /bgx.html
Document Length: 19 bytes
Concurrency Level: 200
# 总花费总时长
Time taken for tests: 1.013 seconds
# 总请求数
Complete requests: 2000
# 请求失败数
Failed requests: 0
Write errors: 0
Total transferred: 510000 bytes
HTML transferred: 38000 bytes
# 每秒多少请求/s(总请求出/总共完成的时间)
Requests per second: 9333.23 [#/sec] (mean)
# 客户端访问服务端, 单个请求所需花费的时间
Time per request: 101.315 [ms] (mean)
# 服务端处理请求的时间
Time per request: 0.507 [ms] (mean, across all concurrent requests)
# 判断网络传输速率, 观察网络是否存在瓶颈
Transfer rate: 491.58 [Kbytes/sec] received
5.将nginx下的bgx文件移走, 再次压测会由tomcat进行处理
Concurrency Level: 200
Time taken for tests: 1.028 seconds
Complete requests: 2000
Failed requests: 0
Write errors: 0
Total transferred: 510000 bytes
HTML transferred: 38000 bytes
Requests per second: 1945.09 [#/sec] (mean)
Time per request: 102.823 [ms] (mean)
Time per request: 0.514 [ms] (mean, across all concurrent requests)
Transfer rate: 484.37 [Kbytes/sec] received
3.影响性能指标
影响性能方便整体关注
- 1.网络
- 网络的流量
- 网络是否丢包
- 这些会影响http的请求与调用
- 2.系统
- 硬件有没有磁盘损坏,磁盘速率
- 系统负载、内存、系统稳定性
- 3.服务
- 连接优化、请求优化
- 根据业务形态做对应的服务设置
- 4.程序
- 接口性能
- 处理速度
- 程序执行效率
- 5.数据库
每个架构服务与服务之间都或多或少有一些关联, 我们需要将整个架构进行分层, 找到对应系统或服务的短板, 然后进行优化
4.系统性能优化
- 文件句柄, Linux一切皆文件,文件句柄可以理解为就是一个索引
- 文件句柄会随着我们进程的调用频繁增加
- 系统默认对文件句柄有限制,不能让一个进程无限的调用
- 需要限制每个进程和每个服务使用多大的文件句柄
- 文件句柄是必须要调整的优化参数
- 设置方式
- 系统全局性修改
- 用户局部性修改
- 进程局部性修改
vim /etc/security/limits.conf //针对root用户 root soft nofile 65535 root hard nofile 65535 //所有用户, 全局 * soft nofile 25535 * hard nofile 25535 //对于Nginx进程 worker_rlimit_nofile 65535; //root用户 //soft提醒 //hard限制 //nofile文件数配置项 //65535最大大小
备注:可以使用ulimit -a 命令查看open files 65535 系统最大打开文件数的值。
5.Nginx性能优化
CPU亲和, 减少进程之间不断频繁迁移, 减少性能损耗
1.查看当前CPU物理状态
[root@nginx ~]# lscpu |grep "CPU(s)"CPU(s): 24On-line CPU(s) list: 0-23NUMA node0 CPU(s): 0,2,4,6,8,10,12,14,16,18,20,22NUMA node1 CPU(s): 1,3,5,7,9,11,13,15,17,19,21,23 |
//2颗物理cpu,没颗cpu12核心, 总共24核心
2.将Nginx worker进程绑到不同的核心上
//启动多少worker进程, 官方建议和cpu核心一致, 第一种绑定组合方式#worker_processes 24;#worker_cpu_affinity 000000000001 000000000010 000000000100 000000001000 000000010000 000000100000 000001000000 000010000000 000100000000 001000000000 010000000000 10000000000;//第二种方式#worker_processes 2;#worker_cpu_affinity 101010101010 010101010101;//最佳方式绑定方式worker_processes auto;worker_cpu_affinity auto; |
3.查看nginx worker进程绑定至对应cpu
ps -eo pid,args,psr|grep [n]ginx
4.Nginx通用优化配置文件
[root@nginx ~]# cat nginx.confuser nginx;worker_processes auto;worker_cpu_affinity auto;error_log /var/log/nginx/error.log warn;pid /run/nginx.pid;#调整至1w以上,负荷较高建议2-3w以上worker_rlimit_nofile 65535;events { use epoll;#限制每个进程能处理多少个连接请求,10240x16 worker_connections 10240;}http { include /etc/nginx/mime.types; default_type application/octet-stream;# 统一使用utf-8字符集 charset utf-8; 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;# Core module sendfile on;# 静态资源服务器建议打开 tcp_nopush on;# 动态资源服务建议打开,需要打开keepalived tcp_nodelay on; keepalive_timeout 65;# Gzip module gzip on; gzip_disable "MSIE [1-6]\."; gzip_http_version 1.1;# Virtal Server include /etc/nginx/conf.d/*.conf;} |
ab测试nginx Nginx性能优化的更多相关文章
- Nginx配置性能优化与压力测试webbench【转】
这一篇我们来说Nginx配置性能优化与压力测试webbench. 基本的 (优化过的)配置 我们将修改的唯一文件是nginx.conf,其中包含Nginx不同模块的所有设置.你应该能够在服务器的/et ...
- 22、编译安装nginx及性能优化
22.1.编译安装nginx: 1.下载nginx: [root@slave-node1 ~]# mkdir -p /tools/ [root@slave-node1 ~]# cd /tools/ [ ...
- Nginx服务器性能优化与安全配置实践指南
转载自:https://www.bilibili.com/read/cv16151784?spm_id_from=333.999.0.0 1.引言 1.1 目的 为了更好的指导部署与测试艺术升系统ng ...
- Nginx配置性能优化
大多数的Nginx安装指南告诉你如下基础知识--通过apt-get安装,修改这里或那里的几行配置,好了,你已经有了一个Web服务器了.而且,在大多数情况下,一个常规安装的nginx对你的网站来说已经能 ...
- Nginx配置性能优化(转)
大多数的Nginx安装指南告诉你如下基础知识——通过apt-get安装,修改这里或那里的几行配置,好了,你已经有了一个Web服务器了.而且,在大多数情况下,一个常规安装的nginx对你的网站来说已经能 ...
- Nginx的性能优化方案
nginx的优化 . gzip压缩优化 . expires缓存有还 . 网络IO事件模型优化 . 隐藏软件名称和版本号 . 防盗链优化 . 禁止恶意域名解析 . 禁止通过IP地址访问网站 . HTTP ...
- [转] Nginx配置性能优化
大多数的Nginx安装指南告诉你如下基础知识——通过apt-get安装,修改这里或那里的几行配置,好了,你已经有了一个Web服务器了.而且,在大多数情况下,一个常规安装的nginx对你的网站来说已经能 ...
- Nginx的性能优化
1.优化worker进程个数: 在高并发.高访问量的WEB服务场景,需要事先启动更多的nginx进程,以保证快速响应并处理大量并发用户的请求,优化nginx进程个数的配置项就是,在nginx.conf ...
- nginx https性能优化
影响HTTPS速度的主要原因:秘钥交换算法 常见的密钥交换算法有 RSA,ECDHE,DH,DHE 等算法.它们的特性如下: RSA:算法实现简单,诞生于 1977 年,历史悠久,经过了长时间的破解测 ...
- 关于Nginx配置性能优化
基本的 (优化过的)配置 将修改的唯一文件是nginx.conf,其中包含Nginx不同模块的所有设置.在服务器的/etc/nginx目录中找到nginx.conf. 首先,我们将谈论一些全局设置,然 ...
随机推荐
- 前端vscode常用插件
Auto Rename Tag 这是一个html标签的插件,可以让你修改一边标签,另外一边自动改变. Beautify 格式化代码插件 Braket Pair Colorizer 给js文件中的每一个 ...
- python-爬虫-史书典籍
import requests import os from lxml import html import time def get_title_url(tree): '''一级 获取标题''' # ...
- C#作业系统中的安全系统
比赛条件 编写多线程代码时,总是存在竞争条件的风险.当一个操作的输出取决于其控制之外的另一个过程的定时时,发生竞争条件. 竞争条件并不总是一个错误,但它是不确定行为的来源.当竞争条件确实导致错误时,可 ...
- netcore程序部署 docker 异常 --生成图片二维码缺少libdl
最近因业务需求需要在程序中实现二维码图片生成,于是就用到QRCoder开发库.最终在windows环境下部署运行没问题,但切换到docker(centos7.0)后发现是有问题的. 错误信息提示:Th ...
- yum tenxun ntpdate 时间同步
centos7 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base ...
- (转)python基础学习-----生成器和迭代器
在Python中,很多对象都是可以通过for语句来直接遍历的,例如list.string.dict等等,这些对象都可以被称为可迭代对象.至于说哪些对象是可以被迭代访问的,就要了解一下迭代器相关的知识了 ...
- Spring 中的几个常用的钩子接口
1.Aware接口 Awear 这个单词的意思是知道的,所以可以猜想以Awear 结尾的接口意思可以把他知道的东西告诉我们.常用的Awear接口有 ApplicationContextAware和 B ...
- Ubuntu - Ubuntu应用记录(1)
1.发生dpkg status database is locked by another process 原因是包管理器没有正确关闭.需要重启计算机或者重新打开终端 输入: sudo rm /var ...
- 3. Linux的shell编程
Shell 是一个用 C 语言编写的程序, 通过 Shell 用户可以访问操作系统内核服务.它类似于 DOS 下的 command 和后来的 cmd.exe.Shell 既是一种命令语言,又是一种程序 ...
- reduce的使用
reduce的使用:https://blog.csdn.net/xiasohuai/article/details/82152432