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

  • 相关阅读:
    springcolud 的学习(一),架构的发展史
    shiro框架的学习
    Mybatis分页插件PageHelper简单使用
    对于解决VS2015启动界面卡在白屏的处理方法
    C# 运行流程
    转:什么是DIP、IoC、DI
    IQueryable,IEnumerable,IList区别
    easyUi——datetimebox绑定数据失效
    前后端参数传递的学习笔记
    java 多线程学习总结
  • 原文地址:https://www.cnblogs.com/busor/p/3619279.html
Copyright © 2011-2022 走看看