Hi, everyone, and welcome back.
Now in today's video, we will be discussing about server weights.
Now, server weight basically allows us to customize the request flow going between enginex that is
acting as a load balancer towards the upstream backend.
So let's assume that you have a load balancer here and you have two servers.
Now both of these servers have a different size altogether.
First server has a size of one GB Ram and second server has the capacity of four GB Ram.
So definitely the first server might be able to handle a little less request when compared to that of
the second server.
So depending upon the size of the server, we do not really want 5,050% traffic to be equally distributed.
This might not be the best strategy here.
What do you want?
Maybe you want 20% of the traffic to go to the smaller server and 80% of the traffic to go to the larger
server.
So when you have a customized environment where you need a different kind of traffic distribution,
this can be achieved with the help of server weights parameter.
So if you look into the sample configuration here, all you have to do is you have to specify the weight
here.
So for the second server with the IP of 0.4, you have a weight of two.
So two requests will be sent to the IP of 0.4 and one request will be sent to the IP of 0.3.
A very straightforward approach, but a very useful in production environments.
So let's go ahead and get it tested.
Now for today's demo, I have three servers yet again and all of these three servers have Nginx up and
running perfectly well.
So using the utility, let's go ahead and send ten requests here to localhost.
And currently this command we are running it in a load balancer server.
Now before we do that, let's go ahead and do a tale on var log Nginx access dot log.
All right.
Similarly, let's also do a tale here.
Var log Nginx access dot log perfect.
Now from the load balancer, let's go ahead and send ten requests here.
Now you will see among these ten requests, five requests came to server one and five requests came
to server two.
So a perfect round robin based distribution of traffic is happening.
So this is the perfect approach.
Now let's assume that the server zero one is a smaller one and the server zero two is a larger one.
So you want a little different distribution of traffic.
So what you will do, you go to Nginx.conf dot D, let's modify the load balancer dot conf and for the
server two, let's quickly verify the IP address again.
So I'll do a control C here.
Let's do a ifconfig here.
The private IP address is 0.3, so for 0.3 based server I'll say weight is equal to two.
I'll go ahead and save this.
So let's again do a tail.
All right.
Same for the server one.
Let's wait for new request within here.
Always verify if your configuration is successful and yes it is.
Let's go ahead and do a restart on Nginx.
Once done, let's run the command once more.
We'll send ten request and again all the ten requests are sent.
Now if you look into the server one this time only three requests came to server one and all of the
rest seven requests came to the server zero two.
So depending upon how uneven distribution of traffic you need, you can go ahead and set the weight
accordingly within your configuration file.
So very simple and a very important parameter that you need to know while dealing with production traffic.
So with this, we'll conclude today's video.