1
00:00:00,150 --> 00:00:06,300
Hello, everyone, and welcome to this new and exciting session in which we are going to be looking

2
00:00:06,300 --> 00:00:07,860
at load testing.

3
00:00:07,890 --> 00:00:17,460
The load testing tool will be using will be lockers and lockers will permit us not only define user

4
00:00:17,460 --> 00:00:26,700
behavior with Python code, but also swarm our system or API, which will build already with millions

5
00:00:26,700 --> 00:00:28,710
of simultaneous users.

6
00:00:28,890 --> 00:00:37,650
So in this course we'll see how to test or better still to load test the API we've built previously

7
00:00:37,650 --> 00:00:41,110
both locally and on the cloud.

8
00:00:41,130 --> 00:00:49,110
At this point you've already tested the model which has been deployed on Heroku and everything looks

9
00:00:49,110 --> 00:00:49,770
fine.

10
00:00:49,950 --> 00:00:56,520
But then what if we tell you that we will have to still carry out some load testing?

11
00:00:56,760 --> 00:00:58,800
Now what's the point of load testing?

12
00:00:58,830 --> 00:01:07,470
The point of load testing is to see how this your API, which you build, will react when you have many

13
00:01:07,470 --> 00:01:08,100
users.

14
00:01:08,100 --> 00:01:15,300
So you wouldn't generally want to create APIs to be used by yourself only, but maybe to be used by

15
00:01:15,330 --> 00:01:20,370
tens of thousands and even millions of different simultaneous users.

16
00:01:20,370 --> 00:01:24,720
So we cannot get access to this millions of people.

17
00:01:24,720 --> 00:01:31,320
So you wouldn't start calling each and every one of those people here to test your API.

18
00:01:31,320 --> 00:01:40,380
And what you will do is to have an automated system where this millions of users are simulated and this

19
00:01:40,800 --> 00:01:47,580
tool will be using your to simulate this millions of users is lowcost, which is an open source load

20
00:01:47,580 --> 00:01:48,540
testing tool.

21
00:01:48,540 --> 00:01:52,620
That said, we are going to create this low cost p file.

22
00:01:52,620 --> 00:01:57,180
So here we have low costs dot p y, there we go.

23
00:01:57,180 --> 00:02:06,420
And then in this file we are going to write out all the code will need to be able to control or simulate

24
00:02:06,420 --> 00:02:08,730
all the users who will be using the platform.

25
00:02:08,730 --> 00:02:16,620
So here we have from log costs, we're going to import sequential task set.

26
00:02:16,890 --> 00:02:22,980
Now, one thing you should note is the fact that with low cost, we use an or we define defining different

27
00:02:22,980 --> 00:02:31,980
tasks and here we are going to define a task whose role would be to simply open up a specific image

28
00:02:31,980 --> 00:02:41,760
and then pass this image via a post request to our API and we obtain the required outputs.

29
00:02:41,760 --> 00:02:46,080
So let's define this emotions.

30
00:02:46,560 --> 00:02:53,730
So emotions task or essay detector task detector task.

31
00:02:53,730 --> 00:02:57,180
And this is sequential text set.

32
00:02:57,180 --> 00:03:05,190
So we have this and then we have this task decorator, we have our task decorator right here.

33
00:03:05,190 --> 00:03:08,400
We're going to define our detection method.

34
00:03:08,400 --> 00:03:16,470
And here the detection method is simply going to be this method where we define what's actually going

35
00:03:16,470 --> 00:03:23,070
to go on when we want to test out our application or load test our application.

36
00:03:23,070 --> 00:03:28,650
So here we have with open, we open up a file which we're going to create locally.

37
00:03:28,650 --> 00:03:31,170
So we have this image.

38
00:03:31,800 --> 00:03:35,670
JPG And there we go.

39
00:03:35,670 --> 00:03:45,450
So we open this file as image and then now we are going to carry out our push request.

40
00:03:45,690 --> 00:03:54,090
So we have that push request and then you see we're going to specify the path, this URL and that's

41
00:03:54,090 --> 00:03:59,880
detect actually want to do for the tag, meaning that you could replace this with test or some other

42
00:03:59,880 --> 00:04:00,750
path you want.

43
00:04:00,750 --> 00:04:06,510
So for now it's detect and then let's get back here for now is detect.

44
00:04:06,510 --> 00:04:10,140
And then now we specify that we're passing a file.

45
00:04:10,140 --> 00:04:15,750
So here we have those files and we have the name M actually.

46
00:04:15,750 --> 00:04:17,880
M And then here we have image.

47
00:04:17,880 --> 00:04:21,480
So remember, we've opened this up as image.

48
00:04:21,480 --> 00:04:28,020
So this is the image we pass in here now from the API we designed already this name.

49
00:04:28,020 --> 00:04:28,290
Yeah.

50
00:04:28,290 --> 00:04:31,540
What we have is M So that's why we specify in this scheme.

51
00:04:31,560 --> 00:04:37,410
And then once we have this set, so this is our detector task, as I said, of the way we build this,

52
00:04:37,410 --> 00:04:44,760
we lock us is we define different tasks and then once we define these different tasks now we could simply

53
00:04:44,760 --> 00:04:48,150
define our load tester class.

54
00:04:48,150 --> 00:04:55,980
So here we have class load tester, and then we have H to type user.

55
00:04:55,980 --> 00:04:59,910
So this inherits from class HTTP user and then.

56
00:05:00,270 --> 00:05:01,610
Specify the host.

57
00:05:01,620 --> 00:05:06,720
Our host in this case is going to simply be what we've been using already.

58
00:05:06,720 --> 00:05:09,900
So this which we deployed on Roku.

59
00:05:10,260 --> 00:05:15,270
Let's copy this, get back here and then paste this out.

60
00:05:15,390 --> 00:05:18,030
So we should we should take off now this detect.

61
00:05:18,030 --> 00:05:20,610
So we'll take that off and that's it.

62
00:05:20,610 --> 00:05:24,030
So we just pass it in this as our host.

63
00:05:24,030 --> 00:05:27,900
And then once we pass this as a host, we now specify the task.

64
00:05:27,900 --> 00:05:29,610
So this is a task.

65
00:05:30,120 --> 00:05:33,710
In this case, our task is the detector task.

66
00:05:33,720 --> 00:05:35,250
Okay, so that's it.

67
00:05:35,280 --> 00:05:37,170
We've specified the task.

68
00:05:37,440 --> 00:05:44,010
Remember, you could obviously create many more different tasks, but for now, we just want to work

69
00:05:44,010 --> 00:05:45,900
only with this detector task.

70
00:05:45,900 --> 00:05:47,040
So that's it.

71
00:05:47,760 --> 00:05:48,780
We have that set.

72
00:05:48,780 --> 00:05:54,660
We could save this, and then now we could go ahead and launch our low cost.

73
00:05:54,660 --> 00:05:56,820
So we have low cost.

74
00:05:57,090 --> 00:06:02,310
We specify that we have a file and it's low costs dot pie.

75
00:06:03,330 --> 00:06:03,900
There we go.

76
00:06:03,900 --> 00:06:06,660
So let's run this low cost command node found.

77
00:06:06,660 --> 00:06:11,550
Oh, we forgot to install local, so let's do pip install low cost.

78
00:06:12,990 --> 00:06:13,790
There we go.

79
00:06:13,800 --> 00:06:14,460
That should work.

80
00:06:14,460 --> 00:06:15,120
Fine.

81
00:06:15,120 --> 00:06:22,440
So install our costs and once we install our cost, we are going to run this command right here.

82
00:06:23,100 --> 00:06:28,470
And now that we have that installed, what we're going to do is run back this.

83
00:06:28,710 --> 00:06:33,540
So there we go, we run this and we could click on this.

84
00:06:33,540 --> 00:06:36,870
So let's click there and see what we get.

85
00:06:37,140 --> 00:06:40,080
So here we have our lockers running.

86
00:06:40,080 --> 00:06:43,350
So yeah, we start new load test.

87
00:06:43,350 --> 00:06:48,030
So now the number of users initially is one, the spawn rate is one.

88
00:06:48,030 --> 00:06:54,030
We're going to check this on later on and then notice how we have this, our URL, which we had specified.

89
00:06:54,030 --> 00:06:56,810
So that's our host which we specified already.

90
00:06:56,820 --> 00:07:00,030
Now let's start the swarming by our low costs.

91
00:07:00,660 --> 00:07:01,830
There we go.

92
00:07:01,830 --> 00:07:05,880
Remember, this is hosted online, so it's going to check that up.

93
00:07:08,150 --> 00:07:09,810
Looks like none is working.

94
00:07:09,810 --> 00:07:13,650
Well, let's check out this chart statistics.

95
00:07:13,950 --> 00:07:16,200
Well, let's get back here.

96
00:07:16,230 --> 00:07:17,670
Let's get back here.

97
00:07:17,670 --> 00:07:21,390
We get in something like this.

98
00:07:21,960 --> 00:07:23,250
So we got some errors.

99
00:07:23,250 --> 00:07:24,470
We could see there are no tags.

100
00:07:24,480 --> 00:07:25,800
The final load tester.

101
00:07:25,800 --> 00:07:27,000
Let's save this.

102
00:07:27,000 --> 00:07:30,000
And then we run this and see what we get.

103
00:07:31,080 --> 00:07:33,420
We run that again, but we still get in this error.

104
00:07:33,420 --> 00:07:34,560
So we have to stop.

105
00:07:34,560 --> 00:07:37,530
And let's check out why we get in this error.

106
00:07:38,580 --> 00:07:39,630
Yeah, we have no tags.

107
00:07:39,630 --> 00:07:43,500
The final load tester, but you have set a task attribute on your class.

108
00:07:43,500 --> 00:07:45,930
Maybe you meant to set tasks here.

109
00:07:46,350 --> 00:07:47,250
Here.

110
00:07:47,430 --> 00:07:52,530
This should be tasks because this actually at least remember, as we said, we define different tasks

111
00:07:52,530 --> 00:07:54,660
and then we have our load tester right here.

112
00:07:54,660 --> 00:07:57,960
So we could have this task here.

113
00:07:58,110 --> 00:08:04,430
We have some other task, oops, we can have some other task, and so on and so forth.

114
00:08:04,440 --> 00:08:06,930
So let's say we have two tasks.

115
00:08:07,080 --> 00:08:11,400
Let's say we have tags and then we'll call this tag stool.

116
00:08:11,400 --> 00:08:16,050
Then we are going to come right here and then put this in this list.

117
00:08:16,050 --> 00:08:21,000
But given that we just have a single task, let's take this text to out.

118
00:08:21,150 --> 00:08:26,490
And then now as we saw here, we should have your tasks and not just task.

119
00:08:26,490 --> 00:08:30,420
So let's save that and then run this again.

120
00:08:30,420 --> 00:08:33,030
And now everything should work fine.

121
00:08:33,750 --> 00:08:35,250
Okay, so we have that.

122
00:08:35,250 --> 00:08:39,120
We click open, start swarming.

123
00:08:40,170 --> 00:08:42,000
Looks like isn't working.

124
00:08:42,000 --> 00:08:43,440
Let's get back here.

125
00:08:43,830 --> 00:08:45,930
Stop this now.

126
00:08:45,930 --> 00:08:47,250
Let's check out the error.

127
00:08:47,250 --> 00:08:50,130
We get in no such file as this.

128
00:08:50,130 --> 00:08:55,860
Okay, So remember, we don't have this file in this directory, so let's just go ahead and copy that

129
00:08:55,860 --> 00:08:56,490
file.

130
00:08:57,150 --> 00:08:58,590
Now, we've copied the file.

131
00:08:58,590 --> 00:09:01,380
You can see that here we have our file here.

132
00:09:01,380 --> 00:09:03,450
Let's go ahead and rerun this.

133
00:09:03,450 --> 00:09:05,070
And now everything should work.

134
00:09:05,070 --> 00:09:05,460
Fine.

135
00:09:05,460 --> 00:09:08,340
So let's click on this.

136
00:09:08,340 --> 00:09:12,270
Open up, start the swarming, and.

137
00:09:12,510 --> 00:09:13,680
Well, let's get back.

138
00:09:13,680 --> 00:09:14,940
We still get an error.

139
00:09:16,380 --> 00:09:19,680
Stop this and check this out.

140
00:09:20,430 --> 00:09:24,840
Yeah, we told that no such file or this.

141
00:09:24,840 --> 00:09:27,720
Well, let's, let's rename this rename.

142
00:09:29,040 --> 00:09:32,460
This should be test image.

143
00:09:32,550 --> 00:09:35,190
Okay, so let's run this again.

144
00:09:36,170 --> 00:09:37,140
It's fine.

145
00:09:38,040 --> 00:09:44,520
Open up, start the swarming and looks like another error

146
00:09:47,100 --> 00:09:49,440
all users want.

147
00:09:50,970 --> 00:09:56,940
Well, let's check back here and you can see that we have this working as expected.

148
00:09:56,940 --> 00:09:59,660
So you can see we have a certain number of requests which we.

149
00:09:59,800 --> 00:10:01,500
Send already zero fills.

150
00:10:01,510 --> 00:10:10,150
We have the median latency, we have the 90 percentile latency, 99 percentile, the average, the mean

151
00:10:10,150 --> 00:10:10,810
and the max.

152
00:10:10,810 --> 00:10:19,450
So you could see that it's taken about 2 seconds for every user to receive whatever output the sent

153
00:10:19,450 --> 00:10:19,900
in.

154
00:10:19,900 --> 00:10:20,650
So that's it.

155
00:10:20,650 --> 00:10:23,100
So we have this mean and we have this Max.

156
00:10:23,110 --> 00:10:29,440
Now we could get into the charts and you see that this is increasing slowly and we have zero failures.

157
00:10:29,440 --> 00:10:30,430
So that's very important.

158
00:10:30,430 --> 00:10:33,610
We have zero failures with just a single user.

159
00:10:33,610 --> 00:10:43,570
And that single user is, as we saw here, getting an average of now is one point 7 milliseconds to

160
00:10:43,990 --> 00:10:46,380
receive the output from the API.

161
00:10:46,390 --> 00:10:47,470
So that's it.

162
00:10:48,790 --> 00:10:54,850
Now another thing we could do is actually stop this and then carry out a new test where we would have

163
00:10:54,850 --> 00:10:56,440
say, ten users.

164
00:10:56,440 --> 00:10:59,380
So we want to test when we have ten users at a time.

165
00:10:59,380 --> 00:11:06,640
Now this spawn rate here fixed at the value of two will simply mean that after every second we are going

166
00:11:06,640 --> 00:11:08,110
to add up to users.

167
00:11:08,110 --> 00:11:12,420
So we're going to start with two users and then after one second we go to four.

168
00:11:12,430 --> 00:11:14,830
After 2 seconds we go to six and so on and so forth.

169
00:11:14,860 --> 00:11:18,670
Until we attain the maximum number of users which we've set already here.

170
00:11:18,670 --> 00:11:19,930
So let's start the swarming.

171
00:11:19,930 --> 00:11:27,550
You can see here we start initially with two, we're going to six and then ten, and after some time

172
00:11:27,550 --> 00:11:29,710
you're going to have the first requests.

173
00:11:29,710 --> 00:11:30,820
So there we go.

174
00:11:30,820 --> 00:11:36,670
We already have two two requests, not that we have dealing with ten users here, and the average time

175
00:11:36,670 --> 00:11:43,300
it takes for each user to receive the response is 10 seconds, meaning that our system will take about

176
00:11:43,300 --> 00:11:50,710
10 seconds to reply to whatever user whenever we have ten simultaneous users.

177
00:11:50,710 --> 00:11:55,120
So let's get into Postman.

178
00:11:55,120 --> 00:11:58,240
Remember here we have this time elapsed.

179
00:11:58,270 --> 00:12:06,310
Note that this time elapsed was for the model, but what we get now is what each and every user located

180
00:12:06,310 --> 00:12:14,320
in some place in the world would have as actual time or latency.

181
00:12:14,710 --> 00:12:18,940
If we have ten users now you start seeing that we start getting failures.

182
00:12:18,940 --> 00:12:20,860
So let's check this out.

183
00:12:22,210 --> 00:12:26,260
When you run this, let's run error code logs.

184
00:12:26,260 --> 00:12:29,260
So yeah, let's clear this so you could see that clearly.

185
00:12:29,440 --> 00:12:36,480
So we run error call logs and then we specify the app emotional detection neural learn and specify tio

186
00:12:36,490 --> 00:12:39,580
so we could get the last logs.

187
00:12:39,580 --> 00:12:45,070
So run that and they should run.

188
00:12:46,870 --> 00:12:53,950
You can see that we have successful calls and we also have this calls which field this is a status and

189
00:12:53,950 --> 00:12:56,650
your connection closed with our response.

190
00:12:56,650 --> 00:12:58,960
So let's get back here.

191
00:12:58,960 --> 00:13:02,710
Remember when we had a single user, we didn't have all this failures.

192
00:13:02,710 --> 00:13:08,320
So let's stop this, run your tests and reduce this.

193
00:13:08,320 --> 00:13:12,340
Maybe it's just three users and then see what we get.

194
00:13:13,180 --> 00:13:17,530
Well, as you can see with just three users, we have fewer failures.

195
00:13:17,530 --> 00:13:19,930
That's about 7% as we could see here.

196
00:13:19,930 --> 00:13:29,020
And it takes on average of 4.5 seconds to receive outputs when you send input images.

197
00:13:29,800 --> 00:13:33,400
And so with this, we have just built and load Tesla API.

198
00:13:33,430 --> 00:13:41,530
They showed us clearly that if we want this to go faster or to reduce our latency and reduce the failure

199
00:13:41,530 --> 00:13:47,860
percentage, which as of now is at 2%, then we'll need to increase our compute capacities.

200
00:13:47,860 --> 00:13:49,630
So that's it for this section.

201
00:13:49,630 --> 00:13:51,310
See you in the next section.
