Home >Operation and Maintenance >Nginx >The difference between nginx and haproxy

The difference between nginx and haproxy

(*-*)浩
(*-*)浩Original
2019-06-04 17:07:596261browse

For soft loads, we all know that the mainstream solutions include LVS, Haproxy, and Nginx! So how do we choose between Haproxy and Nginx? Before answering this question, let me talk about their characteristics based on my personal experience!

The difference between nginx and haproxy

##Haproxy Features

Supports TCP and HTTP protocols, working on network layer 4 and layer 7

Support Session sharing, Cookies guidance

Support URL health detection

Support 8 load balancing strategies

Support heartbeat detection

Nginx Features

Support Http protocol, working on network layer 7

Support port health detection

Support powerful regular matching rules

Support WebSocket Protocol

Support Http Cache

Description:

For Http protocol, Haproxy processing efficiency is higher than Nginx. Therefore, when there are no special requirements or general scenarios, it is recommended to use Haproxy for HTTP protocol load! But if it is the Web, it is recommended to use Nginx! In short, everyone can make a reasonable choice based on the characteristics of their respective usage scenarios!

Last time someone asked me: Can the number of connections of Nginx or Haproxy break through the "curse" of "65535"? In fact, everyone has such questions because they don’t understand the working principle of Nginx or Haproxy!

The following takes the Linux server as an example to explain the theoretical maximum number of connections between the two:

Theoretical maximum number of connections for Nginx on Linux

Correct Reverse proxy: Maximum number of connections = work_processes * worker_connections

Reverse proxy: Maximum number of connections = work_processes * worker_connections / 4
Note: worker_connections refers to the maximum number of connections that a single process can handle. Assume that your server has 8 cores. worker_connections =
65535 (can be customized, but the maximum number of file descriptors cannot be exceeded, because 1 connection is equivalent to using 1 file descriptor)

Maximum connections in the above two cases The numbers (theoretical values) are: 8 * 65535 and 8 * 65535 /4

Theoretical maximum number of connections for Haproxy on Linux

Maximum number of connections = maxconn(global | defaults | listen )

For more Nginx related technical articles, please visit the

Nginx usage tutorial column to learn!

The above is the detailed content of The difference between nginx and haproxy. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn