做过Linux平台性能测试的童鞋平时可能会遇到如下问题:

1、 TCP端口号不够用导致并发上不去(即与服务器端建立新连接失败)

2、 TIME_WAIT状态连接过多导致应用服务器(Nginx、Haproxy、Redis、Tomcat等)性能下降或假死

等等

我们可以通过优化系统内核参数来解决上述问题,优化步骤如下:

Linux 平台

1、 参考附件1中sysctl.conf文件替换或修改系统中/etc/sysctl.conf

意义:

(1) 突破系统最大打开文件描述符数限制(系统级别)

(2) 提高系统网络负载

2、 使用命令“sysctl -p /etc/sysctl.conf”使步骤1修改生效

备注:error: “net.bridge.bridge-nf-call-ip6tables” is an unknown key 解决方法

modprobe bridge
lsmod|grep bridge

3、 修改/etc/security/limits.conf,添加如下内容:

* hard nofile 1024000
* soft nofile 1024000

意义:突破 进程最大打开文件描述符数限制(用户级别)

4、 重新登录服务器使其步骤3修改生效

备注:

(1) 修改过程中需注意:

a. 所有进程打开的文件描述符数不能超过/proc/sys/fs/file-max

b. 单个进程打开的文件描述符数不能超过user limit中nofile的soft limit

c. nofile的soft limit不能超过其hard limit

d. nofile的hard limit不能超过/proc/sys/fs/nr_open

(2) /etc/security/limits.conf里面修改文件描述符数量,建议带上账号,*号代表了所有账户!

1) 新建kdxf运行的账户(一般不使用root账户;现网安全起见一般会禁用root账户直接登录权限,需要从普通账户登录后切换至root)

2) 关闭Linux系统SELINUX和防火墙(需要重启操作系统,SELINUX安全系统控制过严,可能会影响进程访问操作系统某些资源)

修改/etc/selinux/config文件中SELINUX=”“为disabled

关闭防火墙使用命令:

chkconfig iptables off
chkconfig ip6tables off

3) 系统字符集编码配置(系统默认utf-8,在需要的时候可以修改系统字符集,需要重启操作系统)

修改/etc/sysconfig/i18n配置文件中的LANG

LANG="zh_CN.GB18030"

修改/etc/profile,增加两行:

export LANG=zh_CN.GB18030
export LC_ALL=zh_CN.GB18030

4) 产生core文件配置(该配置是应用程序在崩溃时能自动产生一个崩溃core文件,有助于开发定位崩溃原因)

修改/etc/profile,增加一行:

ulimit -c unlimited

修改/etc/sysctl.conf文件,设置

fs.suid_dumpable = 1

运行以下命令使得配置生效

sysctl -p

5) 用户最大进程数配置

Centos5环境修改/etc/security/limits.conf文件

Centos6环境修改/etc/security/limits.d/90-nproc.conf文件

kdxf hard nproc unlimited
kdxf soft nproc unlimited

注:这里kdxf代表运行应用程序的普通系统账户,请根据实际填写!

附件1:sysctl.conf

# Kernel sysctl configuration file for Red Hat Linux
# For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and
# sysctl.conf(5) for more details.
# Controls IP packet forwarding
net.ipv4.ip_forward = 0
# Controls source route verification
net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.default.rp_filter=0
# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0
# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 0
# Controls whether core dumps will append the PID to the core filename.
# Useful for debugging multi-threaded applications.
kernel.core_uses_pid = 1
# Controls the use of TCP syncookies
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 12
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.tcp_max_syn_backlog = 8192
# Disable netfilter on bridges.
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0
# Controls the default maxmimum size of a mesage queue
kernel.msgmnb = 65536
# Controls the maximum size of a message, in bytes
kernel.msgmax = 65536
# Controls the maximum shared segment size, in bytes
kernel.shmmax = 68719476736
# Controls the maximum number of shared memory segments, in pages
kernel.shmall = 4294967296
# Disable IPv6
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
# Determines how often to check for stale neighbor entries.
net.ipv4.neigh.default.gc_stale_time=120
# Using arp_announce/arp_ignore to solve the ARP Problem
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.all.arp_announce=2
vm.swappiness = 0
net.ipv4.tcp_max_tw_buckets = 50000
net.ipv4.tcp_max_syn_backlog = 1024
net.ipv4.tcp_synack_retries = 2
net.ipv4.conf.lo.arp_announce=2
# Controls the application is able to bind to not belong to the local network address
net.ipv4.ip_nonlocal_bind=1
fs.file-max = 1700000

Windows平台

1、 按附件2内容新建tcp.reg注册表文件并执行

意义:修改系统连接数限制

2、 重启系统,使其步骤1修改生效

附件2:tcp.reg

Windows Registry Editor Version 5.00
;修改TCP并发连接数为最大值
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters]
"TcpNumConnections"=dword:00fffffe
;修改分页池最大使用值被系统回收
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management]
"PoolUsageMaxium"=dword:00000032
;修复系统支持最大网络吞吐量
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer]
"MaxFreeConnections"=dword:00001000
"MinFreeConnections"=dword:00000100

Linux系统内核性能调优的更多相关文章

  1. 20个Linux服务器性能调优技巧

    Linux是一种开源操作系统,它支持各种硬件平台,Linux服务器全球知名,它和Windows之间最主要的差异在于,Linux服务器默认情况下一般不提供GUI(图形用户界面),而是命令行界面,它的主要 ...

  2. [转]20个你不得不知的Linux服务器性能调优技巧

    Linux是一种开源操作系统,它支持各种硬件平台,Linux服务器全球知名,它和Windows之间最主要的差异在于,Linux服务器默认情况下一般不提供GUI(图形用户界面),而是命令行界面,它的主要 ...

  3. linux的性能调优

    单机调优: 分析性能瓶颈的原因,解决它.   cpu子系统 内存子系统 IO子系统 网络系统       @cpu子系统调优 cpu技术指标 xeon E5520 2.27GHz 8192kb # c ...

  4. Java性能优化,操作系统内核性能调优,JYM优化,Tomcat调优

    文章目录 Java性能优化 尽量在合适的场合使用单例 尽量避免随意使用静态变量 尽量避免过多过常地创建Java对象 尽量使用final修饰符 尽量使用局部变量 尽量处理好包装类型和基本类型两者的使用场 ...

  5. Linux内存 性能调优

    内存是影响Linux性能的主要因素之一,内存资源的充足与否直接影响应用系统的使用性能. free命令:监控Linux内存使用状况. 由上图可知,空闲内存是free+buffers+cached=155 ...

  6. [转载] 高流量大并发Linux TCP 性能调优

    原文: http://cenwj.com/2015/2/25/19 本文参考文章为: 优化Linux下的内核TCP参数来提高服务器负载能力 Linux Tuning 本文所面对的情况为: 高并发数 高 ...

  7. linux 服务器性能调优总结

    1.性能分析的几个方面 https://blog.csdn.net/w174504744/article/details/53894127 2.cpu 性能分析工具 perf https://blog ...

  8. linux上性能调优常用命令及简介

    1.综合命令:nmon.top:topas(aix) d :磁盘相关 c:cpu相关 m:内存相关 2.磁盘 2.1 测试顺序写性能dd if=/dev/zero of=/cdr/test.data ...

  9. Linux常用性能调优工具索引

    root@ubuntu:~# dstat----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system--usr sys i ...

随机推荐

  1. leetcode NO.349 两个数组的交集 (python实现)

    来源 https://leetcode-cn.com/problems/intersection-of-two-arrays/ 题目描述 给定两个数组,写一个函数来计算它们的交集. 例子: 给定 nu ...

  2. Unity 脚本<1>

    RaycastHit2D hit = Physics2D.Linecast(targetPosition, targetPosition + new Vector2(x, y)); 猜测是lineca ...

  3. python 使用入的坑

    如测试代码,并没有将li.li_ 的交集查询出来 li=[1,2,3,4,5] li_=[2,5,6,7,9] for i in li_: if i in li: li_.remove(i) prin ...

  4. idea下的hibernate反向生成插件

    阅读目录 1. 打开 DataBase 窗口,添加数据源 2. 添加 hibernate 持久层支持,生成实体 Bean /配置文件 谈起 Hibernate 应该得知道 Gavin King 大叔, ...

  5. P1558 色板游戏 (线段树)

    题目链接 Solution 一个简单的 或 线段树.竟然坑了我一个小时... 因为颜色很小,所以把状态压起来. 然后每个节点上的数值代表当前颜色状态. 然后节点合并很简单,直接或起来. 需要注意一下的 ...

  6. python3的cookielib

    http://stackoverflow.com/questions/8405096/python-3-2-cookielib

  7. Brain Powerd计划

    Brain Powerd这片子没有高清的版本,只有DVD..(我手上只有个DVDRip,X2字幕组的)同时字幕质量也不行. 开个坑用waifu2x压个好看一点(用DVDRip)的,码率大概是3.3M ...

  8. 访问外网 ML2 的配置

    通过 router 可以实现位于不同 vlan 中的 instance 之间的通信. 接下来要探讨的问题是 instance 如何与外部网络通信. 这里的外部网络是指的租户网络以外的网络. 租户网络是 ...

  9. js回到顶部

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. 【git】把本地项目和远程git仓库相连通

    1. 打开在你的项目文件夹,输入下面的命令 git init 输完上面的命令,文件夹中会出现一个.git文件夹,如下图所示,其他的的文件也会出现蓝色小问号的标志 2. 添加所有文件 git add . ...