Alibaba Design Protocol-Server

  1. [Recommended] It is recommended that the server with high concurrency reduce the time_wait timeout time of the TCP protocol.
    Note: The operating system will only close the connection in the time_wait state after 240 seconds by default. Under high concurrent access, the server side
    may not be able to establish a new connection because there are too many connections in the time_wait. Waiting for the value.
    Positive example: on the Linux server, please change the default value (seconds) by changing the /etc/sysctl.conf file:
    net.ipv4.tcp_fin_timeout = 30

Without writing, the default will be 240.


  1. [Recommended] Increase the maximum number of file handles supported by the server (File Descriptor, abbreviated as fd).
    Note: The design of mainstream operating systems is to manage TCP / UDP connections in the same way as files, that is, one connection corresponds to one
    fd. The mainstream Linux server supports the maximum number of FDs by default as 1024. When the number of concurrent connections is large, it is easy to cause an
    "open too many files" error due to insufficient FDs, causing new connections to be established. It is recommended to increase the maximum number of handles supported by the Linux server by several
    times (related to the amount of memory in the server).
    Query with command under Linux: found to be open files (-n) 1024
root@ubuntu2015251:~# 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) 63694
max locked memory       (kbytes, -l) 64
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) 63694
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
root@ubuntu2015251:~# 

How to increase the size?
By default, the maximum number of Linux file handles is 1024. When your server reaches the limit in large concurrency, it will report "too many open files".

So how do you modify the maximum number of file handles in Linux? it's actually really easy:

1、ulimit -n 2048

This command can modify the maximum number of Linux file handles. After modification, use ulimit -a to view the status of the modification, such as:

However, this method is only valid for the current process. Reopen a shell or start a process, you will find that the parameter is still ulimit -n xx before modifying the number. So is there a once and for all method?

Of course there is! That is to modify the system parameters.

2. Modify the linux system parameters. vi /etc/security/limits.conf add

* soft nofile 65536

* hard nofile 65536

Save it after modification, log out the current user, log in again, execute ulimit -a, ok, the parameter takes effect:


  1. [Recommended] Set the -XX: + HeapDumpOnOutOfMemoryError parameter for the JVM environment parameters to allow the JVM
    to output dump information when it encounters an OOM scene.
    Note: The occurrence of OOM is probable, and even one case occurs only a few months apart. The information in the heap when an error occurs is very helpful to solve the problem.

  1. [Recommended] In the online production environment, set the memory size of the XVM and Xmx of the JVM to the same size to avoid
    the pressure caused by adjusting the heap size after the GC .

Published 331 original articles · 51 praises · 440,000 visits +

Guess you like

Origin blog.csdn.net/y41992910/article/details/95314088