2021. 8. 30. 10:08 WorkHolic
Varnish Load Balance Request (round-robin, weighting)
Varnish Load Balance Request (round-robin, weighting)
Load balance requests (Should know)
Balancing requests is a great way to share workload across the cluster pool and avoid overloading a single server instance, keeping the overall health of the system. There's also the possibility to direct VIP customers to a dedicated cluster pool, guaranteeing them the best user experience.
By using a director group, Varnish will manage and spread the incoming requests to those servers included in it. Having the servers constantly checked, Varnish can take care of the sick servers and maintain everything as if there was no problem at all.
Getting ready
There are six types of director groups to be configured: random, client, hash, round-robin, DNS, and fallback. While the random director is self-explanatory (randomly distributes requests), a DNS director can be used to spread to an entire network of servers. The hash director will always choose a backend based on the hash of the incoming URL and the fallback director can be used in emergency cases when servers behave oddly.
The two most common directors are the round-robin and client directors.
The round-robin can be used to spread requests one by one to the entire cluster of servers no matter what is requested, and the client director can be used to create a sticky-session based on unique information provided by the client, such as an IP address.
In this recipe we will create both the client and round-robin balancers to spread requests across application servers.
How to do it...
- Group the backend servers to load balance requests by using the following code snippet:In the preceding example, we have declared that our director named dr1 is a round-robin director, and inside this director there are four backend servers to be balanced. Backend servers server01 to server04 have already been configured earlier and this declaration is only referring to them.
- director dr1 round-robin { { .backend = server01 } { .backend = server02 } { .backend = server03 } { .backend = server04 } }
- Create a sticky-session pool of servers by using the following code snippet:At first, there's absolutely no difference from the round-robin declaration to the client one, but inside your vcl_recv subroutine, you'll need to specify what identifies a unique client. Varnish will use, as default, the client IP address, but if you have other services in front of your Varnish Cache (such as a firewall), you'll need to rewrite the value of the client.identity variable. In the following example, we'll use the X-Forwarded-For header to get the clients' real IP address.sub vcl_recv { set client.identity = req.http.X-Forwarded-For; }
- A sticky-session pool is necessary to direct clients to specific parts of your website that requires an HTTP session or authorization, such as shopping cart/checkout and login/logout pages, without breaking their session. Those parts of your website may be critical to your business, and having a sticky-session dedicated cluster can prioritize paying customers while the others are still browsing the products and will not interfere with the checkout process performance.
- The X-Forwarded-For header is used to maintain information lost in the proxying process. For more information visit http://tools.ietf.org/html/draft-ietf-appsawg-http-forwarded-10.
- director dr1 client { { .backend = server01 } { .backend = server02 } { .backend = server03 } { .backend = server04 } }
How it works...
By using directors to load balance the requests, we can obtain greater service availability and provide paying customers with an improved user experience.
There's more...
Sometimes it's not possible for all the servers to be identical inside a cluster. Some servers may have more available ram or more processors than others, and to balance requests based on the weakest server in the cluster is not the best way to solve this problem, since the higher end servers would be underused.
Weight-based load balancing improves the balance of the system by taking into account a pre-assigned weight for each server as shown in the following code snippet:
director dr1 client { { .backend = server01 ; .weight=2; } { .backend = server02 ; .weight=2; } { .backend = server03 ; .weight=2; } { .backend = server04 ; .weight=1; } }
Weighting the servers is only possible in the random or client directors.
'WorkHolic' 카테고리의 다른 글
넷기어 레디나스 ReadyNAS 용 앱 검토 (0) | 2021.09.24 |
---|---|
postfix queue에서 발송자/내용으로 스팸메일 찾아 지우기 (0) | 2021.09.06 |
추석특가 추석명절 선물세트 (0) | 2021.08.27 |
PTR 레코드 (리버스 DNS) 등록 방법 (LGU+) (0) | 2021.07.27 |
서버에서 보낸 메일이 다음메일에서 스팸처리 될 때 (0) | 2021.07.27 |