Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Conference)

23
Performance tests in Gatling Mateusz Gruszczyński, Grand Prade [email protected]

Transcript of Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Conference)

Page 1: Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Conference)

Performance tests in GatlingMateusz Gruszczyński, Grand Prade

[email protected]

Page 2: Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Conference)

Performance Testing

● Why we should test performance?● What are performance tests?

– Performance

– Load

– Stress

– Soak

– Capacity

Page 3: Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Conference)

How to test performance

● Functional vs Non-Functional approach

● Setting goals● Good practices● Understanding architecture and

tech stack● Analyzing results

Page 4: Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Conference)

Why Gatling?

● Asynchronous● Actor model● Non blocking I/O● Simple configuration● GUI and DSL● Easy to understand code● Extendable

Page 5: Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Conference)

http://gruszczynski.pl/WSTest.zip

Page 6: Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Conference)

HTTP & REST

● Request methods– GET, POST, PUT, PATCH, DELETE ...

● Headers● HTTP Codes

– 200, 201, 400, 401, 402, 422, 500

● Session● Authentication● REST

Page 7: Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Conference)

Gatling GUI

● Works as proxy server● Allows to record requests● Generates simulation code● No coding required● Allows to replay recorded

simulations● Generates reports

Page 8: Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Conference)

http://gatling.io/

Page 9: Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Conference)

Simulation Report

● Summary and per request reports● Multiple metrics● Time distribution● Detailed statistics

Page 10: Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Conference)

Lets look at some code

● Simulations are written in Scala● Simulations use Gatling DSL to configure requests● Simulation is a set of scenarios● Generated requests are very simple● Generated code is messy● Complex logic can (should) be added to scenario

Page 11: Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Conference)

Basic Gatling DSL elements

● Requests● Checkers● Assertions● Loops● Condition Blocks● more: Cheat sheet

Page 12: Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Conference)

http://gruszczynski.pl/api.php/

Page 13: Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Conference)

Writing first request

● Setting simple GET request● Validating response code● Validation response content

– HTML response

– JSON response

● Configuring assertions and success conditions

Page 14: Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Conference)

We need more users!

● Injecting users● Injection strategies

– atOnceUsers

– rampUsers

– constantUsersPerSec

– rampUsersPerSec

– mixed strategies

● Injection strategies vs request per second

● Throttling

Page 15: Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Conference)

Gatling Session

● Storing data in session● Reusing stored data in

scenarios● Filling placeholders● Coding inside session

context (block)

Page 16: Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Conference)

Configuring request parameters

● URL– base URL

– URL params

● Headers– content type

– authorization

● Resources

Page 17: Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Conference)

Passing request data

● StringBody● RawFileBody● Constructing data based on

session

Page 18: Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Conference)

Checking response

● Status● Content

– HTML

– JSONPath

● Headers● Response Time

Page 19: Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Conference)

Writing global assertions

● Max time● Average time● Percentiles● Detail

Page 20: Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Conference)

Loops and conditions

● Conditions

– doIf ...

– doSwitch

– randomSwitch

– etc.

● Failure conditions

– tryMax

– exitBlockOnFail

– exitHereIfFailed

● Loops

– forever

– repaet

– during

– foreach

– asLongAs

Page 21: Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Conference)

Loading data to simulation

● Feeder sources– Files

● CSV ...● Json

– Remote files

– Databases● JDBC● Redis

● Feeder strategies– queue

– shuffle

– random

– circular

Page 22: Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Conference)

Advanced reporting & monitoring

● LogBack● JSON Stats● ExtraInfoExtractor● Live monitoring

– Graphite

– InfluxDB

Page 23: Mateusz Gruszczynski - Performance tests in Gatling (Quality Questions Conference)

Questions?