WEBVTT

00:00.230 --> 00:01.840
Hi, everyone, and welcome back.

00:01.850 --> 00:05.750
Now in today's video, we will be discussing about server weights.

00:05.780 --> 00:11.780
Now, server weight basically allows us to customize the request flow going between enginex that is

00:11.780 --> 00:15.200
acting as a load balancer towards the upstream backend.

00:15.200 --> 00:19.010
So let's assume that you have a load balancer here and you have two servers.

00:19.040 --> 00:22.520
Now both of these servers have a different size altogether.

00:22.520 --> 00:28.190
First server has a size of one GB Ram and second server has the capacity of four GB Ram.

00:28.190 --> 00:34.160
So definitely the first server might be able to handle a little less request when compared to that of

00:34.160 --> 00:35.240
the second server.

00:35.240 --> 00:41.900
So depending upon the size of the server, we do not really want 5,050% traffic to be equally distributed.

00:41.900 --> 00:44.020
This might not be the best strategy here.

00:44.060 --> 00:45.020
What do you want?

00:45.050 --> 00:51.590
Maybe you want 20% of the traffic to go to the smaller server and 80% of the traffic to go to the larger

00:51.590 --> 00:51.980
server.

00:51.980 --> 00:57.980
So when you have a customized environment where you need a different kind of traffic distribution,

00:57.980 --> 01:01.680
this can be achieved with the help of server weights parameter.

01:01.680 --> 01:06.780
So if you look into the sample configuration here, all you have to do is you have to specify the weight

01:06.810 --> 01:07.200
here.

01:07.200 --> 01:11.790
So for the second server with the IP of 0.4, you have a weight of two.

01:11.820 --> 01:18.510
So two requests will be sent to the IP of 0.4 and one request will be sent to the IP of 0.3.

01:18.540 --> 01:22.620
A very straightforward approach, but a very useful in production environments.

01:22.620 --> 01:25.020
So let's go ahead and get it tested.

01:25.020 --> 01:30.930
Now for today's demo, I have three servers yet again and all of these three servers have Nginx up and

01:30.930 --> 01:32.100
running perfectly well.

01:32.100 --> 01:37.590
So using the utility, let's go ahead and send ten requests here to localhost.

01:37.590 --> 01:41.400
And currently this command we are running it in a load balancer server.

01:41.400 --> 01:47.610
Now before we do that, let's go ahead and do a tale on var log Nginx access dot log.

01:47.850 --> 01:48.450
All right.

01:50.670 --> 01:54.060
Similarly, let's also do a tale here.

01:54.090 --> 01:58.170
Var log Nginx access dot log perfect.

01:58.200 --> 02:02.070
Now from the load balancer, let's go ahead and send ten requests here.

02:02.760 --> 02:09.180
Now you will see among these ten requests, five requests came to server one and five requests came

02:09.180 --> 02:09.870
to server two.

02:09.900 --> 02:14.310
So a perfect round robin based distribution of traffic is happening.

02:14.310 --> 02:15.960
So this is the perfect approach.

02:15.960 --> 02:21.810
Now let's assume that the server zero one is a smaller one and the server zero two is a larger one.

02:21.810 --> 02:25.770
So you want a little different distribution of traffic.

02:25.770 --> 02:33.420
So what you will do, you go to Nginx.conf dot D, let's modify the load balancer dot conf and for the

02:33.420 --> 02:36.720
server two, let's quickly verify the IP address again.

02:36.720 --> 02:38.700
So I'll do a control C here.

02:38.730 --> 02:40.580
Let's do a ifconfig here.

02:40.650 --> 02:48.450
The private IP address is 0.3, so for 0.3 based server I'll say weight is equal to two.

02:48.480 --> 02:50.040
I'll go ahead and save this.

02:50.160 --> 02:52.710
So let's again do a tail.

02:53.790 --> 02:54.480
All right.

02:56.580 --> 02:58.230
Same for the server one.

02:58.830 --> 03:01.910
Let's wait for new request within here.

03:01.920 --> 03:05.460
Always verify if your configuration is successful and yes it is.

03:05.460 --> 03:08.490
Let's go ahead and do a restart on Nginx.

03:08.520 --> 03:11.310
Once done, let's run the command once more.

03:11.400 --> 03:16.350
We'll send ten request and again all the ten requests are sent.

03:17.010 --> 03:23.610
Now if you look into the server one this time only three requests came to server one and all of the

03:23.610 --> 03:26.490
rest seven requests came to the server zero two.

03:26.490 --> 03:33.030
So depending upon how uneven distribution of traffic you need, you can go ahead and set the weight

03:33.030 --> 03:35.160
accordingly within your configuration file.

03:35.160 --> 03:41.340
So very simple and a very important parameter that you need to know while dealing with production traffic.

03:41.340 --> 03:43.680
So with this, we'll conclude today's video.
