Linux kernel parameter: Difference between revisions

From HPCWIKI
Jump to navigation Jump to search
No edit summary
Line 4: Line 4:
The default value for the <code>net.core.somaxconn</code> [[Linux]] kernel parameter is typically 128 and the maximum value is around 65535 on most systems.
The default value for the <code>net.core.somaxconn</code> [[Linux]] kernel parameter is typically 128 and the maximum value is around 65535 on most systems.


=== For Nginx ===
=== Nginx consideration ===
It is important to set the <code>net.core.somaxconn</code> parameter to a value that is ''larger'' than the <code>backlog</code> value of NGINX, as the <code>backlog</code> value is used to determine the maximum number of connections that can be queued for a listening socket of NGINX only. If the <code>net.core.somaxconn</code> value is smaller than the backlog value, NGINX will not be able to queue all the incoming connections, resulting in connection errors.<ref>https://www.getpagespeed.com/server-setup/nginx/maximizing-nginx-performance-a-comprehensive-guide-to-tuning-the-backlog-and-net-core-somaxconn-parameters</ref>
It is important to set the <code>net.core.somaxconn</code> parameter to a value that is ''larger'' than the <code>backlog</code> value of NGINX, as the <code>backlog</code> value is used to determine the maximum number of connections that can be queued for a listening socket of NGINX only. If the <code>net.core.somaxconn</code> value is smaller than the backlog value, NGINX will not be able to queue all the incoming connections, resulting in connection errors.<ref>https://www.getpagespeed.com/server-setup/nginx/maximizing-nginx-performance-a-comprehensive-guide-to-tuning-the-backlog-and-net-core-somaxconn-parameters</ref>


 
=== Calculate optimal net.core.somaxconn value ===
Calculate optimal value
 
For example, if your average queue length from [[vmstat]] is 1000 and you have 2 [[Vmstat|CPU]] cores,  
For example, if your average queue length from [[vmstat]] is 1000 and you have 2 [[Vmstat|CPU]] cores,  



Revision as of 12:54, 3 January 2024

net.core.somaxconn

somaxconn is used to set the maximum number of connections that can be queued for a socket. This parameter is used to prevent a flood of connection requests from overwhelming the system. The maximum value for the net.core.somaxconn parameter depends on the system and kernel version.

The default value for the net.core.somaxconn Linux kernel parameter is typically 128 and the maximum value is around 65535 on most systems.

Nginx consideration

It is important to set the net.core.somaxconn parameter to a value that is larger than the backlog value of NGINX, as the backlog value is used to determine the maximum number of connections that can be queued for a listening socket of NGINX only. If the net.core.somaxconn value is smaller than the backlog value, NGINX will not be able to queue all the incoming connections, resulting in connection errors.[1]

Calculate optimal net.core.somaxconn value

For example, if your average queue length from vmstat is 1000 and you have 2 CPU cores,

the optimal value for net.core.somaxconn would be 1000 * 4 / 2 = 2000.

The formula for net.core.somaxconn 

optimal value = CPU cores * queue length / 4

References