Hi and welcome back to the Knowledge Portal Video series.
So in this module we'll be talking about one of the load balancer method, which is leased Connect.
So we have already seen on how exactly the round robin works.
So this is one of the other methods which Enginex provides as far as reverse proxy and load balancer
is concerned.
So let me give you an example before we actually go into the leased connect.
So let's assume there are two files.
I'll write big dot php and small dot PHP.
Now big dot PHP basically uses a lot of resources and takes around 20s to execute.
However, small dot PHP is a very fast PHP script and takes around let's assume one second to execute.
So basically the big dot PHP is 20 times slower and more resource consuming than the small dot php.
So here we have two servers.
This is server one and this is server two.
And five client requests.
So let's say the client requests comes to the server one and it is asking for big dot PHP.
I'll just write.
V dot php and there is a second client request b which comes to the server to.
Which ask for small dot php.
Now, basically in order for server one to process this client request.
Server one it will have to take 20s an equivalent amount of resources.
However, for the server two to execute this request, it will take around one second to execute.
Now, if this was a round robin algorithm based load balancer, then the third request, which is request
number C should ideally go to server one.
But in this scenario, server one is already busy trying to execute the big dot php and the server two
is already free now.
So ideally during this time we want the request C to go to server three and not server one.
So during this type of scenarios, running a round robin based algorithm is not very feasible.
So we have another algorithm called as least connect.
So what least connect basically means is forward the request to the server, which has least number
of active connections.
So currently we have B dot PHP, which is already executing.
So there is already an active connection which is going on.
However, for server two there is no active connection because the small dot is already executed.
So for this the C should go to server two.
So.
So the C request has to go to server two.
If it is following the least connect based method.
So let me actually show you on how exactly it works.
So.
So I have two servers in upstream.
This is server one and this is server two.
So let me just refresh the page and here you see it is waiting for PHP script to be executed so it will
take around 20s for this PHP script to be executed and we'll just wait for a while.
And now it is executed.
So it took around 20s and this is small dot PHP.
I'll refresh it.
And here you see it got executed instantaneously.
So what we want is we want to apply the least connect based method of algorithm for our load balancer.
So I've already configured it.
I'll just show you the configuration.
ADC.
Enginex.
Conf.d.
Web conf.
So here what we have mentioned is we have mentioned lease underscore Conn in the upstream directive.
So in the round robin, we don't have to mention anything because it takes round robin as a default.
However, if you want some other load balancing algorithm, then you have to specify the name of algorithm
that you want to choose.
So for this we have choose Lease Connect.
So let's go to the.
Server and let's do apachebench.
So what I'll do is.
I'll do a tail to the engine logs.
So this is server one and this is server two.
So this is row one.
This is server to server one has big PHP, server two has small dot PHP.
Now the naming across both the server is same which is test dot PHP.
So let's keep that in mind and let's run apachebench.
So let's see.
Number of connections limited to 20 concurrent, let's say ten followed by the IP address of the reverse
proxy.
Which is this?
I copy this.
I'll paste it over here.
Oops.
Followed by the code number.
So what?
Basically this will do is it will send ten concurrent requests to the reverse proxy.
So this is the reverse proxy and total number of requests would be 20.
So ideally as we are using least connect the server to which is having small dot php should get the
most number of requests.
However, the server one which is running big dot php should get least number of requests.
So let's run the Apache bench and let's see on how many requests the server each server gets.
About event.
And 20.
Let me figure it out.
Okay.
Apachebench, followed by the total number of requests that we want to send, which is 20 concurrent
requests, will be ten.
The address of the reverse proxy server, which was 52 dot.
6.23.
37.23.
28 6.237.2 28 followed by the optional port number and it seems to be giving some error.
Let's remove the port number.
Okay.
Or you can just put 28 slash and this seems to be working now.
Okay.
So now it is sending 20 number of total requests.
So ideally, let's see on how exactly the logs work.
So this is server two which is running small dot php with the name test dot php.
So this seems to have got the maximum number of requests.
So let's just count one, two, three, four, five, six, seven, eight, nine, ten, 11, 12, 13,
14, 15.
So the server two has got 15 requests and the server one has got only five requests.
So you see with least connect the reverse proxy will send the request to the server which with least
number of active connections.
So this is sometimes useful in a production environment where one of the servers has some very big scripts
while others has the smaller ones.
So this is it about the least connect based algorithm.
I hope this has been informative for you and I'll be posting the scripts, detail the content of the
scripts on the website so you can download it and you can test it on your machines.
So this is it.
About this video.
I hope this has been informative for you and I'd like to thank you for viewing.