<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://www.jackxiang.com/post//</link>
<title><![CDATA[内核参数调整消息队列设置]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Unix/LinuxC技术]]></category>
<pubDate>Sun, 06 Sep 2015 08:47:57 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	背景：想要做一个高性能的框架也好，其实还是站在内核上面跳舞，为此，其对内核的设置很重要，就以swoole来讲，其queque是基于epoll，进程间通讯用到内核的que，当然要设置它 了，再就是消息队列这块的通讯，是不是也得设置，这块还有高并发的句柄这块，也需要设置为更大。这块linux下的epoll和freebsd的kqueque都要设置一下，否则，用不上内核的能力也就问题大了，swoole的nginx配置到swoole的通讯用unix socket dgram，也需要配置，你可能说这个框架性能不行了，其实性能是一个综合体，不是一个框架就能说明的。<br/><br/>当使用消息队列作为进程间通信方式时，需要调整此内核参数<br/><br/>kernel.msgmnb = 4203520，消息队列的最大字节数<br/>kernel.msgmni = 64，最多允许创建多少个消息队列<br/>kernel.msgmax = 8192，消息队列单条数据最大的长度<br/><br/>————————————————————————————<br/>ulimit设置<br/><br/>ulimit -n 要调整为100000甚至更大。 命令行下执行 ulimit -n 100000即可修改。如果不能修改，需要设置 /etc/security/limits.conf，加入<br/><br/>* soft nofile 262140<br/>* hard nofile 262140<br/>root soft nofile 262140<br/>root hard nofile 262140<br/>* soft core unlimited<br/>* hard core unlimited<br/>root soft core unlimited<br/>root hard core unlimited<br/>内核设置<br/><br/>net.unix.max_dgram_qlen = 100<br/><br/>swoole使用unix socket dgram来做进程间通信，如果请求量很大，需要调整此参数。系统默认为10，可以设置为100或者更大。<br/>或者增加worker进程的数量，减少单个worker进程分配的请求量。<br/><br/>net.core.wmem_max<br/><br/>修改此参数增加socket缓存区的内存大小<br/><br/>net.ipv4.tcp_mem&nbsp;&nbsp;=&nbsp;&nbsp; 379008&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 505344&nbsp;&nbsp;758016<br/>net.ipv4.tcp_wmem = 4096&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;16384&nbsp;&nbsp; 4194304<br/>net.ipv4.tcp_rmem = 4096&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;87380&nbsp;&nbsp; 4194304<br/>net.core.wmem_default = 8388608<br/>net.core.rmem_default = 8388608<br/>net.core.rmem_max = 16777216<br/>net.core.wmem_max = 16777216<br/>net.ipv4.tcp_tw_reuse<br/><br/>是否socket reuse，此函数的作用是Server重启时可以快速重新使用监听的端口。如果没有设置此参数，会导致server重启时发生端口未及时释放而启动失败<br/><br/>net.ipv4.tcp_tw_recycle<br/><br/>使用socket快速回收，短连接Server需要开启此参数<br/><br/>消息队列设置<br/><br/>当使用消息队列作为进程间通信方式时，需要调整此内核参数<br/><br/>kernel.msgmnb = 4203520，消息队列的最大字节数<br/>kernel.msgmni = 64，最多允许创建多少个消息队列<br/>kernel.msgmax = 8192，消息队列单条数据最大的长度<br/><br/>开启CoreDump<br/><br/>设置内核参数<br/><br/>kernel.core_pattern = /data/core_files/core-%e-%p-%t<br/>通过ulimit -c命令查看当前coredump文件的限制<br/><br/>ulimit -c<br/>如果为0，需要修改/etc/security/limits.conf，进行limit设置。<br/><br/>开启core-dump后，一旦程序发生异常，会将进程导出到文件。对于调查程序问题有很大的帮助<br/>其他重要配置<br/><br/>net.ipv4.tcp_syncookies=1<br/>net.ipv4.tcp_max_syn_backlog=81920<br/>net.ipv4.tcp_synack_retries=3<br/>net.ipv4.tcp_syn_retries=3<br/>net.ipv4.tcp_fin_timeout = 30<br/>net.ipv4.tcp_keepalive_time = 300<br/>net.ipv4.tcp_tw_reuse = 1<br/>net.ipv4.tcp_tw_recycle = 1<br/>net.ipv4.ip_local_port_range = 20000 65000<br/>net.ipv4.tcp_max_tw_buckets = 200000<br/>net.ipv4.route.max_size = 5242880<br/>查看配置是否生效<br/><br/>如：修改net.unix.max_dgram_qlen = 100后，通过<br/><br/>cat /proc/sys/net/unix/max_dgram_qlen<br/>如果修改成功，这里是新设置的值。<br/><br/>摘自：http://wiki.swoole.com/wiki/page/11.html<br/>本地socket--SOCK_DGRAM方式：http://blog.csdn.net/shanzhizi/article/details/16883601
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] 内核参数调整消息队列设置]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>