首页 > 系统相关 >Nginx基础 - 12性能优化

Nginx基础 - 12性能优化

时间:2023-03-12 10:46:50浏览次数:37  
标签:www 12 root 性能 nofile Nginx attributes requests 优化

 

一、性能优化概述

  • 系统结构瓶颈: 观察指标、压力测试
  • 了解业务模式: 接口业务类型、 系统层次化结构
  • 性能与安全:   性能好安全弱、安全好性能低

 

二、压力测试工具

工具: 压测宝、 ab
[root@my-node51 ~]#  ab
ab: wrong number of arguments
Usage: ab [options] [http[s]://]hostname[:port]/path
Options are:
    -n requests     Number of requests to perform
    -c concurrency  Number of multiple requests to make at a time
    -t timelimit    Seconds to max. to spend on benchmarking, This implies -n 50000
    -s timeout      Seconds to max. wait for each response, Default is 30 seconds
    -b windowsize   Size of TCP send/receive buffer, in bytes
    -B address      Address to bind to when making outgoing connections
    -p postfile     File containing data to POST. Remember also to set -T
    -u putfile      File containing data to PUT. Remember also to set -T
    -T content-type Content-type header to use for POST/PUT data, eg. 'application/x-www-form-urlencoded', Default is 'text/plain'
    -v verbosity    How much troubleshooting info to print
    -w              Print out results in HTML tables
    -i              Use HEAD instead of GET
    -x attributes   String to insert as table attributes
    -y attributes   String to insert as tr attributes
    -z attributes   String to insert as td or th attributes
    -C attribute    Add cookie, eg. 'Apache=1234'. (repeatable)
    -H attribute    Add Arbitrary header line, eg. 'Accept-Encoding: gzip', Inserted after all normal header lines. (repeatable)
    -A attribute    Add Basic WWW Authentication, the attributes are a colon separated username and password.
    -P attribute    Add Basic Proxy Authentication, the attributes are a colon separated username and password.
    -X proxy:port   Proxyserver and port number to use
    -V              Print version number and exit
    -k              Use HTTP KeepAlive feature
    -d              Do not show percentiles served table.
    -S              Do not show confidence estimators and warnings.
    -q              Do not show progress when doing more than 150 requests
    -l              Accept variable document length (use this for dynamic pages)
    -g filename     Output collected data to gnuplot format file.
    -e filename     Output CSV file with percentages served
    -r              Don't exit on socket receive errors.
    -m method       Method name
    -h              Display usage information (this message)
    -I              Disable TLS Server Name Indication (SNI) extension
    -Z ciphersuite  Specify SSL/TLS cipher suite (See openssl ciphers)
    -f protocol     Specify SSL/TLS protocol (SSL2, TLS1, TLS1.1, TLS1.2 or ALL)
    -E certfile     Specify optional client certificate chain and private key

  

[root@my-node51 ~]# ab -n 50 -c 20 http://www.myshop.com/index.html
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.myshop.com (be patient).....done

Server Software:        nginx/1.22.1
Server Hostname:        www.myshop.com
Server Port:            80

Document Path:          /index.html
Document Length:        153 bytes

Concurrency Level:      20
Time taken for tests:   0.006 seconds
Complete requests:      50
Failed requests:        0
Non-2xx responses:      50
Total transferred:      15150 bytes
HTML transferred:       7650 bytes
Requests per second:    8368.20 [#/sec] (mean)
Time per request:       2.390 [ms] (mean)
Time per request:       0.120 [ms] (mean, across all concurrent requests)
Transfer rate:          2476.14 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:     0    1   0.7      1       4
Waiting:        0    1   0.7      1       4
Total:          1    2   0.6      1       4
WARNING: The median and mean for the total time are not within a normal deviation
        These results are probably not that reliable.

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      2
  75%      2
  80%      2
  90%      2
  95%      2
  98%      4
  99%      4
 100%      4 (longest request)

 

三、 影响性能指标 

  • 网络: 网络流量;网络是否丢包; 这些会影响http的请求与调用
  • 系统: 硬件有没有磁盘损坏、磁盘速率; 系统负载、内存、系统稳定性
  • 服务: 连接优化、请求优化; 根据业务形态做对应的服务设置
  • 程序: 接口性能; 处理速度; 程序执行效率
  • 数据库: 

 

四、 系统性能优化

文件句柄

[root@my-node51 ~]# vi /etc/security/limits.conf
root             soft    nofile          65535
root             hard    nofile          65535
*                soft    nofile          25535
*                hard    nofile          25535

 

[root@my-node51 ~]# vi /etc/nginx/nginx.conf
worker_rlimit_nofile 45535;

[root@my-node51 ~]# cat /proc/1632/limits
Limit                     Soft Limit           Hard Limit           Units
Max processes             7068                 7068                 processes
Max open files            65535                65535                files

  

五、Nginx性能优化

  • worker_processes auto;
  • worker_cpu_affinity auto;    # CPU亲和性, 减少进程之间不断频繁迁移,减少性能损耗
  • worker_rlimit_nofile 45535;  # 文件描述符
  • worker_connections 10240;    # 限制每个进程能处理多少个连接请求
  • charset utf-8;               # 字符集统一为utf-8
  • sendfile on;
  • tcp_nopush  on;              # 静态资源服务器,建议打开
  • tcp_nodelay on;              # 动态资源服务器,建议打开,需要打开 keepalive
  • keepalive_timeout  65;
  • gzip on;

 

标签:www,12,root,性能,nofile,Nginx,attributes,requests,优化
From: https://www.cnblogs.com/kingdomer/p/13938370.html

相关文章

  • Nginx基础 - 13模块与变量
      一、Nginx常用模块Nginx模块分为Nginx官方模块以及Nginx第三方模块Nginx编译选项模块作用ngx_http_core_module包含一些核心的http参数配置......
  • Nginx配置实例-动静分离实例:搭建静态资源服务器
    什么是动静分离Nginx动静分离简单来说就是把动态跟静态请求分开,不能理解成只是单纯的把动态页面和静态页面物理分离。严格意义上说应该是动态请求跟静态请求分开,可以理解......
  • Nginx
    ​ 1分类1.1通用分布式文件系统​和传统的本地文件系统(如ext3、NTFS等)相对应。典型代表:lustre、MooseFS1.1.1优点​标准文件系统操作方式,对开发者门槛较低1.1.......
  • P1075 [NOIP2012 普及组] 质因数分解 提交 333.88k 通过 126.26k 时间限制 1.00s 内存
    P1075[NOIP2012普及组]质因数分解[NOIP2012普及组]质因数分解题目描述已知正整数n是两个不同的质数的乘积,试求出两者中较大的那个质数。输入格式输入一个正整......
  • day12
    用户交互界面两种输入方法next()输入法packagecom.xiao.scanner;importjava.util.Scanner;publicclassDemo01{publicstaticvoidmain(String[]args){......
  • 通过HH8WilEdit学习WIL 文件编码 12 对WIL文件调色板的读取
    unitWilPalette;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,ExtCtrls,StdCtrls;typeTRGBQua......
  • js Set 去重优化
    场景:往tempListExtra塞入数据,返回过滤后的数组。constarr=[...tempListExtra,...extraOpt];constset=newSet();constduplication=arr.filter((item:any)=>......
  • 量化交易基础 - 012 - 检验中的假设条件
    12-检验中的假设条件检验流程中的另一组成部分是假设条件,这些有关交易策略的假设条件在历史上已被检验。这里我们讨论两个例子:交易成本和(股票市场中性策略或多头/空头策......
  • 本地浏览器访问云服务器127.0.0.1的某个端口
    目前在学习gin框架,但是在无图形化界面的linux云服务器上看不到网页的效果,而且lynx等纯文本浏览器过于丑陋了。于是研究了一下如何在本地计算机访问云服务器上的127.......
  • UVA12107 题解
    前言题目传送门!更好的阅读体验?很久以前的一道搜索大模拟题目,另一篇题解的写法有点鬼畜,所以就来补篇题解。题面给你一个数字谜。修改最少次数(每次修改一个数位为空格或......