Stress Test with Gatling

Test is a very important part of software development. Everybody agree and some people(sadly not everybody yet) do lots of unit testing, some do integration tests other do some kind of UI testing as well.

But thats not enought you are into SOA/microservice land. As much as you distribute your software you have way more wants to fail. Tests need to catch up, Stress test are something that unfortunately people dont do - sometimes they do but when they know that there is a scalability problem witch is sad.

This practice of stress tests could be automated(it really should) or at least make sure you run periodically as far as i know Netflix does 2-3 times per week - because this is not just about scalability. Stress Tests are bigger than just how many users can i handle.

What Stress Tests are about? 

First of all i will not try to make difference of terms, like is load tests of stress tests, call it however you want i dont think the name matters much. So for sure stress tests let you know how much you can scala and thats not only for Web Scalae business but for your company too. Stress Tests can review a serious of problems that you might not them at all like:
   * Services can hide Bottlenecks - Could be ground for optimization
   * Services can have race conditions - Could be bad coding practices
   * Services can not recover on failure - Could be just hanging forever
   * Service maybe get affected by dependencies - a.k.a other service not functining well.
   * Services could be hiding other botlenecks like databases, messaing systems, datagrids or even infrastructure issues.

The list goes on and on and thats i just Stress Testing not to mention Chaos testing. Like introducing network faliures, drop packages, issues with ack, hanging, os issues like permissions, sicurity groups or firewall issues, lack of oss problem tunning to handle more threads and sockets, etc...

Why Gatling?

Gatling( is a great tool. I worked a lot with Jmeter and the problem with jmeter to me is that besides the fact is old is that JMeter is very hard to use it - They UI is a mess and confusing. The XML is not the best structure to code your tests and is not clear what are the things you are doing. Gatling however get all this things right IMHO. So no XML at all you have Scala DSL witch is simple and easy to read and understand what are you doing. Gatling is REST native so is so, so, so easy to test REST services. Gatling have good documentation and in the end of the day is scala code so you can add whatever do you need.

What i really like in Gatling besides the simplicity is the LATENCY orientation, reports are pretty much around latency so you know how fast your service is responding or not and i really appreciate that vision.

Gatling is not so great(at least today) when we talk about high scales, they clustering is not there yet and you need do things by yourself and no hel with the aggregation but for lots of scenarios is a great tool and can help you alot.

Having some Fun

So you need download Gatling from here() and them you just need code your scripts at Gatling: $GATLING_HOME/user-files/simulations/ and them you can place your scala code there. Here is a sample.

For this script we are calling the open weather REST service,uk querying for London. We are checking the http status code so see if is 200 and this call should not take more than 1 second otherwise the test will fail. For this test we have 30 active users, that means 30 threads hammering for 60 seconds.

ÍF you run $GATLING_HOME/bin/gatling.bat

Gatling will list all stress tests scripts you have - them you just pick the one you want run and wait for it. The results come in 2 flavors a summary and a HTML report like this.

There is a Jenkins plugins I recommend you create a separate job so this dont delay your build - whats even better is have a dedicated replica with a dedicated environment just todo stress tests.

Have Fun :-)

Diego Pacheco

Popular posts from this blog

Kafka Streams with Java 15

Rust and Java Interoperability

HMAC in Java