does load balancer have all its child servers' sockets open
Let's say I have the following setup:
client (browser)-> load balancer (nginx) -> 10 nodejs servers
I'm using websocket ( socket.io
) for bidirectional communication between client and server.
My question is: when a client sends a message via socket, does load balancer simply redirect the socket request to another server like a normal http request, or something more complicated is going on, like making the socket remain open on the load balancer machine for the whole duration of the websocket connection between client and server.
Because if the above is true, it means that load balancer machine has the SUM of ALL its child servers' TCP connection opened, which means load balancer has to be quite a huge machine on it own, and it's not "entirely" distributing all the load.. and eventually I have to worry about "running out of sockets" on the load balancer machine?
Can anyone clarify this whole concept for me? Thanks!
For websockets, yes, the load balancer will almost certainly maintain a TCP connection in from the client and out to the server for every connection. The load balancer, however, has much less work to do than the server machines actually handling the clients -- it doesn't have to "think" about the protocol or generate or interpret any payload, it just has to copy data from one pipe to another and tear down connections when they close.
With an event-driven model and potentially using the Linux kernel's splice(2) system call, the "copied" data can be shuffled between the connections all in kernel space, for very efficient operation.
A well-designed load balancer is as likely to run up against the IPv4 limit of ~64K address/port pairs for a given IP address as any other resource, like CPU or memory.
Even with normal web traffic, where the balancer is understanding and making routing decisions based on request and response bodies, the app servers still typically have far more work to do than the balancer.
Anecdotally, some of the smallest machines in my infrastructure are the load balancers... and they still tend to have the smallest workloads as evidenced by memory, CPU, and disk access.
链接地址: http://www.djcxy.com/p/44820.html上一篇: SignlaR不支持负载平衡
下一篇: 负载均衡器是否打开了所有子服务器的套接字