ASP. NET performance optimization-Load Balancing

Source: Internet
Author: User
Tags varnish

HTTP redirection
The so-called HTTP redirection is to identify the new URL by modifying the Location in the HTTP Response Header, and then return it to the client, so that the client can make a new request based on the URL identified by the Location.
This is the simplest and most lightweight Load Balancing implementation solution. We can use asp.net to implement it like this. For example, in the main site www.yourdomain.com, we encode the following code on the default homepage:

Static string [] servers =
{
"Http: // 192.168.0.77/luminji2/aspx/test3.aspx ",
"Http: // 192.168.0.77/luminji2/aspx/test4.aspx"
};
Protected void Page_Load (object sender, EventArgs e)
{
Response. Redirect (servers [DateTime. Now. Millisecond % 2]);
}
In the above Code, Response. Redirect actually returns the status code 302 for the http header, In order to tell the browser, please go to Location to get the URL and go to the new URL for the request. Of course, we can also use the most primitive method to replace the Redirect method:

Response. Status = "302 Found ";
Response. StatusCode = 302;
Response. AddHeader ("Location", servers [DateTime. Now. Millisecond % 2]);
For HttpWatch monitoring, we request www.yourdomain.com and get:
 

You can clearly see the 302 returned for the first request, and then forward it to the new address to get the status code 200.
The above method is redirection on the client, that is, the browser requests twice, one to the master server, and the second to the server specified in Location.
The HTTP redirection method relies heavily on the processing capability of the main site. Its performance bottleneck also comes from the IIS's response to the request-> asp.net homepage dynamic processing program-> response request with a specific header, yes, it cannot break through its own performance bottleneck. For example, on my broken test machine, I get the following throughput:
 

Fortunately, IIS itself supports redirection (check the http://technet.microsoft.com/zh-cn/library/cc732969 (WS.10). aspx), which further omits the performance loss caused by running ASP. NET code by writing our own code to achieve redirection.
2: reverse proxy load balancing implemented by varnish
Another idea is to use the Server Load balancer function of the reverse proxy server. The varnish mentioned in the previous article supports this function and view the configuration file:

Backend web1 {
. Host = "192.168.0.77 ";
. Port = "8081 ";
}
Backend web2 {
. Host = "192.168.0.77 ";
. Port = "8082 ";
}
Director lb round-robin {
{
. Backend = web1;
}
{
. Backend = web2;
}
}
Sub vcl_recv {
Set req. backend = lb;
Return (pass );
}
In this configuration file, we have deployed two WEB servers. Of course, for the sake of simplicity, I use the two ports of the same server. In the vcl_recv function, varnish defines load balancing.
When varnish is run, we will find that the request is forwarded to the backend server.
3: Other solutions
1. DNS load balancing: Add domain name A records to enable the DNS server to achieve load balancing. The advantage is that there are almost no performance problems. Disadvantage: each WEB server must have an Internet address. Once a server crashes, the DNS modification cannot take effect immediately. You cannot define your own forwarding policy;
2: IP load balancing, LVS-NAT, using iptables, Linux kernel operations, performance compared with the reverse proxy server does not have a qualitative leap; IP load balancing still needs to forward requests to the actual server, at the same time, the response from the actual server needs to be forwarded to the user. Therefore, the performance bottleneck of the server comes from the performance and network bandwidth of the NAT server;
3: Direct routing, LVS-DR, working on the data link layer (Layer 2), requiring all WEB servers to access the Internet; Load balancer is responsible for forwarding requests to the actual server, however, by modifying the MAC address in the data packet, the server can directly return the response from the actual server to the user without using the Server Load balancer, which further improves the efficiency of Server Load balancer;
4: IP tunnel, LVS-TUN, used in different data centers (that is, different WAN network segments) load balancing, the principle of the same LVS-DR;

 


Author: Luminji
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.