WEBVTT

00:00.410 --> 00:03.960
Hi and welcome back to the Knowledge Portal Video series.

00:03.980 --> 00:10.250
So in this module we'll be talking about one of the load balancer method, which is leased Connect.

00:11.240 --> 00:16.220
So we have already seen on how exactly the round robin works.

00:16.220 --> 00:23.090
So this is one of the other methods which Enginex provides as far as reverse proxy and load balancer

00:23.090 --> 00:23.960
is concerned.

00:24.650 --> 00:30.320
So let me give you an example before we actually go into the leased connect.

00:30.590 --> 00:33.520
So let's assume there are two files.

00:33.840 --> 00:40.760
I'll write big dot php and small dot PHP.

00:45.550 --> 00:54.130
Now big dot PHP basically uses a lot of resources and takes around 20s to execute.

00:54.920 --> 01:02.830
However, small dot PHP is a very fast PHP script and takes around let's assume one second to execute.

01:03.460 --> 01:11.620
So basically the big dot PHP is 20 times slower and more resource consuming than the small dot php.

01:13.700 --> 01:15.660
So here we have two servers.

01:15.680 --> 01:17.930
This is server one and this is server two.

01:19.310 --> 01:21.510
And five client requests.

01:21.530 --> 01:29.720
So let's say the client requests comes to the server one and it is asking for big dot PHP.

01:31.340 --> 01:32.180
I'll just write.

01:35.540 --> 01:43.010
V dot php and there is a second client request b which comes to the server to.

01:45.100 --> 01:47.530
Which ask for small dot php.

01:49.900 --> 01:54.610
Now, basically in order for server one to process this client request.

01:54.640 --> 02:00.910
Server one it will have to take 20s an equivalent amount of resources.

02:01.240 --> 02:09.880
However, for the server two to execute this request, it will take around one second to execute.

02:11.470 --> 02:18.400
Now, if this was a round robin algorithm based load balancer, then the third request, which is request

02:18.430 --> 02:22.450
number C should ideally go to server one.

02:23.110 --> 02:32.290
But in this scenario, server one is already busy trying to execute the big dot php and the server two

02:32.290 --> 02:33.790
is already free now.

02:34.540 --> 02:41.830
So ideally during this time we want the request C to go to server three and not server one.

02:42.370 --> 02:50.540
So during this type of scenarios, running a round robin based algorithm is not very feasible.

02:50.810 --> 02:56.180
So we have another algorithm called as least connect.

02:56.930 --> 03:04.280
So what least connect basically means is forward the request to the server, which has least number

03:04.280 --> 03:05.870
of active connections.

03:06.530 --> 03:11.630
So currently we have B dot PHP, which is already executing.

03:11.630 --> 03:14.840
So there is already an active connection which is going on.

03:15.110 --> 03:21.800
However, for server two there is no active connection because the small dot is already executed.

03:22.430 --> 03:30.620
So for this the C should go to server two.

03:30.830 --> 03:31.340
So.

03:31.340 --> 03:34.100
So the C request has to go to server two.

03:34.670 --> 03:37.790
If it is following the least connect based method.

03:38.180 --> 03:42.230
So let me actually show you on how exactly it works.

03:44.240 --> 03:45.320
So.

03:49.880 --> 03:52.280
So I have two servers in upstream.

03:52.280 --> 03:54.710
This is server one and this is server two.

03:54.740 --> 04:03.860
So let me just refresh the page and here you see it is waiting for PHP script to be executed so it will

04:03.860 --> 04:10.850
take around 20s for this PHP script to be executed and we'll just wait for a while.

04:17.880 --> 04:19.380
And now it is executed.

04:19.380 --> 04:24.030
So it took around 20s and this is small dot PHP.

04:24.960 --> 04:26.280
I'll refresh it.

04:26.850 --> 04:30.390
And here you see it got executed instantaneously.

04:30.660 --> 04:38.970
So what we want is we want to apply the least connect based method of algorithm for our load balancer.

04:39.270 --> 04:41.160
So I've already configured it.

04:41.160 --> 04:44.400
I'll just show you the configuration.

04:46.940 --> 04:47.290
ADC.

04:47.720 --> 04:48.130
Enginex.

04:48.180 --> 04:49.120
Conf.d.

04:49.480 --> 04:50.560
Web conf.

04:53.470 --> 05:00.520
So here what we have mentioned is we have mentioned lease underscore Conn in the upstream directive.

05:00.550 --> 05:07.810
So in the round robin, we don't have to mention anything because it takes round robin as a default.

05:07.840 --> 05:13.870
However, if you want some other load balancing algorithm, then you have to specify the name of algorithm

05:13.870 --> 05:15.070
that you want to choose.

05:15.430 --> 05:18.190
So for this we have choose Lease Connect.

05:21.830 --> 05:24.140
So let's go to the.

05:28.830 --> 05:31.320
Server and let's do apachebench.

05:31.530 --> 05:33.090
So what I'll do is.

05:35.220 --> 05:38.580
I'll do a tail to the engine logs.

05:42.600 --> 05:46.480
So this is server one and this is server two.

05:50.700 --> 05:52.470
So this is row one.

05:52.470 --> 05:57.630
This is server to server one has big PHP, server two has small dot PHP.

05:58.710 --> 06:03.420
Now the naming across both the server is same which is test dot PHP.

06:04.230 --> 06:09.030
So let's keep that in mind and let's run apachebench.

06:10.440 --> 06:11.190
So let's see.

06:11.220 --> 06:19.200
Number of connections limited to 20 concurrent, let's say ten followed by the IP address of the reverse

06:19.200 --> 06:20.130
proxy.

06:24.540 --> 06:27.140
Which is this?

06:28.170 --> 06:29.220
I copy this.

06:30.240 --> 06:31.650
I'll paste it over here.

06:35.900 --> 06:36.590
Oops.

06:39.250 --> 06:40.570
Followed by the code number.

06:41.230 --> 06:41.950
So what?

06:41.980 --> 06:48.970
Basically this will do is it will send ten concurrent requests to the reverse proxy.

06:48.970 --> 06:55.330
So this is the reverse proxy and total number of requests would be 20.

06:55.450 --> 07:03.010
So ideally as we are using least connect the server to which is having small dot php should get the

07:03.010 --> 07:04.960
most number of requests.

07:04.990 --> 07:11.680
However, the server one which is running big dot php should get least number of requests.

07:11.710 --> 07:17.110
So let's run the Apache bench and let's see on how many requests the server each server gets.

07:24.250 --> 07:25.450
About event.

07:27.980 --> 07:29.660
And 20.

07:33.610 --> 07:34.960
Let me figure it out.

07:36.940 --> 07:37.570
Okay.

07:45.010 --> 07:51.310
Apachebench, followed by the total number of requests that we want to send, which is 20 concurrent

07:51.310 --> 07:53.410
requests, will be ten.

07:54.310 --> 08:01.690
The address of the reverse proxy server, which was 52 dot.

08:04.490 --> 08:05.540
6.23.

08:05.540 --> 08:06.350
37.23.

08:06.440 --> 08:16.310
28 6.237.2 28 followed by the optional port number and it seems to be giving some error.

08:17.150 --> 08:18.830
Let's remove the port number.

08:24.990 --> 08:25.470
Okay.

08:27.870 --> 08:33.120
Or you can just put 28 slash and this seems to be working now.

08:33.540 --> 08:34.080
Okay.

08:34.410 --> 08:37.830
So now it is sending 20 number of total requests.

08:37.830 --> 08:42.090
So ideally, let's see on how exactly the logs work.

08:42.720 --> 08:48.540
So this is server two which is running small dot php with the name test dot php.

08:48.750 --> 08:52.650
So this seems to have got the maximum number of requests.

08:52.650 --> 09:02.880
So let's just count one, two, three, four, five, six, seven, eight, nine, ten, 11, 12, 13,

09:02.880 --> 09:04.140
14, 15.

09:04.140 --> 09:12.170
So the server two has got 15 requests and the server one has got only five requests.

09:12.180 --> 09:20.400
So you see with least connect the reverse proxy will send the request to the server which with least

09:20.400 --> 09:22.020
number of active connections.

09:22.020 --> 09:29.380
So this is sometimes useful in a production environment where one of the servers has some very big scripts

09:30.250 --> 09:32.620
while others has the smaller ones.

09:32.770 --> 09:38.020
So this is it about the least connect based algorithm.

09:38.290 --> 09:45.250
I hope this has been informative for you and I'll be posting the scripts, detail the content of the

09:45.250 --> 09:51.780
scripts on the website so you can download it and you can test it on your machines.

09:51.790 --> 09:52.690
So this is it.

09:52.690 --> 09:53.560
About this video.

09:53.560 --> 09:57.100
I hope this has been informative for you and I'd like to thank you for viewing.
