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 新思路 

  • 相关阅读:
    [Java算法分析与设计]--链式堆栈的设计
    Spring 单例模式和多例模式
    lucene_09_solrj的使用
    lucene_08_solr导入数据库数据
    lucene_07_solr使用IK分词器
    lucene_06_solr域
    lucene_05_solr配置
    lucene_04_解析语法查询
    lucene_03_索引的增删改查
    lucene_02_IKAnalyre
  • 原文地址:https://www.cnblogs.com/busor/p/3619279.html
Copyright © 2011-2022 走看看