It will also automatically import realm "perf-realm" into Keycloak from file src/main/resources/perfrealm.json
Note that by default it will use in-memory H2 database, which means that all changes (for example all added users) are discarded after server restart. For performance testing, it's recommended to use some database like PostgreSQL or MySQL
To run server with PostgreSQL you may use command like this (change host,port,dbName and credentials according your DB configuration):
Performance test is using users with prefix "user" (so users like "user-0", "user-1", ... , "user-123456" etc). So you first need to add some of these users into your database.
For adding 10000 new users into your database (will start from last added user, so you don't need to explicitly check how many users to create are needed:
Note that with default H2 are all data automatically cleared after server restart. So it's recommended to use different DB like PostgreSQL or Mongo.
Execute performance test
------------------------
When server is started and some users are created, you can run performance test. It's possible to run it from Command line with:
```shell
mvn verify -Pperformance-test
````
By default, test is using Keycloak on localhost:8081 and 50 concurrent clients (threads) and each client doing 50 test iterations. Each iterations is:
- Login user into KC and retrieve code
- Exchange code for accessToken
- Refresh token 2 times
- Logout user
Each client is using separate username, so actually you need at least 50 users created into your DB (users "user-0", "user-1", ... "user-49" . See above)
ATM it's possible to adjust behaviour with properties:
* host --- Keycloak host ("localhost" by default)
* port --- Keycloak port ("8081" by default)
* userPrefix --- prefix of users ("user" by default)
* concurrentUsers --- Number of concurrent clients (50 by default). RampUp time is configured to start 5 new users each second, so with 50 users are all clients started in like 10 seconds.
* iterationsPerUser --- Number of iterations per each client (50 by default). So by default we have 50*50 = 2500 iterations in total per whole test
* refreshTokenRequestsPerIteration --- Number of refresh token iterations (2 by default)
You can change configuration by adding some properties into command line for example to start just with 10 concurrent clients and 10 iterations per client (so just 100 test iterations) you can use:
and then open file src/test/jmeter/keycloak_web_perf_test.jmx and trigger test from JMeter GUI. It may be good as you can see the progress of whole test during execution.