Windows 7 to do 7-layer soft load experience sharing

  
This article will introduce you to do some analysis of the 7-layer soft load under Windows, you are interested in the load of this piece, you can come and see. In fact, the so-called four layers are load balancing based on IP+ ports; the seventh layer is load balancing based on application layer information such as URLs; you have a shallow impression on the 7th layer, then everyone has the experience of doing 7 layers of soft load can be discussed Share it, of course, it is best under the windows platform.
Performance Analysis
1. Connection management and protocol resolution for external network. Using http.sys(HttpApi.dll, HttpListener) built-in mechanism, http.sys performs HTTP connection management and protocol analysis at the kernel level. Performance should be Guarantee.
2, the internal network RealServer connection management and consolidation package using HttpWebRequest built-in mechanism, but the following problems
a) connection management: the default proxy to RealServer to send a request will establish a new connection, will receive a response The connection is removed, which means that a large number of connections will be established between the Proxy and the RealServer, but due to the limitation of the port (65535), the outbound connection cannot be too much. To solve this problem, you can try to enable KeepAlive to solve RealServer.
b) Package: After the HttpListener receives the package, it will automatically resolve to the object, but also repackage the package into the HttpWebRequest format and send it to RealServer, which includes copying Uri, HttpHeader, Cookies, Body, etc. The amount of data is quite large, and it is sure to lose performance in memory. This issue should be unavoidable.
3, if it is a regular web application (resource access class), Request is small, Response is very large, RealServer will also go through the Proxy when returning Response, but also to copy the memory, this also affects performance. Then Layer 7 can't do the DirectRoute mechanism of LVS (you need to modify the mac address of the network packet), and the state transition of IP tunnel and TCP needs to modify the TCP/IP protocol stack of the operating system. Given the cost, the issue is not circumvented.
4, Http protocol stipulates that the request and response must appear in pairs. By default, after a request is sent out on a connection, the next request can be sent after receiving the response corresponding to the request. Although Http1.1 has a pipeline function, Requests can be sent in batches without having to wait for a response, but there are also many restrictions, such as stipulating that POST should not use a pipeline, the first time a connection is sent, the pipeline mechanism cannot be used, and the number of requests per batch is not Well, after sending the request in bulk, if the connection is broken, there will be multiple requests failing, and so on. The HTTP protocol does not match the request and response by CallID and Cseq like the SIP protocol, so that the request and response can be sent and received asynchronously, so when the Http protocol stack is implemented, the response is synchronously waited, and then the next batch of requests can be sent on the connection. This will inevitably affect performance.
5, HttpListener asynchronous receiving request and send response is the ordinary APM mode (BeginXXX, EndXXX format), this asynchronous mode will generate and destroy a large number of IAsyncRequest objects when frequently called, thereby increasing the pressure of the GC, and IAsyncRequest The object does not yet provide a custom pooled interface. If HttpListener provides a new event-based asynchronous mode (XXXAsync (eventargs) mode, refer to the Socket.ReceiveAsync method) will solve this problem.
6, in addition, because HttpLisenter is a wrapper class of .net, it is executed in user mode, and HTTP.SYS is running in kernel mode. When accepting a request, returning a response will switch between user mode and kernel mode twice. Reduce performance, if you can directly perform 7-layer forwarding in the kernel state, LVS (KTCPVS) can achieve kernel-based content-based 7-layer forwarding under Linux. You may need to do TDI or NDIS development under Windows. Some of the information is too complicated, so I don't think about it first.
Reliability Analysis
In order to provide disaster tolerance and improve reliability, consider the following schemes.
1. 7 layers of soft load must have 4 layers of load devices, 7 layers of soft load, and shared hashing strategy. The 4th layer device performs random load according to Session, so that all 7 layers of soft load machines can correctly handle any request, and after a 7 layer soft load is down, the remaining 7 layers of soft load can continue to work, due to 4 The layer load has a keepalive function, which can detect which 7-layer soft load is down, and does not forward requests to it.
2. The 7-layer soft load is double-click hot standby, and the 7-layer soft load is directly connected to the external network. Under normal circumstances, the primary server processes the request. If the primary server is down, the backup server discovers and obtains the primary server through ARP spoofing. The original IP is used to attract the request to the backup server (the hardware may support the primary and backup machines to share a MAC address if supported), and the short-time request may fail when the active/standby switchover occurs.
Comprehensive consideration, the second program has some cottages and no insurance, giving priority to the first option.
Copyright © Windows knowledge All Rights Reserved