Chinaunix

标题: [有奖讨论]FreeBSD性能的优化,您会怎么做?(获奖名单已公布-2012-12-5) [打印本页]

作者: iceblood    时间: 2012-10-25 16:55
标题: [有奖讨论]FreeBSD性能的优化,您会怎么做?(获奖名单已公布-2012-12-5)
获奖名单已公布,详情请看:http://bbs.chinaunix.net/thread-4057438-1-1.html

FreeBSD无疑是目前众多开源OS中最优秀的系统之一,然而对于默认安装的FreeBSD为适应各种不同的环境,都会对系统做适当的优化。在优化方式上又有着不同的选择。大家很多时候会选择FreeBSD作为自己的服务器或者个人操作系统,但是随着发行版的版本,有的地方有不少改动,但是大部分的性能优化还是通用的,本次我们通过这个话题话,将相关的性能优化总结一下,欢迎大家积极参与!

本题嘉宾:gvim

本期话题:
一、FreeBSD的优化您是重新编译内核还是使用sysctl.conf或者loader.conf?
二、FreeBSD在安装完毕后你都会做那些初始化?
三、列举一些针对某项功能的优化参数。
四、基于第三个问题的服务器硬件配置是什么?(CPU、内存)

范例:
一、FreeBSD的优化您是重新编译内核还是使用sysctl.conf或者loader.conf?
答:对于高负载的一般采用重新编译内核的方法,而对于普通负载,则修改sysctl.conf或者loader.conf。
二、FreeBSD在安装完毕后你都会做那些初始化?
答:启用一个简单的ipfw,用来做一些特定条件的IP限制,设置如下2个参数,提高服务器抗负载的能力:
#系统最大打开文件数
kern.maxfiles=655350
#Unix sock并发连接数
kern.ipc.maxsockets=65535
#网络并发连接数
kern.ipc.somaxconn=65535
三、列举一些针对某项功能的优化参数。
针对ipfilter防火墙及NAT功能的优化:
/sbin/ipf -D
/sbin/sysctl net.inet.ipf.fr_tcpidletimeout=7200
/sbin/sysctl net.inet.ipf.fr_defnatage=240
/sbin/sysctl net.inet.ipf.ipf_nattable_sz=32767
/sbin/sysctl net.inet.ipf.ipf_natrules_sz=16383
/sbin/sysctl net.inet.ipf.ipf_rdrrules_sz=16383
/sbin/sysctl net.inet.ipf.ipf_hostmap_sz=32767
/sbin/sysctl net.inet.ipf.fr_tcptimeout=60
/sbin/sysctl net.inet.ipf.fr_tcpclosewait=30
/sbin/sysctl net.inet.ipf.fr_tcphalfclosed=90
/sbin/sysctl net.inet.ipf.fr_tcpclosed=60
/sbin/sysctl net.inet.ipf.fr_tcplastack=60
/sbin/sysctl net.inet.ipf.fr_statemax=32767
/sbin/sysctl net.inet.ipf.fr_statesize=32767
/sbin/ipf -E
/sbin/ipnat -F -f /etc/ipnat.rules
四、基于第三个问题的服务器硬件配置是什么?(CPU、内存)
CPU: Intel(R) Xeon(R) CPU           X3430  @ 2.40GHz (2394.00-MHz K8-class CPU)
  Origin = "GenuineIntel"  Id = 0x106e5  Stepping = 5
  Features=0xbfebfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CLFLUSH,DTS,ACPI,MMX,FXSR,SSE,SSE2,SS,
  Features2=0x98e3fd<SSE3,DTES64,MON,DS_CPL,VMX,SMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,SSE4.1,SSE4.2,POPCNT>
  AMD Features=0x28100800<SYSCALL,NX,RDTSCP,LM>      
  AMD Features2=0x1<LAHF>                             
  TSC: P-state invariant                              
real memory  = 2147483648 (2048 MB)                  
avail memory = 2053672960 (1958 MB)   


活动时间:
2012.10.25-11.15

活动奖品:


我们为参与本次讨论,发表最有价值内容的网友准备了余洪春《构建高可用Linux服务器(第二版)》一书5本 作为本次活动的奖励!欢迎大家积极参与!(这书里有不少FreeBSD的内容哈




作者: fender0107401    时间: 2012-10-25 16:59
个人经验:最好别做。
作者: ulovko    时间: 2012-10-25 17:01
支持一下 ^_^
作者: iceblood    时间: 2012-10-25 17:03
fender0107401 发表于 2012-10-25 16:59
个人经验:最好别做。

我觉得个人经验可以给人以参考,只有完全不会的人才会照抄,而懂的人则会根据别人的经验进行吸收并消化。因此我觉得相互借鉴西还是有必要的。
作者: meego2012    时间: 2012-10-25 17:04
fender0107401 发表于 2012-10-25 16:59
个人经验:最好别做。


版主之间来拆台了哈
作者: meego2012    时间: 2012-10-25 17:05
反正bsd下安装msyql挺操蛋的,我直接打包了一个,解压到/var下用,不敢安装,贼麻烦
作者: send_linux    时间: 2012-10-25 17:05
meego2012 发表于 2012-10-25 17:04
版主之间来拆台了哈


这是鼓励大家的交流,不是拆台,不要误会
作者: fender0107401    时间: 2012-10-25 17:25
回复 6# meego2012

这说明你不会按。。。

   
作者: fender0107401    时间: 2012-10-25 17:26
回复 4# iceblood

最好还是别做。
作者: gvim    时间: 2012-10-25 20:28
都很矜持啊,我相信比我能的人很多在潜水,也有血的教训总结出来的“最好别做”,总舵赞助咱搞个专题讨论讨论,不才就先抛个砖吧
虽然这个话题放在BSD来做,但我觉得优化本身已经超出这个范畴了。
我是做程序员出身,因为比较喜欢摆弄各种系统,在前一个公司的时候系统管理和优化对我算是个副业,弄Linux相对多一些。
优化是软件工业里面最复杂最要求全面的方向之一,个人觉得就是寻找个人技能和性能瓶颈的平衡。可是就像学武功似得,九阳神功第一从还没联熟练,很多人就想着摆弄第九从,所以说过早的优化最好别做,不懂的优化最好别做。
优化在我看来分三个层面:应用系统优化,优化一般效果最明显。包括应用软件体系和设计,框架的选择和调优,算法的选择,如果有虚拟机的平台还包括虚拟机优化(虚拟机自己也相当于是个操作系统,所以比如java之类的优化比C/C++的影响因素更多更不好跟)。有时候会追求效率而跳过比较好的设计方式,框架也是没办法的有时候必须考虑团队的整体可操作能力和框架性能、扩展的平衡,这个地方做优化需要对目标系统的平台和应用业务有相当了解,如果有数据库还需要对数据库有相当了解,比如SQL自己的优化能力。这个领域实在很大。第二个层面是系统优化,也就是这里讨论的调优。系统包括操作系统,数据库服务器,web服务器,缓冲,代理服务器等等系统组建,重要的还是上一层整体的设计。这里比如得了解你用的web服务器,操作系统的网络模型,熟悉这些系统的IO模型,内存模型,调度模型,有时候硬盘的驱动模型都需要有所了解,还有比如大文件多还是小文件多,一段时间会产生多少流量,新生多少文件,数据库链接和访问量,峰值量大概,比如线程,进程,epollkqueue还是select,数据库自身的优化是启发式还是近乎暴力,数据库对内存的管理方式,如果是裸数据还看数据库的文件系统,第三个是物理层,这里就没办法了,加内存,加带宽,加硬盘。。。

一、FreeBSD的优化您是重新编译内核还是使用sysctl.conf或者loader.conf?
个人做优化的时候一般会准备所有系统组件的代码在手边随时查看某个部分的实现和参数带来的影响,比如sysctl(Linux也有类似的东西)的时候我个人会查资料,然后看代码大致了解这个参数能影响的局面,通过调试代码和测试数据看参数设置成多少比较合适。内核代码里有些好几个参数在一个文件里面出现的需要多注意一点,这种情况意味着这几个参数可能互相影响而不应该单独考虑某一个。
调优很费精力很费神,各种工具,各种系统,各种业务,各种环境的交叉影响,没几年时间熟悉他们的全部,也就不敢揽这个活。前一个公司有些系统整的。。。调了不如不调。所有我能理解fender0107401为什么这么说。

三、列举一些针对某项功能的优化参数
优化参数不好说,的看目的系统的环境,压力等等

四、基于第三个问题的服务器硬件配置是什么?(CPU、内存)
我的服务器是IBM入门级u1,志强2的频率忘了,内存2G。现在一般用pc做实验。
等过段时间攒了钱打算买10个RPi回来做集群玩玩。


我非专业SA,所以上面罗嗦的东西都是我自己乱搞的方式,说出来希望能有更多人分享自己的调优心得,经验,教训,工具,故事等等等等。
作者: meego2012    时间: 2012-10-25 20:42
fender0107401 发表于 2012-10-25 17:25
回复 6# meego2012

这说明你不会按。。。

版主说的对哈,我只是提个意见
我在linux下安装就很容易,直接apt-get就可以了

为啥bsd就做的这么难使用,这难道是特色么?
作者: fender0107401    时间: 2012-10-26 08:20
meego2012 发表于 2012-10-25 20:42
版主说的对哈,我只是提个意见
我在linux下安装就很容易,直接apt-get就可以了


你认为所有的linux都能apt-get install foo吗?
作者: meego2012    时间: 2012-10-26 09:45
fender0107401 发表于 2012-10-26 08:20
你认为所有的linux都能apt-get install foo吗?


我用的ubuntu和Fedora是可以这样的,之前也试验过archlinux,也是可以这样的

我没有必要这这里撒谎啊
作者: fender0107401    时间: 2012-10-26 09:47
meego2012 发表于 2012-10-26 09:45
我用的ubuntu和Fedora是可以这样的,之前也试验过archlinux,也是可以这样的

我没有必要这这里撒谎啊 ...


fedora和archlinux也移植了apt系统?
作者: meego2012    时间: 2012-10-26 10:02
fender0107401 发表于 2012-10-26 09:47
fedora和archlinux也移植了apt系统?


当然不是啊,他们是自己的包管理系统的啊,但是包依赖的关系解决的比较好,至少比FreeBSD的好
作者: fender0107401    时间: 2012-10-26 10:05
meego2012 发表于 2012-10-26 10:02
当然不是啊,他们是自己的包管理系统的啊,但是包依赖的关系解决的比较好,至少比FreeBSD的好


扯淡。
作者: ulovko    时间: 2012-10-26 10:34
meego2012 发表于 2012-10-26 10:02
当然不是啊,他们是自己的包管理系统的啊,但是包依赖的关系解决的比较好,至少比FreeBSD的好

我个人感觉freebsd做的更好、管理也方便! ^_^
作者: lsstarboy    时间: 2012-10-26 14:56
楼上几位,有脚踏骑三轮车的经验吗?
一直骑两轮的自行车,直接上三轮车,有很大机率冲入路边的渠道里。
作者: lsstarboy    时间: 2012-10-26 15:33
本帖最后由 lsstarboy 于 2012-10-26 15:41 编辑

一、FreeBSD的优化您是重新编译内核还是使用sysctl.conf或者loader.conf?
    1、作为服务器用,重新编译内核是必须的,主要目的有两个:(1)去掉一些不用的模块,使内核更小,加载的速度会更快;
  (2)加一些优化的参数,性能会更好。
    我必用的几个:
        去掉调试信息:makeoptions, KTRACE,stack,
        我不用nfs,所以也去掉
        ipv6去掉,用不着, sctp也用不到
        所有的scsi系列,都是ahci了,服务器一般也不需要U盘,usb和1394都禁掉
        网卡当然保留需要的
        
        smp必用,现在都是多核;
        HZ和polling必用,网卡性能会更好;
        建议把dummynet加上,说不上什么时候就需要控制流量
        我习惯ipfw,把ipfw的那一套加上吧,具体有:
  1. options         LIBALIAS
  2. options         IPFIREWALL              #firewall
  3. options         IPFIREWALL_VERBOSE      #enable logging to syslogd(8)
  4. options         IPFIREWALL_VERBOSE_LIMIT=100    #limit verbosity
  5. options         IPFIREWALL_DEFAULT_TO_ACCEPT    #allow everything by default
  6. options         IPFIREWALL_FORWARD      #packet destination changes
  7. options         IPFIREWALL_NAT          #ipfw kernel nat support
  8. options         IPDIVERT                #divert sockets
  9. options         IPSTEALTH               #support for stealth forwarding
复制代码
新机器别忘了把ahci加上,测试的成绩可能不明显,但是用起来很有效果。
            
    2、sysctl.conf和loader.conf,这两个都要用,用的目的不一样,我的原则是能在sysctl.conf中用的,尽量不要loader.conf中写,一般loader.conf中处理硬件相关的内容,sysctl.conf中处理系统相关的东西。
        具体参数在第三个问题中写。
   
   
二、FreeBSD在安装完毕后你都会做那些初始化?
      1、rc.conf
  1. sshd_enable="yes"
  2. syslogd_enable="yes"
  3. syslogd_flags="-s -s"
  4. sendmail_enable="NONE"
复制代码
2、.cshrc
  1. setenv  PACKAGESITE ftp://ftp.jp.freebsd.org/pub/FreeBSD/ports/amd64/packages-9-stable/Latest/
复制代码
三、列举一些针对某项功能的优化参数。
  做natd服务器的部分常用sysctl.conf:
  1. net.inet.tcp.blackhole=2
  2.   net.inet.udp.blackhole=1

  3.   kern.ipc.somaxconn=8192
  4.   kern.ipc.maxsockets=204800
  5.   kern.ipc.shmmax=2147483648
  6.   kern.ipc.nmbclusters=262144

  7.   net.inet.tcp.msl=2000
  8.   net.inet.tcp.always_keepalive=1
  9.   net.inet.tcp.fast_finwait2_recycle=1
  10.   
  11.   #kern.maxfiles=204800
  12.   #kern.maxfilesperproc=200000
  13.   #kern.maxvnodes=200000
  14.   
  15. kern.timecounter.hardware=HPET
  16.   
  17.   net.inet.tcp.sendspace=16384
  18.   net.inet.tcp.recvspace=16384
  19.   net.inet.udp.recvspace=65535
  20.   net.inet.udp.maxdgram=57344
  21.   net.local.stream.sendspace=65535
  22.   
  23.   net.inet.tcp.drop_synfin=1
  24. #  net.inet.ip.portrange.randomized=0
  25.   
  26.   net.inet.tcp.keepidle=60000
  27.   
  28.   
  29.   net.inet.ip.redirect=0
  30.   net.inet.ip.sourceroute=0
  31.   net.inet.ip.accept_sourceroute=0
  32.   net.inet.icmp.maskrepl=0
  33.   net.inet.icmp.log_redirect=0
  34.   net.inet.icmp.drop_redirect=1
  35.   net.inet.tcp.icmp_may_rst=0
复制代码
四、基于第三个问题的服务器硬件配置是什么?(CPU、内存)
我用的目前大多数都是pc服务器,dmesg节选:
  1. CPU: Intel(R) Xeon(R) CPU           E5504  @ 2.00GHz (2000.11-MHz K8-class CPU)
  2. real memory  = 4299161600 (4100 MB)
  3. ahci0: AHCI v1.20 with 6 3Gbps ports, Port Multiplier not supported
  4. em0: <Intel(R) PRO/1000 Network Connection 7.2.3> port 0xcc00-0xcc1f mem 0xfbce0000-0xfbcfffff,0xfbcdc000-0xfbcdffff irq 16 at device 0.0 on pci5
  5. hpet0: <High Precision Event Timer> iomem 0xfed00000-0xfed003ff on acpi0
  6. Timecounter "HPET" frequency 14318180 Hz quality 950
  7. qpi0: <QPI system bus> on motherboard
  8. ada0: 300.000MB/s transfers (SATA 2.x, UDMA6, PIO 8192bytes)
  9. ada0: Command Queueing enabled
  10. ada0: 476940MB (976773168 512 byte sectors: 16H 63S/T 16383C)
  11. ada1: <WDC WD5003ABYX-01WERA1 01.01S02> ATA-8 SATA 2.x device
  12. ada1: 300.000MB/s transfers (SATA 2.x, UDMA6, PIO 8192bytes)
  13. ada1: Command Queueing enabled
  14. ada1: 476940MB (976773168 512 byte sectors: 16H 63S/T 16383C)

复制代码

作者: linpay2000    时间: 2012-10-26 15:36
对于第一个问题来说,我一般选择编译内核一下,按网络上的教程稍改下参数。做点心理安慰,个人经验一般不会有问题。性能提升多少,不好说。
内存占用肯定会少些。
至于防火墙这样的东东,简单配置一下,封封端口。
其它的一般不会做,还是和楼上大虾的思路一样,应用优化比较多一些。因为那样出问题自己能控制得了。
作者: iceblood    时间: 2012-10-26 15:43
To lsstarboy
02.real memory  = 4299161600 (4100 MB)

你的内存数好奇怪。VPS?
作者: lsstarboy    时间: 2012-10-26 19:02
本帖最后由 lsstarboy 于 2012-10-26 19:07 编辑

回复 21# iceblood


    实体机,4G DDR3 ,等会找光驱启动另一台4G PC试试。
   好像FreeBSD一直这样,不知道那4M是怎么多出来的。

---------------------------------------

  试了,pc 普通的ddr2 800,是4096,难道是ECC? 或者是主板的显卡带显存?
作者: dreampili    时间: 2012-10-26 20:53
怎么优化都是经验之谈,但是没理论的支撑很难啊,这是我使用中的体会

BSD是一个干净的系统,但我常用的资料仅仅有手册,出版物市面上似乎并不多,如果能多一些软件使用方面的心得就好了。

身边没有同道中人,遇到问题都是百度,谷歌,要么就是来这里看看大家发的帖子,也不敢随便说话,怕说的浅了大家笑话,说的不对了误导后来人。


作者: lsstarboy    时间: 2012-10-27 12:29
回复 23# dreampili


    优化的这些都是有理论支撑的,看别人的优化项目,也需要跟自己的环境对比,不是每个参数都需要的。

 比如net.inet.tcp.msl这个参数,调得小一些,会让更快地释放连接资源,特别是小包多,或者受到攻击的时候,效果非常明显,大的网络最好弄小一些。
 但是家用反而效果不好,频繁地清除、新建连接会白白增加系统负担,在adsl等网络不好的情况下更明显。
作者: king_819    时间: 2012-10-27 15:36
回复 2# fender0107401


    个人经验,内核优化,这个可以有
作者: king_819    时间: 2012-10-27 15:38
关于内核 优化这个要根椐实际情况来看

根椐自己的硬件来加载对应的驱动,其它模块也是一样
作者: fender0107401    时间: 2012-10-27 17:44
king_819 发表于 2012-10-27 15:36
回复 2# fender0107401


这个吗,感觉效果也不明显,比如说删除了内核里面的不使用驱动,那就能小一点,但是现在的内存都这么大,这个基本上可以忽略了。

别的吗不好说。

FreeBSD的内核编译并没有给用户提供特别多的选择,

用Linux的话选择会有很多选择,我定制Linux内核的时候经常修改很多选项,比如删除多于的驱动,删除多于的调度器算法(IO的、网络的)。但是效果吗,没什么感觉,算数据的时候还是差不多,而且定制多了有可能会无法编译。 :wink:

以前还指定make.conf的cpu选项和优化级别,现在这些基本上都省了。

我这边同样的硬件是FreeBSD最快,然后是Gentoo,最后是Debian。

我感觉基本上怎么优化,也不太可能改变这个顺序。
作者: mirnshi    时间: 2012-10-27 22:40
一、FreeBSD的优化您是重新编译内核还是使用sysctl.conf或者loader.conf?
看看是否会涉及到只有编译内核才会有效的优化,不过大部分都是可以通过sysctl优化的。sysctl和loader.conf,是有些区别的,勿以为二者相同,loader.conf里的配置集是小于sysctl的,原因在于只有某些配置项,在内核里可以通过TUNABLE_xxx_FETCH()加载进来。
但在一些测试环境里,会重新优化编译内核,比如设置内核空间的大小,很久之前,曾有讨论过mfs问题,这就涉及到内核空间问题,一般是需要重新编译内核的。

二、FreeBSD在安装完毕后你都会做那些初始化?
如果安装盘的版本比较久,最大的可能性,就是同步更新到最新的版本,或者安装一些port里的程序,比如wget/lsof之类的。如果是公网服务,就要检查是否有额外的端口开放出去了,ssh端口是否修改成非标准的,密码是否足够长,比如10位以上的大小写字母+数字+其他字符

三、列举一些针对某项功能的优化参数。
可能会对磁盘,尤其大规模访问,做出不同的分配,大文件的块可能要大一些。小文件量很大,可能要降低块,提高inode. 所以一般数据盘都会安装后再创建文件系统,没必要安装时做。

四、基于第三个问题的服务器硬件配置是什么?(CPU、内存)
这个主要还是看服务器的用途,如果是普通的文件服务器,现在的主流配置或者前几年的都足够用了。当作前置负载,也无需那么高的配置。FreeBSD的网络协议栈是很简洁高效的。
作者: mirnshi    时间: 2012-10-27 22:50
回复 19# lsstarboy

HZ和polling必用,网卡性能会更好;

   
提高HZ会提高中断数,也就是会额外增加CPU的中断响应次数,也就相同增加了CPU的占用,如果网络不是非常繁忙,没必要提高HZ,基本缺省足够了,但是虚拟机里,降低HZ,会减少CPU的占用。

轮询,如果小包不是非常多,或者不是非常高的网络流量,也没有必要的,有一个好一些的网卡足以应付的,比如Intel的82574,有些桌面级的网卡还是不要用于网络服务上面。

优化哪些参数,需要根据实际的环境/瓶颈,没有通用的。如果有普世效果,早就增加到发行版里了。
作者: mirnshi    时间: 2012-10-27 22:55
fender0107401 发表于 2012-10-27 17:44
这个吗,感觉效果也不明显,比如说删除了内核里面的不使用驱动,那就能小一点,但是现在的内存都这么大 ...


BSD内核配置一直就是非常简洁的,包括基于BSD的SunOS都是如此。但在NOTES里,有比较详细的说明以及没有出现GENERIC里的配置项。
作者: mirnshi    时间: 2012-10-27 22:56
回复 6# meego2012

pkg_add不能满足要求吗?
   
作者: mirnshi    时间: 2012-10-27 23:01
7以后的版本,性能已经非常好了,稍微调整一些网络参数,做个简单的优化,就可以在一些机器上跑双向10G的流量。所以对于普通的服务,尽管用就是了,无需担心。
作者: lsstarboy    时间: 2012-10-27 23:25
回复 29# mirnshi


    支持!具体的参数优化还要看使用环境,就像我在24楼提到的那个msl一样,用的不恰当反而拖累系统。特别是防火墙和NAT,要根据实际的情况来调整,防火墙要根据不同应用和攻击手段来进行防范。我所在的网络经常换策略,某段时间icmp攻击多,就禁掉icmp;有此时候p2p多,就进行限速或限连接数;到了udp超多的时候,干脆就把udp全禁了,领导看视频也不开。
作者: lsstarboy    时间: 2012-10-27 23:29
mirnshi 发表于 2012-10-27 22:40
三、列举一些针对某项功能的优化参数。
可能会对磁盘,尤其大规模访问,做出不同的分配,大文件的块可能要大一些。小文件量很大,可能要降低块,提高inode. 所以一般数据盘都会安装后再创建文件系统,没必要安装时做。


这个确实是必须考虑的,做raid的时候也需要特别注意,有很多人觉得raid快不了多少,其实很多是跟块(簇)的策略有关。
作者: mirnshi    时间: 2012-10-27 23:32
回复 34# lsstarboy

用raid(5)是为了快,这个想法就是错误的。raid(5)是为了安全
   
作者: mirnshi    时间: 2012-10-27 23:42
lsstarboy 发表于 2012-10-27 23:25
回复 29# mirnshi


弄个panabit就行了,做流控呗
作者: lsstarboy    时间: 2012-10-28 17:48
回复 36# mirnshi


    包月的线路,如果一直做着流控有点浪费带宽,p2p少的时候,还是尽量快一点。
作者: tulip0425    时间: 2012-10-28 20:57
好啊楼主,没想到啊,太好了
作者: huanliuzu    时间: 2012-10-28 21:32
回复 33# lsstarboy


    在单机上双向10G么,没有跑过这么高的流量,能否把优化具体说一下?3ks
作者: action08    时间: 2012-10-29 10:13
本帖最后由 action08 于 2012-10-29 10:15 编辑

反正我也觉得一个人,光凭一股好学上进的劲儿看几本书,就开始大谈性能优化,
这世上哪有这么容易成功的捷径哦,

还是支持请一些走过不少路的人来谈,


个人认为,手册帮N当家的斑竹的建议没错,优化别做
作者: action08    时间: 2012-10-29 10:21
本帖最后由 action08 于 2012-10-29 10:31 编辑

@fender0107401

拆台的也欢迎来说说,心得经验什么的呀,

新人还是蛮爱听这些的
作者: action08    时间: 2012-10-29 10:26
这是一个kernel编译性能优化的开门辞,来自centos

Are you sure? CentOS is designed to function as a complete environment. If you replace a critical component, it may very well affect how the rest of the system acts.
ARE YOU ABSOLUTELY SURE? Seriously, 99.9% of users no longer need to rebuild their own kernel.....
...etc

http://wiki.centos.org/HowTos/Custom_Kernel
作者: meego2012    时间: 2012-10-29 13:36
action08 发表于 2012-10-29 10:26
这是一个kernel编译性能优化的开门辞,来自centos

Are you sure? CentOS is designed to function as a ...


不过有的时候真的需要定制一些内容,比如一些特定功能的机器,比如服务器上,那些无线的驱动啥的,音频的支持啥的,这些直接去掉吧,真没啥用

那个之所以这么写,是怕那些菜鸟们瞎搞,kernel给dump了就惨了
作者: lsstarboy    时间: 2012-10-29 13:50
回复 39# huanliuzu


    10M行不?
作者: lsstarboy    时间: 2012-10-29 13:56
回复 40# action08


    优化不做的话,负载小还能凑合,稍大点就完了。

 比如我的经验:
   php的课程管理系统claroline,仅用默认设置,nginx+fpm最高并发数是200,230都报502错误,但是优化一下的话,可以到500以上不报错。

   防火墙,用ipfw内核nat,不优化的话,能到60、70M就不错了,优化后可以地跑到300M——千兆的线路。
作者: action08    时间: 2012-10-29 14:05
本帖最后由 action08 于 2012-10-29 14:10 编辑

回复 45# lsstarboy


    谢谢你的分享,目前我也在做nginx php方面的东西,

可以分享一下,优化了那些细节做到性能负载翻了一倍的??
作者: action08    时间: 2012-10-29 14:13
本帖最后由 action08 于 2012-10-29 15:02 编辑

跟新手分享说明一下,nginx出502,基本是php-fpm跟不上反映的问题,

nginx本身很轻巧,还是比较适合在压力环境下工作的
作者: lsstarboy    时间: 2012-10-29 14:30
回复 47# action08


    对啊!就是php跟不上了,php的日志里面,都是打开错误。
 参数19楼的基本都列举了,我注释掉的几个跟php性能有点关系,跟防火墙关系不大。
 把fpm的socket放内存盘中,性能也能提升一点,不是很大,但稍有提高。
 
 我现在把fpm多开了一个,用nginx做均衡,效果非常好,现在整个系统的瓶颈在mysql了,php基本上不拖后腿。
 
作者: lsstarboy    时间: 2012-10-29 14:58
本帖最后由 lsstarboy 于 2012-10-29 14:58 编辑

再说一个php的优化:

环境:
FreeBSD9.0+Nginx+php-fpm+mysql,跟课程管理系统claroline

现象:
用ab测试首页,超过220并发就出现大量的failed页面。同时top中显示php-fpm状态出现locked,用其他机器访问的时候出现502。
网上的设置基本都试过,效果不是很明显。

原因(只是自已猜测,没查到权威的解释):
    nginx发起的连接数,远远超过了php-fpm所能处理的数目,导致端口(或socket)频繁被锁,造成堵塞。

解决思路:
运行两个(或多个)php-fpm实例,各听一个端口或socket,这样就减少了lock

方案:
1、fpm2的调整(FreeBSD下)
  (1)进入/usr/local/etc,复制php-fpm.conf为php-fpm2.conf,并修改占用的端口(socket)
  (2)复制rc.d/php-fpm为rc.d/php-fpm2,进行修改,把所有的fpm都替换为fpm2,并添加:
  

    start_precmd="${name}_prestart"

    php_fpm2_prestart()
    {
            rc_flags="-y /usr/local/etc/php-fpm2.conf"
    }

 (3)在rc.conf中添加:php_fpm2_enable="yes"

2、nginx的调整:

    upstream backend{
       server 127.0.0.1:9000;
       server 127.0.0.1:9002;
      }
      
      
    server {
              listen 80;
              server_name a.b.cd.com;
              charset utf-8;
……
      
              location ~ \.php$ {
                  root /var/www;
                   fastcgi_pass backend
      ……
                }
    }


3、socket的优化:
   用md系统,要比普通文件系统快不少。

作者: mirnshi    时间: 2012-10-29 15:06
lsstarboy 发表于 2012-10-29 13:56
回复 40# action08


印象里ipfw做nat效果就是很差,ipnat就好多了。
作者: action08    时间: 2012-10-29 15:07
lsstarboy 发表于 2012-10-29 14:58
再说一个php的优化:

环境:


我们来稍微谈点程序方面的issue

你们php连接mysql是怎么连接的?
我的经验把代码种所有连接全部换成持久版的 mysql_pconnect,性能可以做得更好
作者: action08    时间: 2012-10-29 15:09
mysql_pconnect能很有效的解决占用系统文件句柄的问题,

如果效果理想,完全可以忽略对os层面调整limit的那个句柄参数
作者: mirnshi    时间: 2012-10-29 15:22
lsstarboy 发表于 2012-10-29 14:58
再说一个php的优化:

环境:


貌似可以用unix socket来通信吧,这个要快一些。另外,可以根据CPU或者瓶颈所在,增加一些php-cgi进程数
作者: action08    时间: 2012-10-29 15:26
@mirnshi
增加一些php-cgi进程数



你好,欢迎分享一下,CPU和当前分配php-cgi的进程数
作者: mirnshi    时间: 2012-10-29 15:27
meego2012 发表于 2012-10-29 13:36
不过有的时候真的需要定制一些内容,比如一些特定功能的机器,比如服务器上,那些无线的驱动啥的,音频 ...


除非内核有缺陷,普通用户想搞瘫kernel基本没戏。
作者: meego2012    时间: 2012-10-29 15:35
mirnshi 发表于 2012-10-29 15:27
除非内核有缺陷,普通用户想搞瘫kernel基本没戏。


兄弟,免责声明一般写的都比较咋呼,就是为以防万一的啊
作者: mirnshi    时间: 2012-10-29 15:53
action08 发表于 2012-10-29 15:26
@mirnshi

先要知道瓶颈在哪,再考虑下步优化。
作者: lsstarboy    时间: 2012-10-29 16:20
回复 53# mirnshi


    一般说,php进程太多也不行,除非上几百。但几百个进程后,虽然出现502,但性能会下降,并且出现大量的locked。

http://blog.chinaunix.net/uid-20332519-id-3357066.html
作者: lsstarboy    时间: 2012-10-29 16:21
回复 50# mirnshi


    ipfw相比pf来说,不会差很多,特别是内核nat以后,性能还是很不错的。
作者: lsstarboy    时间: 2012-10-29 16:24
回复 54# action08


    应该跟具体的应用有关系,我现在用的claroline,php-fpm进程总数大约为CPU数*2的样子,用ab测的每秒页数最大。

 但是dedecms好像要到几十性能才最好。
作者: lsstarboy    时间: 2012-10-29 16:30
回复 52# action08


    我还没有用持久连接,不了解效果。因为目前系统速度还可以,计划先折腾pdo,pdo折腾的差不多了再测试持久连接的效果。
作者: zhengwei_zw    时间: 2012-10-29 17:13
长连接会消耗mysql的资源。要看网站类型。比如论坛。就没有必要
如果是交易系统,可以用
作者: action08    时间: 2012-10-29 17:19
本帖最后由 action08 于 2012-11-08 15:01 编辑

@lsstarboy
{:3_187:} {:3_188:}
作者: mirnshi    时间: 2012-10-29 17:38
lsstarboy 发表于 2012-10-29 16:21
回复 50# mirnshi


ipfw借用libalias做nat,由于libalias并不是特意跑内核的,所以能否高效的跑在内核,还是有待验证的。做nat是比较简单的事情,开发人员只是想更加省事而已,或者不想做大改动。

早期,ipfilter的效率要高过pf的,只是不知道现在pf进化得如何了。
作者: mirnshi    时间: 2012-10-29 17:42
lsstarboy 发表于 2012-10-29 16:20
回复 53# mirnshi


优化不能单一,而是要根据瓶颈来做的。你优化A后,B成了瓶颈,你再怎么调整A,都是无效果的了。
作者: action08    时间: 2012-10-29 17:50
回复 65# mirnshi


    看来你走得路不少,欢迎分享哦{:3_183:}
作者: lsstarboy    时间: 2012-10-29 19:22
终于找到印象最深的那个老外的文章了,从上面学习了很多东西,比网上疯传的那几个强多了,原来好像只到8,现在已经跟进到9了:

转部分,详情请参照原文:

sysctl.conf
# No zero mapping feature
# May break wine
# (There are also reports about broken samba3)
#security.bsd.map_at_zero=0

# Servers with threading software apache2 / Pound may want to rise following sysctl
#kern.threads.max_threads_per_proc=4096

# Max. backlog size
kern.ipc.somaxconn=4096

# Shared memory // 7.2+ can use shared memory > 2Gb
kern.ipc.shmmax=2147483648

# Sockets
kern.ipc.maxsockets=204800

# Mbuf 2k clusters (on amd64 7.2+ 25600 is default)
# Note that defaults for other variables depend on this variable, for example `tcpreass`
# Note for FreeBSD-7 and older: For such high value vm.kmem_size must be increased to 3G
kern.ipc.nmbclusters=262144

# Jumbo pagesize(_SC_PAGESIZE) clusters
# Used as general packet storage for jumbo frames on some network cards
# Can be monitored via `netstat -m`
#kern.ipc.nmbjumbop=262144

# Jumbo 9k/16k clusters
# If you are using them
#kern.ipc.nmbjumbo9=65536
#kern.ipc.nmbjumbo16=32768

# For lower latency you can decrease scheduler's maximum time slice
# default: stathz/10 (~ 13)
#kern.sched.slice=1

# Increase max command-line length showed in `ps` (e.g for Tomcat/Java)
# Default is PAGE_SIZE / 16 or 256 on x86
# This avoids commands to be presented as [executable] in `ps`
# For more info see: http://www.freebsd.org/cgi/query-pr.cgi?pr=120749
kern.ps_arg_cache_limit=4096

# Every socket is a file, so increase them
kern.maxfiles=204800
kern.maxfilesperproc=200000
kern.maxvnodes=200000

# On some systems HPET is almost 2 times faster than default ACPI-fast
# Useful on systems with lots of clock_gettime / gettimeofday calls
# See http://old.nabble.com/ACPI-fast-default-timecounter,-but-HPET-83--faster-td23248172.html
# After revision 222222 HPET became default: http://svnweb.freebsd.org/base?view=revision&revision=222222
kern.timecounter.hardware=HPET


# Small receive space, only usable on http-server, on file server this
# should be increased to 65535 or even more
#net.inet.tcp.recvspace=8192

# This is useful on Fat-Long-Pipes
#kern.ipc.maxsockbuf=10485760
#net.inet.tcp.recvbuf_max=10485760
#net.inet.tcp.recvbuf_inc=65535

# Small send space is useful for http servers that serve small files
# Autotuned since 7.x
net.inet.tcp.sendspace=16384

# This is useful on Fat-Long-Pipes
#net.inet.tcp.sendbuf_max=10485760
#net.inet.tcp.sendbuf_inc=65535

# Turn off receive autotuning
# You can play with it.
#net.inet.tcp.recvbuf_auto=0
#net.inet.tcp.sendbuf_auto=0

# This should be enabled if you going to use big spaces (>64k)
# Also timestamp field is useful when using syncookies
net.inet.tcp.rfc1323=1
# Turn this off on high-speed, lossless connections (LAN 1Gbit+)
net.inet.tcp.delayed_ack=0

# This feature is useful if you are serving data over modems, Gigabit Ethernet,
# or even high speed WAN links (or any other link with a high bandwidth delay product),
# especially if you are also using window scaling or have configured a large send window.
# Automatically disables on small RTT ( http://www.freebsd.org/cgi/cvswe ... cp_subr.c?#rev1.237 )
# This sysctl was removed in 10-CURRENT:
# See: http://www.mail-archive.com/svn- ... d.org/msg06178.html
#net.inet.tcp.inflight.enable=0

# TCP slowstart algorithm tunings
# Here we are assuming VERY uncongested network
# Only takes effect if net.inet.tcp.rfc3390 is set to 0
# Otherwise formula teken from http://tools.ietf.org/html/rfc3390
#net.inet.tcp.slowstart_flightsize=10
#net.inet.tcp.local_slowstart_flightsize=100


# Disable randomizing of ports to avoid false RST
# Before usage check SA here www.bsdcan.org/2006/papers/ImprovingTCPIP.pdf
# (it's also says that port randomization auto-disables at some conn.rates, but I didn't checked it thou)
#net.inet.ip.portrange.randomized=0

# Increase portrange
# For outgoing connections only. Good for seed-boxes and ftp servers.
net.inet.ip.portrange.first=1024
net.inet.ip.portrange.last=65535

#
# stops route cache degregation during a high-bandwidth flood
# http://www.freebsd.org/doc/en/bo ... curing-freebsd.html
#net.inet.ip.rtexpire=2
net.inet.ip.rtminexpire=2
net.inet.ip.rtmaxcache=1024

# Security
net.inet.ip.redirect=0
net.inet.ip.sourceroute=0
net.inet.ip.accept_sourceroute=0
net.inet.icmp.maskrepl=0
net.inet.icmp.log_redirect=0
net.inet.icmp.drop_redirect=1
net.inet.tcp.drop_synfin=1
#
# There is also good example of sysctl.conf with comments:
# http://www.thern.org/projects/sysctl.conf
#
# icmp may NOT rst, helpful for those pesky spoofed
# icmp/udp floods that end up taking up your outgoing
# bandwidth/ifqueue due to all that outgoing RST traffic.
#
#net.inet.tcp.icmp_may_rst=0

# Security
net.inet.udp.blackhole=1
net.inet.tcp.blackhole=2

# IPv6 Security
# For more info see http://www.fosslc.org/drupal/content/security-implications-ipv6
# Disable Node info replies
# To see this vulnerability in action run `ping6 -a sglAac ::1` or `ping6 -w ::1` on unprotected node
net.inet6.icmp6.nodeinfo=0
# Turn on IPv6 privacy extensions
# For more info see proposal http://unix.derkeiler.com/Mailin ... 08-06/msg00103.html
net.inet6.ip6.use_tempaddr=1
net.inet6.ip6.prefer_tempaddr=1
# Disable ICMP redirect
net.inet6.icmp6.rediraccept=0
# Disable acceptation of RA and auto linklocal generation if you don't use them
#net.inet6.ip6.accept_rtadv=0
#net.inet6.ip6.auto_linklocal=0

# Increases default TTL, sometimes useful
# Default is 64
net.inet.ip.ttl=128

# Lessen max segment life to conserve resources
# ACK waiting time in miliseconds
# (default: 30000. RFC from 1979 recommends 120000)
net.inet.tcp.msl=5000

# Max bumber of timewait sockets
net.inet.tcp.maxtcptw=200000
# Don't use tw on local connections
# As of 15 Apr 2009. Igor Sysoev says that nolocaltimewait has some buggy realization.
# So disable it or now till get fixed
#net.inet.tcp.nolocaltimewait=1

# FIN_WAIT_2 state fast recycle
net.inet.tcp.fast_finwait2_recycle=1

# Time before tcp keepalive probe is sent
# default is 2 hours (7200000)
#net.inet.tcp.keepidle=60000

# Should be increased until net.inet.ip.intr_queue_drops is zero
net.inet.ip.intr_queue_maxlen=4096

# Protocol decoding in interrupt thread.
# If you have NIC that automatically sets flow_id then it's better to not use direct_force, and use advantages of multithreaded netisr(9)
# If you have Yandex drives you better off with net.isr.direct_force=1 and net.inet.tcp.read_locking=0 otherwise you may run into some TCP related problems
# If you have old NIC that don't set flow_ids you may need to patch ip_input to manually set FLOW_ID via nh_m2flow
# FreeBSD 8+
#net.isr.direct=1
#net.isr.direct_force=1
# In FreeBSD 9+ it was renamed to
#net.isr.dispatch=direct

# This is for routers only
#net.inet.ip.forwarding=1
#net.inet.ip.fastforwarding=1

# This speed ups dummynet when channel isn't saturated
net.inet.ip.dummynet.io_fast=1
# Increase dummynet(4) hash
#net.inet.ip.dummynet.hash_size=2048
#net.inet.ip.dummynet.max_chain_len

# Should be increased when you have A LOT of files on server
# (Increase until vfs.ufs.dirhash_mem becomes lower)
vfs.ufs.dirhash_maxmem=67108864

# Note from commit http://svn.freebsd.org/base/head@211031 :
# For systems with RAID volumes and/or virtualization envirnments, where
# read performance is very important, increasing this sysctl tunable to 32
# or even more will demonstratively yield additional performance benefits.
vfs.read_max=32


# Explicit Congestion Notification (see http://en.wikipedia.org/wiki/Explicit_Congestion_Notification)
net.inet.tcp.ecn.enable=1

# Flowtable - flow caching mechanism
# Useful for routers
#net.inet.flowtable.enable=1
#net.inet.flowtable.nmbflows=65535

# IPFW dynamic rules and timeouts tuning
# Increase dyn_buckets till net.inet.ip.fw.curr_dyn_buckets is lower
net.inet.ip.fw.dyn_buckets=65536
net.inet.ip.fw.dyn_max=65536
net.inet.ip.fw.dyn_ack_lifetime=120
net.inet.ip.fw.dyn_syn_lifetime=10
net.inet.ip.fw.dyn_fin_lifetime=2
net.inet.ip.fw.dyn_short_lifetime=10
# Make packets pass firewall only once when using dummynet
# i.e. packets going thru pipe are passing out from firewall with accept
#net.inet.ip.fw.one_pass=1

# shm_use_phys Wires all shared pages, making them unswappable
# Use this to lessen Virtual Memory Manager's work when using Shared Mem.
# Useful for databases
#kern.ipc.shm_use_phys=1

# ZFS
# Enable prefetch. Useful for sequential load type i.e fileserver.
# FreeBSD sets vfs.zfs.prefetch_disable to 1 on any i386 systems and
# on any amd64 systems with less than 4GB of avaiable memory
# For additional info check this nabble thread http://old.nabble.com/Samba-read ... ing-td27964534.html
#vfs.zfs.prefetch_disable=0

# On highload servers you may notice following message in dmesg:
# "Approaching the limit on PV entries, consider increasing either the
# vm.pmap.shpgperproc or the vm.pmap.pv_entry_max tunable"   
vm.pmap.shpgperproc=2048




loader.conf
# Accept filters for data, http and DNS requests
# Useful when your software uses select() instead of kevent/kqueue or when you under DDoS
# Note: DNS accf available on 8.0+
#accf_data_load="YES"
#accf_http_load="YES"
#accf_dns_load="YES"

# Async IO system calls
aio_load="YES"

# Linux specific devices in /dev
# As for 8.1 it only /dev/full
#lindev_load="YES"

# Adds NCQ support in FreeBSD
# WARNING! all ad[0-9]+ devices will be renamed to ada[0-9]+
# 8.0+ only
#ahci_load="YES"
#siis_load="YES"

# FreeBSD 9+
# New Congestion Control for FreeBSD
# http://caia.swin.edu.au/urp/newtcp/tools/cc_chd-readme-0.1.txt
# http://www.ietf.org/proceedings/78/slides/iccrg-5.pdf
# Initial merge commit message http://www.mail-archive.com/svn-src-all@freebsd.org/msg31410.html
#cc_chd_load="YES"


# Increase kernel memory size to 3G.
#
# Use ONLY if you have KVA_PAGES in kernel configuration, and you have more than 3G RAM
# Otherwise panic will happen on next reboot!
#
# It's required for high buffer sizes: kern.ipc.nmbjumbop, kern.ipc.nmbclusters, etc
# Useful on highload stateful firewalls, proxies or ZFS fileservers
# (FreeBSD 7.2+ amd64 users: Check that current value is lower!)
#vm.kmem_size="3G"

# If you have really busy forking webserver (i.e. apache13) you may run out of processes
#kern.maxproc=10000

# If your server has lots of swap (>4Gb) you should increase following value
# according to http://lists.freebsd.org/piperma ... October/029616.html
# Otherwise you'll be getting errors
# "kernel: swap zone exhausted, increase kern.maxswzone"
#kern.maxswzone="256M"

# Older versions of FreeBSD can't tune maxfiles on the fly
#kern.maxfiles="200000"

# Useful for databases
# Sets maximum data size to 1G
# (FreeBSD 7.2+ amd64 users: Check that current value is lower!)
#kern.maxdsiz="1G"

# Maximum buffer size(vfs.maxbufspace)
# You can check current one via vfs.bufspace
# Should be lowered/upped depending on server's load-type
# Usually decreased to preserve kmem
# (default is 10% of mem)
#kern.maxbcache="512M"

# Sendfile buffers
# For i386 only
#kern.ipc.nsfbufs=10240

# FreeBSD 9+
# HPET "legacy route" support. It should allow HPET to work per-CPU
# See http://www.mail-archive.com/svn- ... d.org/msg03603.html
#hint.atrtc.0.clock=0
#hint.attimer.0.clock=0
#hint.hpet.0.legacy_route=1

# syncache Hash table tuning
net.inet.tcp.syncache.hashsize=32768
net.inet.tcp.syncache.bucketlimit=32
net.inet.tcp.syncache.cachelimit=1048576

# Increased hostcache
# Later host cache can be viewed via net.inet.tcp.hostcache.list hidden sysctl
# Very useful for it's RTT RTTVAR
# Must be power of two
net.inet.tcp.hostcache.hashsize=65536
# hashsize * bucketlimit (which is 30 by default)
# It allocates 255Mb (1966080*136) of RAM
net.inet.tcp.hostcache.cachelimit=1966080

# TCP control-block Hash table tuning
# see http://serverfault.com/questions ... hashsize-in-freebsd
net.inet.tcp.tcbhashsize=524288

# Disable ipfw deny all
# Should be uncommented when there is a chance that
# kernel and ipfw binary may be out-of sync on next reboot
#net.inet.ip.fw.default_to_accept=1

#
# SIFTR (Statistical Information For TCP Research) is a kernel module that
# logs a range of statistics on active TCP connections to a log file.
# See prerelease notes http://groups.google.com/group/m ... ad/b4c18be6cdce76e4
# and man 4 sitfr
#siftr_load="YES"

# Enable superpages, for 7.2+ only
# See: http://lists.freebsd.org/piperma ... ovember/030094.html
vm.pmap.pg_ps_enabled=1

# Usefull if you are using Intel-Gigabit NIC
#hw.em.rxd=4096
#hw.em.txd=4096
#hw.em.rx_process_limit="-1"
# Also if you have ALOT interrupts on NIC - play with following parameters
# NOTE: You should set them for every NIC
#dev.em.0.rx_int_delay: 250
#dev.em.0.tx_int_delay: 250
#dev.em.0.rx_abs_int_delay: 250
#dev.em.0.tx_abs_int_delay: 250
# There is also multithreaded version of em/igb drivers that can be found here:
# http://people.yandex-team.ru/~wawa/
#
# for additional em monitoring and statistics use
# sysctl dev.em.0.stats=1 ; dmesg
# sysctl dev.em.0.debug=1 ; dmesg
# Also after r209242 (-CURRENT) there is a separate sysctl for each stat variable;   
# Same tunings for igb
#hw.igb.rxd=4096
#hw.igb.txd=4096
#hw.igb.rx_process_limit=100

# Some useful netisr tunables. See sysctl net.isr
#net.isr.maxthreads=4
#net.isr.defaultqlimit=10240
#net.isr.maxqlimit=10240
# Bind netisr threads to CPUs
#net.isr.bindthreads=1

#
# FreeBSD 9.x+
# Increase interface send queue length
# See commit message http://svn.freebsd.org/viewvc/ba ... amp;revision=207554
#net.link.ifqmaxlen=1024

# Nicer boot logo =)
loader_logo="beastie"


Most of FreeBSD's limits can be monitored by

# vmstat -z

and

# limits  

Variety of network counters can be monitored via

# netstat -s

In FreeBSD-8+ netstat's -Q option appeared, try following command to display netisr stats

# netstat -Q

For solving non-trivial TCP problems one can use net.inet.tcp.log_debug, it produces dmesg output similar to:



最后一句非常关键:

# man 7 tuning



原文:http://serverfault.com/questions ... -loader-conf-kernel
作者: Hongqiyaodao    时间: 2012-10-30 07:45
提示: 作者被禁止或删除 内容自动屏蔽
作者: action08    时间: 2012-10-30 09:35
回复 60# lsstarboy


    我没有做过具体的优化测试,但看到的很多优化经验都表示,

多进程数目一般接近等于cpu核心数或者为核心数的整数倍
作者: action08    时间: 2012-10-30 09:37
恭喜,你的测试水平达到业界主流水平,
作者: lsstarboy    时间: 2012-10-30 13:55
回复 69# action08


    嗯,应该差不多。
 网上的教程大多数都很大,我说的CPU数*2已经非常少了,最高还有上千的,我都怀疑它能不能跑动。
作者: action08    时间: 2012-10-30 20:17
本帖最后由 action08 于 2012-10-31 15:40 编辑

回复 27# fender0107401


    我这边同样的硬件是FreeBSD最快,然后是Gentoo,最后是Debian。


可以分享一下同样硬件的情况下,性能差异之几许??

谢谢斑竹的宝贵经验,{:3_200:}
作者: congli    时间: 2012-10-31 00:14
挺热闹啊! 优化似乎离自己很远但又很近, 无事基本不去折腾.
作者: meego2012    时间: 2012-10-31 09:18
action08 发表于 2012-10-29 17:50
回复 65# mirnshi


弯路也不少,学习了很多
作者: 归隐乡村    时间: 2012-10-31 16:45
为什么?会造成系统不稳定吗?回复 2# fender0107401


   
作者: fender0107401    时间: 2012-10-31 16:46
回复 75# 归隐乡村

是的。


   
作者: Hongqiyaodao    时间: 2012-10-31 17:48
提示: 作者被禁止或删除 内容自动屏蔽
作者: frogoscar    时间: 2012-10-31 18:27
支持下先~~~~~~~~~
作者: fallening_cu    时间: 2012-10-31 20:37
我这边机器上内存有 48G
而某个运行的程序瓶颈是硬盘上读写数据,于是把内存分了一块出来作为 tmpfs 挂载上,将程序的输入和输出都放到 tmpfs 上去,速度马上上来了。

作者: wait_rabbit    时间: 2012-11-01 00:28
我就想知道,在freebsd下玩儿虚拟机方便吗?
作者: mirnshi    时间: 2012-11-01 18:05
fallening_cu 发表于 2012-10-31 20:37
我这边机器上内存有 48G
而某个运行的程序瓶颈是硬盘上读写数据,于是把内存分了一块出来作为 tmpfs 挂载上 ...


tmpfs似乎不建议用于生产。但mfs还是可以的。
作者: mirnshi    时间: 2012-11-01 18:06
归隐乡村 发表于 2012-10-31 16:45
为什么?会造成系统不稳定吗?回复 2# fender0107401


修改参数前,应该明确知道其作用,切忌照本宣科。
作者: 瀚海书香    时间: 2012-11-02 08:16
回复 1# iceblood
要是Fedora或者Suse优化,还有点东西;要是FreeBSD吗。。。,没用过

   
作者: pitonas    时间: 2012-11-02 10:25
优化!!很费精力很费神!!
作者: gsq8038    时间: 2012-11-02 11:11
不错帮你顶
作者: 归隐乡村    时间: 2012-11-02 15:01
水平还没那么高哦,谢谢亲提醒。回复 82# mirnshi


   
作者: zhaopingzi    时间: 2012-11-02 15:34
优化?怎么优化,内核代码是别人写的。你改个参数就可以了吗?

作者: lsstarboy    时间: 2012-11-02 17:21
回复 87# zhaopingzi


    车子是别人造的,却是自己开的,开车的水平也各不相同。
作者: zhaopingzi    时间: 2012-11-02 17:44
上次谁列举的开源7宗罪来这,这东西出问题找不到原厂支持
作者: mirnshi    时间: 2012-11-03 09:50
zhaopingzi 发表于 2012-11-02 15:34
优化?怎么优化,内核代码是别人写的。你改个参数就可以了吗?


怎么不可以呢?电视买回来,还有优化调整一下呢。音响听不同的音乐,还有调整一下高低音呢
作者: mirnshi    时间: 2012-11-03 09:52
zhaopingzi 发表于 2012-11-02 17:44
上次谁列举的开源7宗罪来这,这东西出问题找不到原厂支持


用开源,需要独立性。想获得原厂支持,买商业软件。N多的国企/政府买商业软件的目的之一,就是出了问题,与自己无关,一切都是厂商的事情。
作者: ruochen    时间: 2012-11-03 22:47
看了这个活动,可能下面说的有点跑题,当然很多东西可能是和Linux对比一下,以下有的话不专指FreeBSD
作为使用过BSD系列和Linux的使用者(注意是“使用者”,不是玩OS),目前也在维护大规模的Linux主机
说到具体的应用是MySQL,目前在WebGame类公司做MySQL DBA,算是SA出家的DBA,可能在这里说这个话题身份不是很合适
但是看了一些大家的讨论,还是觉得有些话不说不快的感觉
(其实最近几年接触的主机基本都跑在CentOS系统,下面有些是根据前几年的印象说的,错误之处请海涵)

一、FreeBSD的优化您是重新编译内核还是使用sysctl.conf或者loader.conf?
我现在基本很少去编译Kernel,不管是Linux还是BSD系列,大规模主机的应用,统一维护完全相同版本的OS和Kernel
不同版本的后期维护的压力确实不小,除非国内像TB BD TX等公司有专门的团队来维护这个,否者会遇到很多痛苦
一般都是同一类生产环境应用同一版本的OS,使用自带相同的Kernel或者升级到相同版本的Kernel,或者是升级到相同版本的OS
一般的应用我都会选用后者配置文件的方式来优化

二、FreeBSD在安装完毕后你都会做那些初始化?
如上面说的两个配置文件,Linux一般是sysctl.conf和rc.local和其他的配置文件
一般优化的内容无非是信号量限制、文件句柄限制、内存参数、网络参数。。。等等
生产环境一般都是标准化的sysctl.conf和loader.conf,放在中心ftp服务器上,标准化安装OS后,直接覆盖掉本地的相同文件
我们有一个check_install_OS-info.sh的系统初始化脚本,(OS-info如有CentOS54),一般会包含替换相关的配置文件、安装应用软件和调整防火墙等
如sysctl.conf、loader.conf、rc.local、forward(防火墙)。。。等等,甚至是包含sshd_conf等一些应用软件的配置优化

三、列举一些针对某项功能的优化参数。
忽略

四、基于第三个问题的服务器硬件配置是什么?(CPU、内存)
选择什么硬件和应用是息息相关的,应用有CPU bond、IO bond、mem等类型的
如视频应用、数据库应用、cdn应用、cache应用、海量文件应用。。。不同的应用优化的思路策略和方法都有一些细微的差异
现在生产大家选择intel的PC服务器比较多,一般的主机也都有5504/5620*2这样的CPU,16G mem了

补充:
我们用Linux类主要是大部分生产app应用,BSD类主要是网络或者安全方面的应用
至于有人说软件使用差异和性能差异,我觉得没必要深究,至于说将工作或者优化做到极致,那是另一个话题
软件包管理和安装,Linux有yum和rpm等,BSD有port和pkg-add等
使用什么系统和应用类型及你对这个OS的有把握程度都相关的

不管是OS还是MySQL/Oracle等这类的应用程序,他们也都是在互相学习和互相演进的
作者: ruochen    时间: 2012-11-03 22:51
优化,总感觉是有一个基本优化+后续优化的策略
主要还是后续优化吧,根据应用的特点和监控数据,再逐步调整优化的过程

作者: wjgapg    时间: 2012-11-04 09:02
本帖最后由 wjgapg 于 2012-11-04 09:08 编辑

回复 6# meego2012

对于postgres8以上和php5的版本来说必须得编译内核,freebsd8.1他不自带内存方面的模块


在我们公司一般不会把freebsd作为web服务器,一般用他来进行防火墙设置进行包过滤的,然后用red系的linux如scientfic等进行内核裁减后放web

    这个验证码看着真麻烦
作者: meego2012    时间: 2012-11-04 15:38
ruochen 发表于 2012-11-03 22:47
看了这个活动,可能下面说的有点跑题,当然很多东西可能是和Linux对比一下,以下有的话不专指FreeBSD
作为 ...


学习了,写的真详细
作者: SinTeryx    时间: 2012-11-04 19:21
ruochen 发表于 2012-11-03 22:51
优化,总感觉是有一个基本优化+后续优化的策略
主要还是后续优化吧,根据应用的特点和监控数据,再逐步调整 ...


很赞同,先稳定运行,且可靠管理起来,以后才是优化
作者: lemoncandy    时间: 2012-11-04 20:07
瀚海书香 发表于 2012-11-02 08:16
回复 1# iceblood
要是Fedora或者Suse优化,还有点东西;要是FreeBSD吗。。。,没用过


毕竟现在Linux是主流
作者: shanghan    时间: 2012-11-05 00:52
bsd的那个内核编译之前,搞清楚每一条含义先,确定目前业务可以用,考虑周全重要。

作者: 刺客阿地    时间: 2012-11-05 09:18
进来支持下,freebsd暂时还没怎么用过,万变不离其宗吧,应该跟linux差别不大!
作者: lemoncandy    时间: 2012-11-05 11:39
zhaopingzi 发表于 2012-11-02 17:44
上次谁列举的开源7宗罪来这,这东西出问题找不到原厂支持


FreeBSD后面也是有企业的,但是大部分是用户,没有原厂的势力






欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2