https://www.cnblogs.com/sunjianguo/p/8298283.html

停用除SSH外的所有服务,仅保留nginx,优化思路主要包括两个层面:系统层面+nginx层面。

1、调整同时打开文件数量

ulimit -n 20480

2、TCP最大连接数(somaxconn)

echo 10000 > /proc/sys/net/core/somaxconn

3、TCP连接立即回收、回用(recycle、reuse)

echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse

echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle

4、不做TCP洪水抵御

echo 0 > /proc/sys/net/ipv4/tcp_syncookies

也可以直接使用优化后的配置,在/etc/sysctl.conf中加入

net.core.somaxconn = 20480

net.core.rmem_default = 262144

net.core.wmem_default = 262144

net.core.rmem_max = 16777216

net.core.wmem_max = 16777216

net.ipv4.tcp_rmem = 4096 4096 16777216

net.ipv4.tcp_wmem = 4096 4096 16777216

net.ipv4.tcp_mem = 786432 2097152 3145728

net.ipv4.tcp_max_syn_backlog = 16384

net.core.netdev_max_backlog = 20000

net.ipv4.tcp_fin_timeout = 15

net.ipv4.tcp_max_syn_backlog = 16384

net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_tw_recycle = 1

net.ipv4.tcp_max_orphans = 131072

net.ipv4.tcp_syncookies = 0

使用:sysctl -p 生效

sysctl -p

二、nginx层面

修改nginx配置文件,nginx.conf

加work_rlimit_nofile和worker_connections数量,并禁用keepalive_timeout

worker_processes 1;

worker_rlimit_nofile 20000;

events {

use epoll;

worker_connections 20000;

multi_accept on;

}

http {   

keepalive_timeout 0;

}

重启nginx

/usr/local/nginx/sbin/nginx -s reload

使用ab压力测试

ab -c 10000 -n 150000 http://127.0.0.1/index.html

测试结果:

This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 127.0.0.1 (be patient) Completed 15000 requests Completed 30000 requests Completed 45000 requests Completed 60000 requests Completed 75000 requests Completed 90000 requests Completed 105000 requests Completed 120000 requests Completed 135000 requests Completed 150000 requests Finished 150000 requests Server Software: nginx/1.8.0 Server Hostname: 127.0.0.1 Server Port: 80 Document Path: /index.html Document Length: 612 bytes Concurrency Level: 10000 Time taken for tests: 19.185 seconds Complete requests: 150000 Failed requests: 0 Write errors: 0 Total transferred: 131180388 bytes HTML transferred: 95121324 bytes Requests per second: 7818.53 [#/sec] (mean) Time per request: 1279.013 [ms] (mean) Time per request: 0.128 [ms] (mean, across all concurrent requests) Transfer rate: 6677.33 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 650 547.9 522 7427 Processing: 212 519 157.4 496 958 Waiting: 0 404 139.7 380 845 Total: 259 1168 572.1 1066 7961 Percentage of the requests served within a certain time (ms) 50% 1066 66% 1236 75% 1295 80% 1320 90% 1855 95% 2079 98% 2264 99% 2318 100% 7961 (longest request)

最新文章

  1. 项目 CTR预估
  2. redhat 安装 jdk1.7 问题
  3. .net下mysql存储过程返回自定义值(原创)
  4. C++ 内联函数笔记
  5. 35.Android之带删除按钮EditText学习
  6. 【转】HTML5新增元素兼容旧浏览器方法
  7. Gentoo安装配置过程与总结
  8. Codeforces Round #328 div2
  9. SQLSERVER一个比较不错的分页存储过程p_splitpage
  10. mysql 使用游标进行删除操作的存储过程
  11. Linux软件大全
  12. vijos 1067 Warcraft III 守望者的烦恼 矩阵
  13. Hibernate 注解说明
  14. linux服务器的操作禁忌
  15. jQuery form插件使用详解
  16. springboot:接收date类型的参数
  17. Android直连SQL Server数据库
  18. Ubunut操作系统下nDPI的部署及简单使用
  19. ThinkPHP3上传文件中遇到的问题
  20. H5中canvas标签制作在线画板

热门文章

  1. VectorCAST软件自动化测试方案
  2. 记一次 .NET 某妇产医院 WPF内存溢出分析
  3. Windows下mysql5.6升级到5.7的方法(亲测有效哦!)
  4. java 注解的几大作用及使用方法详解
  5. win10 安装xmemcache及使用
  6. Python的安装和卸载
  7. LuoguP6857 梦中梦与不再有梦 题解
  8. LuoguP7285 「EZEC-5」修改数组 题解
  9. Golang爬虫+正则表达式
  10. springboot使用线程池(ThreadPoolTaskExecutor)