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

Post on 15-Apr-2017

134 views 2 download

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

Performance tests in GatlingMateusz Gruszczyński, Grand Prade

mateusz.gruszczynski@grandparade.co.uk

Performance Testing

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

– Performance

– Load

– Stress

– Soak

– Capacity

How to test performance

● Functional vs Non-Functional approach

● Setting goals● Good practices● Understanding architecture and

tech stack● Analyzing results

Why Gatling?

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

http://gruszczynski.pl/WSTest.zip

HTTP & REST

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

● Headers● HTTP Codes

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

● Session● Authentication● REST

Gatling GUI

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

simulations● Generates reports

http://gatling.io/

Simulation Report

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

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

Basic Gatling DSL elements

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

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

Writing first request

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

– HTML response

– JSON response

● Configuring assertions and success conditions

We need more users!

● Injecting users● Injection strategies

– atOnceUsers

– rampUsers

– constantUsersPerSec

– rampUsersPerSec

– mixed strategies

● Injection strategies vs request per second

● Throttling

Gatling Session

● Storing data in session● Reusing stored data in

scenarios● Filling placeholders● Coding inside session

context (block)

Configuring request parameters

● URL– base URL

– URL params

● Headers– content type

– authorization

● Resources

Passing request data

● StringBody● RawFileBody● Constructing data based on

session

Checking response

● Status● Content

– HTML

– JSONPath

● Headers● Response Time

Writing global assertions

● Max time● Average time● Percentiles● Detail

Loops and conditions

● Conditions

– doIf ...

– doSwitch

– randomSwitch

– etc.

● Failure conditions

– tryMax

– exitBlockOnFail

– exitHereIfFailed

● Loops

– forever

– repaet

– during

– foreach

– asLongAs

Loading data to simulation

● Feeder sources– Files

● CSV ...● Json

– Remote files

– Databases● JDBC● Redis

● Feeder strategies– queue

– shuffle

– random

– circular

Advanced reporting & monitoring

● LogBack● JSON Stats● ExtraInfoExtractor● Live monitoring

– Graphite

– InfluxDB

Questions?