728x90
반응형

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...

  1. 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.
  2. director dr1 round-robin { { .backend = server01 } { .backend = server02 } { .backend = server03 } { .backend = server04 } }
  3. 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; }
  4. 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.
  5. 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.
  6. 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.

 

https://subscription.packtpub.com/book/hardware_and_creative/9781782160403/1/ch01lvl1sec11/load-balance-requests-(should-know) 

 

Load balance requests (Should know) | Instant Varnish Cache How-to

 

www.prod.packt.com

 

728x90
SMALL
Posted by gromet

블로그 이미지
나는 운이 좋은 사람이다 나는 나날이 점점 더 좋아진다 내가 하는 선택과 행동은 반드시 성공으로 이어진다 내게는 인내력과 지속력이 있다 네게는 좋은것들만 모여든다
gromet

공지사항

Yesterday
Today
Total
반응형

달력

 « |  » 2024.9
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

160x600