• 支持上百万并发连接


    在真实的 Linux 系统中,可以通过调整内核参数来支持上百万并发连接,具体做法见:

    http://urbanairship.com/blog/2010/09/29/linux-kernel-tuning-for-c500k/

    http://www.metabrew.com/article/a-million-user-comet-application-with-mochiweb-part-3 

    Kernel Options

    Several parameters exist to allow for tuning and tweaking of socket-related parameters. In/etc/sysctl.conf there are a few options we’ve modified.

    First is fs.file-max, the maximum file descriptor limit. The default is quite low so this should be adjusted. Be careful if you’re not ready to go super high.

    Second, we have the socket buffer parameters net.ipv4.tcp_rmem and net.ipv4.tcp_wmem. These are the buffers for reads and writes respectively. Each requires three integer inputs: min, default, and max. These each correspond to the number of bytes that may be buffered for a socket. Set these low with a tolerant max to reduce the amount of ram used for each socket.


    The relevant portions of our config look like this:

    fs.file-max = 999999

    net.ipv4.tcp_rmem = 4096 4096 16777216

    net.ipv4.tcp_wmem = 4096 4096 16777216

    net.ipv4.ip_local_port_range = 1024 65535

    kernel.threads-max = 640000


    Meaning that the kernel allows for 999,999 open file descriptors and each socket buffer has a minimum and default 4096-byte buffer, with a sensible max of 16MB.


    We also modified /etc/security/limits.conf to allow for 999,999 open file descriptors for all users.

    #<domain>      <type>  <item>         <value>

    *                        -            nofile         999999

    yucheng            -            nproc         30000

    让用户yucheng的一个进程可以启动3万个线程


    You may want to look at the manpage for more information.


    Testing

    When testing, we were able to get about 64,000 connections per client by increasing the number of ephemeral ports allowed on both the client and the server.


    echo "1024 65535" > /proc/sys/net/ipv4/ip_local_port_range

    This effectively allows every ephemeral port above 1024 be used instead of the default, which is a much lower (and typically more sane) default.

    陈硕 C1000K 新思路 

  • 相关阅读:
    UEditor用法
    String,StringBuffer与StringBuilder差异??
    TsFltMgr.sys其原因是,该系统蓝屏QQ计算机管理器!
    Linux编程实现守护进程
    开机黑屏 只显示鼠标 电脑黑屏 有只老鼠 举 [我们已经成功地解决了]
    页面背景图像的代码
    动态规划01背包问题
    关键部分CCriticalSection使用
    编程:获取股票实时行情数据大全
    iphone开发教程下载
  • 原文地址:https://www.cnblogs.com/busor/p/3619279.html
Copyright © 2020-2023  润新知