Performance Testing with K6 – NewsClicks24

Spread the love

Stay on Top of Enterprise Technology Trends

Get refreshes affecting your industry from our NewsClicks24 Research Community

Join the Community!

The issue isn’t that trying is the bottleneck. The issue is that you don’t have a clue what’s in the container. That is a difficult that testing addresses.

— Michael Bolton, creator, “Quick Software Testing.”

You will not discover a ton of specialists out there who say they get amped up for testing. Quality confirmation (QA) is the sort of unglamorous errand that engineers frequently approach with hesitance—like leg day at the rec center. In any case, pardon me on the off chance that I wax energetic about k6, the presentation testing bundle that is the furthest down the line expansion to my utility belt. K6 is an advanced open-source testing apparatus written in Go. In any case, it gives JavaScript libraries to compose experiments, so architects and analyzers can utilize the k6 libraries to test their APIs and applications.

In this blog entry, I investigate what I have gained from my short meeting with k6, which is said to make load testing as simple as unit testing. Furthermore, I am satisfied to report that I am altogether getting a charge out of it! Here I’ll portray my experience with the apparatus as a feature of an application modernization project, itemizing what I realized and the means I brought the way.


In the a few quarters, my group was chipping away at a venture to decay an inheritance stone monument administration. Our objective was to supplant it by growing new miniature/small scale RESTFul web administrations. Due to the everyday help overhead, execution issues, and challenges conveying any adjustment underway rapidly, we settled on an essential choice to part the inheritance project. One MySQL information base was supporting the three unique administrations and numerous MapReduce preparing occupations, making a solitary purpose of disappointment for a few products.

My group and I began with the littlest and autonomous API assets to break down them from the stone monument. After altogether investigating all the pieces, we began dealing with our pattern plan and rolled out essential improvements in the inside APIs plan while ensuring that all the highlights of our public APIs stayed latent. Before long our new help was ready.

The fundamental difficulties to address in front of sending were:

  • Conduct detachment check
  • Improve execution and execution measurement
  • Reduce upkeep and backing overhead
  • Estimate asset use for cost optimization
  • Plan delivery to creation with practically no downtime

Why K6?

“Write a heap test like a unit test.” It’s an expression from k6’s site that promptly caught my eye when I investigated the apparatus after an associate acquainted me with it. I began perusing the documentation and the primary thing that I enjoyed was that I can utilize JavaScript to compose a presentation test. It was a triumphant second for me being a Java engineer—I definitely realized how to compose JavaScript.

I utilized Home Brew to introduce the k6 libraries on my MacBook and was good to go in under a moment. (Figure 1)

Figure 1. Homemade libation Install

As a Java designer, the expectation to learn and adapt is delicate, and I found the k6 documentation both strong and elegantly composed. I had the option to blast out my first unit test in only a couple minutes and to later upgrade the code to stack test the assistance. It was unexplainable adoration. Far and away superior, k6 isn’t a program based utility—I could run the test on an order line instrument with a straightforward one-line command.

I have utilized other testing devices like Apache Benchmark, Jmeter, Gatling, and Postman, however k6 surpasses them all with its simplicity of composing work processes utilizing different activities given by an assistance. Adding field approvals, attesting yields, producing dynamic dataset, and troubleshooting the tests were all moreover extremely simple contrasted with different devices I have utilized in the past.

My First K6 Test

I composed two JavaScript capacities and my first burden test was prepared, as so:

Figure 2. First Load Test

Note that I skirted different pieces of my test to zero in on the significant subtleties and show the simplicity of composing a test.

Now to run the test, I utilized k6 choices to call a GET/Consumers API and run 10 cycles for 10 virtual clients. I utilized the check work given by the k6 library to attest the reaction HTTP code. For more accessible choices, kindly allude to k6 Options.

Figure 3. Running the Test

The rundown gave by k6 is simple, we can perceive the number of solicitations k6 created, the achievement demand rate, and numerous other significant measurements. The outcome rundown resembles this (Figure 4):

Figure 4. The Result Summary

For more insights regarding every measurement if it’s not too much trouble, check Metrics. This asset additionally shows numerous other yield measurements dependent on your test configuration.

I utilized k6 and its highlights to work through with the difficulties referenced previously. After some time I had the option to build the level and intricacy of testing, as follows:

  • For the detachment check, I attested the API reaction under different burden conditions and by utilizing all realized workflows.
  • I have utilized k6 while neighborhood, dev, and QA climate to perform unit and burden testing. Subsequent to running the presentation test utilizing k6, I utilized NewRelic to analyze the exhibition of heritage and new administrations by taking care of the help logs to it. I introduced the when execution correlation with all the partners utilizing the service.
  • Because I can powerfully produce the test information utilizing JavaScript capacities and classes, I utilized the heap test to make creation level traffic in our organizing climate during the organization of more current curios. That not just assisted me with seeing whether we will confront difficulties during our item conveyance, however it additionally let me better arrangement the conveyance plan. We had the option to screen framework execution and maintain a strategic distance from a minute ago arrangement time shocks. I utilized Github to source control my testing code.
  • I ran a k6 test with a heavier burden than our creation traffic to recognize the assets that we should run the assistance viably and proficiently. I utilized the Grafana dashboard to create a report of asset use and cost to run the service.
  • I archived the courses of events expected to reveal the progressions to creation by running different test situations. This assisted me with conveying the arrangement to all the stakeholders.
  • After creation sending and prior to empowering the support of end-clients, I had the option to run my test underway without influencing different organizations. This permitted me to test the accuracy of the product and tidy up the test information toward the finish of the testing cycle.

K6 incorporates with many test perception instruments, however I still can’t seem to investigate them as my k6 venture has recently begun. Truth be told, that is my greatest grumbling. In contrast to Gatling, k6 comes up short on a graphical outcome synopsis that doesn’t need an outsider integration.


Overall, k6 has caused me up my game in presentation testing—it turns out I had nothing to stress over! I had the option to get the accompanying professional tips, which caused me during my journey:

  • Use climate factors to make your test powerfully acknowledge Dev/Staging/Prod Configs, if there are any.
  • If you need to run long-running tests, remember to utilize the Duration alternative by utilizing a climate variable (K6_DURATION) or CLI param (– span/ – d) or automatically in your JavaScript file.
  • If k6 can’t connect with your API running behind an intermediary worker, send out the HTTP_PROXY choice prior to running the test, as demonstrated in Figure 5:

Figure 5. Sending out the HTTP_Proxy Option

Finally, I realized there isn’t anything to stop me, as a designer, from embracing testing devices that can speed me up simultaneously they assist me with conveying better results.

References: k6: Load Testing for Engineering Teams

About The Author

Shradha Khard is an Associate Lead Software Engineer at Cerner Corporation. An industry chief cloud evangelist who is client fixated, item engaged, and thorough, Khard is energetic about work environment correspondence and ladies’ development in the IT area. Her most valuable belongings are her two daughters.

Read More Interesting Here : News Clicks 24