Hello, everyone, and welcome to this new and exciting session in which we are going to be looking
at load testing.
The load testing tool will be using will be lockers and lockers will permit us not only define user
behavior with Python code, but also swarm our system or API, which will build already with millions
of simultaneous users.
So in this course we'll see how to test or better still to load test the API we've built previously
both locally and on the cloud.
At this point you've already tested the model which has been deployed on Heroku and everything looks
fine.
But then what if we tell you that we will have to still carry out some load testing?
Now what's the point of load testing?
The point of load testing is to see how this your API, which you build, will react when you have many
users.
So you wouldn't generally want to create APIs to be used by yourself only, but maybe to be used by
tens of thousands and even millions of different simultaneous users.
So we cannot get access to this millions of people.
So you wouldn't start calling each and every one of those people here to test your API.
And what you will do is to have an automated system where this millions of users are simulated and this
tool will be using your to simulate this millions of users is lowcost, which is an open source load
testing tool.
That said, we are going to create this low cost p file.
So here we have low costs dot p y, there we go.
And then in this file we are going to write out all the code will need to be able to control or simulate
all the users who will be using the platform.
So here we have from log costs, we're going to import sequential task set.
Now, one thing you should note is the fact that with low cost, we use an or we define defining different
tasks and here we are going to define a task whose role would be to simply open up a specific image
and then pass this image via a post request to our API and we obtain the required outputs.
So let's define this emotions.
So emotions task or essay detector task detector task.
And this is sequential text set.
So we have this and then we have this task decorator, we have our task decorator right here.
We're going to define our detection method.
And here the detection method is simply going to be this method where we define what's actually going
to go on when we want to test out our application or load test our application.
So here we have with open, we open up a file which we're going to create locally.
So we have this image.
JPG And there we go.
So we open this file as image and then now we are going to carry out our push request.
So we have that push request and then you see we're going to specify the path, this URL and that's
detect actually want to do for the tag, meaning that you could replace this with test or some other
path you want.
So for now it's detect and then let's get back here for now is detect.
And then now we specify that we're passing a file.
So here we have those files and we have the name M actually.
M And then here we have image.
So remember, we've opened this up as image.
So this is the image we pass in here now from the API we designed already this name.
Yeah.
What we have is M So that's why we specify in this scheme.
And then once we have this set, so this is our detector task, as I said, of the way we build this,
we lock us is we define different tasks and then once we define these different tasks now we could simply
define our load tester class.
So here we have class load tester, and then we have H to type user.
So this inherits from class HTTP user and then.
Specify the host.
Our host in this case is going to simply be what we've been using already.
So this which we deployed on Roku.
Let's copy this, get back here and then paste this out.
So we should we should take off now this detect.
So we'll take that off and that's it.
So we just pass it in this as our host.
And then once we pass this as a host, we now specify the task.
So this is a task.
In this case, our task is the detector task.
Okay, so that's it.
We've specified the task.
Remember, you could obviously create many more different tasks, but for now, we just want to work
only with this detector task.
So that's it.
We have that set.
We could save this, and then now we could go ahead and launch our low cost.
So we have low cost.
We specify that we have a file and it's low costs dot pie.
There we go.
So let's run this low cost command node found.
Oh, we forgot to install local, so let's do pip install low cost.
There we go.
That should work.
Fine.
So install our costs and once we install our cost, we are going to run this command right here.
And now that we have that installed, what we're going to do is run back this.
So there we go, we run this and we could click on this.
So let's click there and see what we get.
So here we have our lockers running.
So yeah, we start new load test.
So now the number of users initially is one, the spawn rate is one.
We're going to check this on later on and then notice how we have this, our URL, which we had specified.
So that's our host which we specified already.
Now let's start the swarming by our low costs.
There we go.
Remember, this is hosted online, so it's going to check that up.
Looks like none is working.
Well, let's check out this chart statistics.
Well, let's get back here.
Let's get back here.
We get in something like this.
So we got some errors.
We could see there are no tags.
The final load tester.
Let's save this.
And then we run this and see what we get.
We run that again, but we still get in this error.
So we have to stop.
And let's check out why we get in this error.
Yeah, we have no tags.
The final load tester, but you have set a task attribute on your class.
Maybe you meant to set tasks here.
Here.
This should be tasks because this actually at least remember, as we said, we define different tasks
and then we have our load tester right here.
So we could have this task here.
We have some other task, oops, we can have some other task, and so on and so forth.
So let's say we have two tasks.
Let's say we have tags and then we'll call this tag stool.
Then we are going to come right here and then put this in this list.
But given that we just have a single task, let's take this text to out.
And then now as we saw here, we should have your tasks and not just task.
So let's save that and then run this again.
And now everything should work fine.
Okay, so we have that.
We click open, start swarming.
Looks like isn't working.
Let's get back here.
Stop this now.
Let's check out the error.
We get in no such file as this.
Okay, So remember, we don't have this file in this directory, so let's just go ahead and copy that
file.
Now, we've copied the file.
You can see that here we have our file here.
Let's go ahead and rerun this.
And now everything should work.
Fine.
So let's click on this.
Open up, start the swarming, and.
Well, let's get back.
We still get an error.
Stop this and check this out.
Yeah, we told that no such file or this.
Well, let's, let's rename this rename.
This should be test image.
Okay, so let's run this again.
It's fine.
Open up, start the swarming and looks like another error
all users want.
Well, let's check back here and you can see that we have this working as expected.
So you can see we have a certain number of requests which we.
Send already zero fills.
We have the median latency, we have the 90 percentile latency, 99 percentile, the average, the mean
and the max.
So you could see that it's taken about 2 seconds for every user to receive whatever output the sent
in.
So that's it.
So we have this mean and we have this Max.
Now we could get into the charts and you see that this is increasing slowly and we have zero failures.
So that's very important.
We have zero failures with just a single user.
And that single user is, as we saw here, getting an average of now is one point 7 milliseconds to
receive the output from the API.
So that's it.
Now another thing we could do is actually stop this and then carry out a new test where we would have
say, ten users.
So we want to test when we have ten users at a time.
Now this spawn rate here fixed at the value of two will simply mean that after every second we are going
to add up to users.
So we're going to start with two users and then after one second we go to four.
After 2 seconds we go to six and so on and so forth.
Until we attain the maximum number of users which we've set already here.
So let's start the swarming.
You can see here we start initially with two, we're going to six and then ten, and after some time
you're going to have the first requests.
So there we go.
We already have two two requests, not that we have dealing with ten users here, and the average time
it takes for each user to receive the response is 10 seconds, meaning that our system will take about
10 seconds to reply to whatever user whenever we have ten simultaneous users.
So let's get into Postman.
Remember here we have this time elapsed.
Note that this time elapsed was for the model, but what we get now is what each and every user located
in some place in the world would have as actual time or latency.
If we have ten users now you start seeing that we start getting failures.
So let's check this out.
When you run this, let's run error code logs.
So yeah, let's clear this so you could see that clearly.
So we run error call logs and then we specify the app emotional detection neural learn and specify tio
so we could get the last logs.
So run that and they should run.
You can see that we have successful calls and we also have this calls which field this is a status and
your connection closed with our response.
So let's get back here.
Remember when we had a single user, we didn't have all this failures.
So let's stop this, run your tests and reduce this.
Maybe it's just three users and then see what we get.
Well, as you can see with just three users, we have fewer failures.
That's about 7% as we could see here.
And it takes on average of 4.5 seconds to receive outputs when you send input images.
And so with this, we have just built and load Tesla API.
They showed us clearly that if we want this to go faster or to reduce our latency and reduce the failure
percentage, which as of now is at 2%, then we'll need to increase our compute capacities.
So that's it for this section.
See you in the next section.