zoukankan      html  css  js  c++  java
  • 支持上百万并发连接

    在真实的 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 新思路 

  • 相关阅读:
    怎么样实现打印网页中指定的表格,而不是全页
    加深C# 中字符串前加@符号理解以及使用~~
    CommandArgument 绑定多个参数
    gridview等控件CommandField英文的解决.
    正式发布基于VS2008的AJAX模板包
    给datalist加自动编号
    .net生成文字图片
    重新注册.net
    Android JNI入门第二篇——Java参数类型与本地参数类型对照
    Android推送方式比较
  • 原文地址:https://www.cnblogs.com/busor/p/3619279.html
Copyright © 2011-2022 走看看