Tests are really important in the software development cycle. But how we can test if our API - or even a page - will support the web traffic and requests our users will create by accessing them?
In this video, you will learn how to create HTTP load and benchmarking tests in Node.js using the autocannon package. With that, we can make sure our API is not consuming too much memory, CPU, or any other resource that can cause slow responses.
Instructor: [0:01] We need to clone our repo called micro-frontend pages. We go, click at the link, and moving back to our terminal, we can run Git-Clone, pass in the link that we copied. Inside the folder, we can run docker-compose, and space up --viewed.
[0:20] We can run all docker configuration that we have for all the pages in the repo, and view their images. Now that we have this adapt finished, let's route to cannon. We'll be routing to cannon and configuring to simulate 100 connections for 30 seconds, with time per manual requests, bypassing 100 on Dash-C, 30 on Dash-D, and 10 on Dash-B.
[0:48] As a last parameter, we can pass the website for a round of tests. Now pointed to local host, 8888 is the port and /docs, and that will be pinging our page. When you click enter, it will be running and show the loader for the task. When it finishes, it shows all the information for that specific task.
[1:12] As you can see, autocannon will show you all the information for latency, request per second, and bytes per second. Those information are really relevant and really important for application if you want to work in performance or even improve those numbers.
[1:31] As a recap, we are running autocannon using NEPX in configuring to simulate 100 connections for 30 seconds using 10 pipelines. The last parameter we'll be passing will be the address we want to check, which is localhost 8888 is the port \docs.