`

压力测试Exception:Too many open files.

阅读更多

当进行大并发的压力测试时,经常会出现如下Exception:Too many open files.
查阅资料,google baidu.
首先感谢demo的评论,使我对这个问题有了新的认识。
经过再次查找,发现这个问题的出现原因是system对打开files数量的限制问题。
用 ulimit -a 命令可以查看当前所有资源限制
fingki@ubuntu:~$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 15863
max locked memory       (kbytes, -l) 32
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 15863
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
fingki@ubuntu:~$
可以看出,对open files的限制数是1024,我们可以通过修改这个值来增加可以打开的文件数。
最简单的修改方式就是用ulimit -n 命令,
比如我打算将其改为2048,用 ulimit -n 2048.
当你把open files的值增大到一定程度,你的Too many open files就不会再出现了。

而对于tcp_fin_timeout,是合tcp连接相关的,当你有大量tcp连接时,或许有些性能改善;
tcp_fin_timeout,默认情况下,win为4 min,linux为60 sec.
可以把其相应设置短一些,以增加系统性能。

in Windows

  1. Run regedit to start the Registry Editor
  2. Locate the following key: HKEY_LOCAL_MACHINE"System"CurrentControlSet"Services"tcpip"Parameters
  3. Add a new value named TcpTimedWaitDelay asa decimal and set the desired timeout in seconds (30-300)
  4. Reboot

in Linux

  1. Update the configuration value by running (30 seconds used in the example)
    echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout
  2. Restart the networking component, for example by running
    /etc/init.d/networking restart  or  service network restart

在linux下,经常会有权限问题使设置不能成功,尽管你用了sudo。
解决办法就是先 su root,在root用户下来执行操作,这样就ok了。
再有就是可能忘记root密码了,那就 sudo passwd root,来设置一个新密码。

根据进一步的研究发现:服务器默认情况下对进程的处理也是有限制的,要想server处理更多用户进程就需要调整相应参数。
这里面有两个文件要特别注意,
一个是    /etc/security/limits.conf
另一个    /etc/sysctl.conf

当我们用ulimit -a命令可以查看 open files(默认为1024)和max user processes(默认也为1024),
所以默认情况下这个server只允许同时打开1024个文件,处理1024个用户进程,
若要 临时 改变这两个参数值,可以使用 ulimit -n 10240 ,ulimit -u 10240,
若要 长久 改变这两个参数值,就要修改/ect/security/limits.conf,在文件中加上两行:
* - nofile 102400
* - nproc 102400

而对于大量使用tcp连接的应用来说,也需要对/etc/sysctl.conf中的参数进行相应优化:
net/ipv4/ip_always_defrag = 1
net.ipv4.ip_local_port_range = 1024    65000
net.ipv4.tcp_max_syn_backlog = 102400
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
上面是我根据我的需求的一些参数调整,你可以根据你的需求来调整相应参数值。
然后执行 sysctl -p命令可立即生效。sysctl -a可查看参数值。

参考 :http://www.iteye.com/topic/65175

分享到:
评论

相关推荐

    EurekaLog_7.5.0.0_Enterprise

    7)....Added: Streaming unpacked debug info into temporal files instead of memory - this greatly reduces run-time application memory usage at cost of slightly slower exception processing. This also ...

    VclZip pro v3.10.1

    - Improved memory performance when working with archives containing extremely high number of compressed files. ==================== Version 3.06 Build 2 Made Delphi 2005 compatible Other assorted ...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    Of course, .cc files typically do require the definitions of the classes they use, and usually have to include several header files. Note: If you use a symbol Foo in your source file, you should ...

    Java邮件开发Fundamentals of the JavaMail API

    downloading and unbundling pop31_1_1.zip, add pop3.jar to your CLASSPATH, too. After installing JavaMail 1.1.3, install the JavaBeans Activation Framework. Installing the JavaBeans Activation ...

    Sakemail

    to multiple recipients, i.e.: ‘a@doma.com, b@domb.com,c@domc.com‘ This change is done for better compatibility with other emails clients.- Better formatting of the field Date of TSakMsg. Some ...

    delphi2010皮肤控件-VCLSkinv5.30FS

    VclSkin automatically skin kinds of windows in application, include Delphi forms,MDIform and common Windows dialogs (MsgBox,Open/Save,Font,Print), even the Exception MsgBox. Vclskin not only support ...

    Borland Delphi 2005 Architect Update 3

    t repaint when Enabled changed.5.00 of 5 Closed2625 Impossible to open a .TLB into the TLB Editor if missing uses reference3.50 of 5 Closed2608 Compiler crashes, dcc70.dll Read of address 000000004.00...

    CE中文版-启点CE过NP中文.exe

    Disassembler: Several disassembler instructions had a comma too many or too few ,fixed those Disassembler: Fixed the description for ret # Disassembler/Debug: Fixed the address that is being edited ...

    Universal-USB-Installer

    安装linux工具源码 (UUI) Universal USB ...This Open Source tool falls under the GNU General Public License Version 2 Source Code is made available at time of download, from the official UUI page: ...

    曲线拟合工具CurveExpert 1.0

    + the common dialogs (file open/save, print) did not accept keystokes until after they were clicked with the mouse, which makes it terribly hard for non-mouse users. Fixed. + If the current path ...

    微软内部资料-SQL性能优化2

    Contents Module Overview 1 Lesson 1: Memory 3 Lesson 2: I/O 73 Lesson 3: CPU 111 Module 3: Troubleshooting Server Performance ...Troubleshooting server performance-based support calls requires ...

    Professional.MFC.with.VC6

    Jet Airliner, Don't Take Me Too Far Away Creating Data Sources System Data Sources Programmatically Creating Data Sources Other Interesting Settings Your Environment Data Definition Language ...

    NativeXml-master

    + exception 'Unregistered classtype encountered in nodename' instead of general exception (NativeXmlObjectStorage) ! Local bias (daylightsaving) and time zone designator in date/time conversion ...

    FastReport.v4.15 for.Delphi.BCB.Full.Source企业版含ClientServer中文修正版支持D4-XE5

    - fixed bug with URLs in Open Document Text and Open Document Spreadsheet exports - fixed format string in XLS OLE export - fixed format string in XLS BIFF8 export - fixed output of the check boxes ...

    oracle学习文档 笔记 全面 深刻 详细 通俗易懂 doc word格式 清晰 连接字符串

    oracle学习文档 笔记 全面 深刻 详细 通俗易懂 doc word格式 清晰 第一章 Oracle入门 一、 数据库概述 数据库(Database)是按照数据结构来组织、存储和管理数据的仓库,它产生于距今五十年前。...

Global site tag (gtag.js) - Google Analytics