Karyo

Performance testing

Karyo 2.1.1rendered at build time
On this page

How to measure the speed of a local Karyo with the Gatling harness in tests/gatling, and what the harness refuses to do.

Derived from tests/gatling/ (the build, RunTarget, TokenSource, PerfRun and the five simulations), tests/gatling/scale/, infrastructure/keycloak/karyo-realm.json, infrastructure/keycloak/karyo-realm-prod.json, services/karyo-app/src/main/kotlin/com/karyo/app/auth/IdentityConfigurationGuard.kt, .github/workflows/ci.yml and .github/workflows/nightly.yml.

What it is

The harness is a load generator that you start by hand. It signs in as a development user, picks one Facility, and sends the same requests a console or a floor device sends, many at a time. It reports how long each request took and how many failed.

Nothing runs it for you. tests/gatling is a Gradle build of its own. The root settings.gradle.kts does not include it, so ./gradlew test, ./gradlew detekt and every job in .github/workflows/ci.yml and .github/workflows/nightly.yml never read it. No workflow starts it. This keeps the CI runners free and keeps load off a stack that nobody chose to load.

There are five simulations. Start one by its class name under com.karyo.perf.simulations.

Simulation What it sends Writes
ListEndpointsSimulation The first page of the lists the console opens first: locations, products, stock units, unit loads, delivery orders, goods receipts and pick orders No
StockLookupSimulation The reads a picker's device makes on a stock row: amount at a location, stock of an item, and the stock unit, unit load, location and product behind it No
InsightEnginesSimulation The four reads that recompute on every request: GET /api/v1/forecasts, GET /api/v1/simulations/reorder, GET /api/v1/flow/state and GET /api/v1/flow/projection No
MutationEndpointsSimulation POST /api/v1/products and POST /api/v1/locations with names unique to the run Yes
WalkthroughSimulation Per user: receive a pallet, put it away, order part of it, release, pick and pack it - thirteen requests Yes

Four load profiles say how hard a run pushes. KARYO_PERF_PROFILE picks one, and smoke is the default. A profile applies to each scenario of a simulation on its own. The figures below are for one scenario. ListEndpointsSimulation has 7 scenarios, so it pushes 7 times the load. InsightEnginesSimulation has 4 scenarios, so it pushes 4 times the load. MutationEndpointsSimulation has 2 scenarios, so it pushes twice the load. The other two simulations have one scenario each.

Profile Load Use
smoke 2 users at a time for 15 seconds Prove that the run works. Its figures mean nothing
baseline 10 users at a time for 60 seconds The repeatable figure to compare one change against another
ramp 100 new users arrive evenly over 2 minutes See where latency starts to climb
spike A trickle, then 200 new users within 10 seconds See how a burst is absorbed

What it refuses

A run that is not told where to go does not go anywhere, and it never reaches a host it was not given. RunTarget (tests/gatling/src/main/kotlin/com/karyo/perf/RunTarget.kt) enforces this before the first request, and RunTargetTest pins each rule.

  • No default host. KARYO_PERF_BASE_URL and KARYO_PERF_ISSUER_URL are required. The run stops with a message when either is unset.
  • Loopback only. localhost, 127.0.0.1 and [::1] are allowed. Any other host is refused, whatever its scheme.
  • The token endpoint obeys the same rule. The sign-in sends a password and a client secret to KARYO_PERF_ISSUER_URL, so that URL is checked as well as the API.
  • No secret in source. The user name, password and client secret come from the environment. The run never prints the password or the secret.
  • No call to Gatling's own site. Gatling's warm-up sends a request to gatling.io before the first scenario by default. KaryoProtocol switches it off.
  • Only the development realm signs in. The harness uses the password grant of the karyo-backend client. karyo-realm.json allows that grant. karyo-realm-prod.json turns it off, so a production-shaped installation cannot be signed in to this way.
  • No seeding and no reset. The harness never calls /api/v1/demo/seed or /api/v1/demo/reset. You seed the warehouse yourself, below.

The two write simulations create rows named PERF-<run>-... in the Facility you choose. Run them only against an installation that you can throw away.

Prerequisites

  • A JDK 21 with javac, as for the rest of the build.
  • A local session with the demo warehouse. Follow Boot a local session through step 3, with KARYO_DEMO=on exported for step 2, then seed the warehouse with the demo/seed call that step 5 shows. Step 3 matters: until the user is enrolled and holds grants, every call is refused action-not-granted.
  • A user who holds the actions the simulations use. The Administrator standard profile at the Company is enough. The reads need inventory.read, products.read, layout.read, orders.read, fulfillment.read and, for the insight reads, operations.view. The writes add products.write, layout.write, inventory.write, orders.write, orders.release and fulfillment.write.
  • Development mode. The built jar refuses an http issuer outside development and test (IdentityConfigurationGuard.validateIssuer), and the development realm is plain http. So the stack to measure is quarkusDev, not the production image. Its figures compare one change against another on one machine. They are not a capacity claim.

Set QUARKUS_HIBERNATE_ORM_LOG_SQL=false for the quarkusDev run. The development profile logs every statement, and that cost lands in every response time.

Run it

export KARYO_PERF_BASE_URL=http://localhost:8080
export KARYO_PERF_ISSUER_URL=http://localhost:8180/realms/karyo
export KARYO_PERF_USERNAME=admin
export KARYO_PERF_PASSWORD=admin
export KARYO_PERF_CLIENT_SECRET=dev-backend-secret
export KARYO_PERF_FACILITY=RIVERSIDE     # a code or an id; needed when the user reaches several

./gradlew -p tests/gatling gatlingRun --simulation=com.karyo.perf.simulations.ListEndpointsSimulation
KARYO_PERF_PROFILE=baseline \
  ./gradlew -p tests/gatling gatlingRun --simulation=com.karyo.perf.simulations.WalkthroughSimulation

The user name, password and secret above are the public development fixtures in infrastructure/keycloak/karyo-realm.json. They work only after step 3 has enrolled and granted that user. The issuer is the Keycloak of the same session, on port 8180.

All the settings:

Variable Meaning
KARYO_PERF_BASE_URL Required. The origin of the application, written in canonical form: http://localhost:8080, not http://localhost:8080/ plus a path
KARYO_PERF_ISSUER_URL Required. The development realm URL, for example http://localhost:8180/realms/karyo
KARYO_PERF_USERNAME, KARYO_PERF_PASSWORD Required. A development realm user
KARYO_PERF_CLIENT_SECRET Required. The secret of the karyo-backend client, which is the client the harness always uses
KARYO_PERF_FACILITY The Facility code or id. Required when the user reaches more than one
KARYO_PERF_PROFILE smoke (default), baseline, ramp or spike

A run ends with the request counts, the response-time percentiles and a path to an HTML report under tests/gatling/build/reports/gatling/. Each simulation asserts that no request failed, so the Gradle task exits non-zero on the first failure. A run with failures is not a measurement.

Always start gatlingRun with --simulation. Without it, the task asks which simulation to run. The --all flag runs every simulation one after another, writes included.

To undo most of what a write run left, call POST /api/v1/demo/reset. It clears the operational data of every Business Unit, so it is for a disposable installation only. It keeps unit load types, so each Mutation or Walkthrough run leaves one PERF-<run>-ULT unit load type behind.

The guard has unit tests that need no stack: ./gradlew -p tests/gatling test.

Taking a baseline

A figure is only worth keeping if the next run can repeat the conditions.

  1. Start from a fresh seed. Reset and seed the demo warehouse, and say which seed a figure came from. Detectors need a few minutes after a seed before their alerts appear, so wait before you measure.
  2. Use an idle machine, the same quarkusDev settings and the same profile every time.
  3. Run baseline for each simulation at least three times and compare the medians.
  4. Write down the commit, the machine, the seed and, for each simulation, the request count, the 50th, 95th and 99th percentiles and the failure count.

The harness keeps no baseline. Where you record the figures is your choice.

Measuring how the engines grow

InsightEnginesSimulation is a measuring tool before it is a load test. The four reads it sends compute their answer from the rows on every request, cache nothing and page nothing, so what they cost depends on how much history the Facility holds. A figure without the size of the data beside it means nothing. The demo warehouse is small: on a fresh seed each route answers in about 10 to 20 milliseconds.

To measure a larger warehouse, repeat the demo Facility's history on a disposable installation:

  1. Seed the demo warehouse, as in the prerequisites, and note its Facility id. POST /api/v1/demo/seed prints the ids in its tree.
  2. Add copies of the history with tests/gatling/scale/repeat-demo-history.sql. Run it once for each copy, with copy set to 1, 2, 3 and so on: psql -v ON_ERROR_STOP=1 -v facility=<id> -v copy=1 -f tests/gatling/scale/repeat-demo-history.sql. The copies are dated as the originals, so the 90-day and 28-day windows the engines read grow in proportion. A copy's picks carry its own product numbers, so each copy also adds products to the forecast.
  3. Run VACUUM ANALYZE and send each route a few times by hand before measuring, to leave out the cold start. Then run the simulation, or time single requests.
  4. Take the size of the data from the database: the products picked in the last 90 days, the pick rows in the last 90 days and the delivery orders of the Facility.
  5. Undo the copies with tests/gatling/scale/undo-repeat-demo-history.sql, or reset the installation.

The smoke profile sends two requests at a time to each route. For a figure that says what one caller waits, time single requests after two warm-up requests and take the median. The ceilings in the HTTP API surface and in the flow model were taken this way.

Known limits

  • Two users moving stock through one location can fail with HTTP 409. A move recalculates the allocation of each location it touches and writes that location's row. The only writer is LocationService.setAllocationFromEntries (services/warehouse-layout-service/karyo-layout-core/src/main/kotlin/com/karyo/layout/service/LocationService.kt). The row carries a version check, so when two requests change it at once the second fails with an OptimisticLockException and the caller receives a 409 concurrent-change and must retry. A putaway from one shared receiving location and a dispatch into the Facility's ship-staging area, whose few locations every user shares, both fail this way at two concurrent users. This is why WalkthroughSimulation gives each user receiving and storage bins of its own, and why it stops at PACKED, before dispatch. It is a limit of the application the harness found, not a flaw of the harness.
  • There is no stock-selection request to measure. The archived harness measured GET /api/v1/stock-units/select. That endpoint no longer exists, because selection runs inside the release to picking. StockLookupSimulation measures the lookups that remain.
  • One Facility per run. The harness works in the Facility that KARYO_PERF_FACILITY names.

Changing the harness

File under tests/gatling/ Holds
settings.gradle.kts, build.gradle.kts The standalone build. It reads the Gatling and Kotlin versions from gradle/libs.versions.toml
src/main/kotlin/com/karyo/perf/RunTarget.kt Every environment setting and every refusal. Change a rule here and in RunTargetTest
src/main/kotlin/com/karyo/perf/TokenSource.kt Sign-in, and the replacement of a token before it expires
src/main/kotlin/com/karyo/perf/PerfRun.kt The Facility, the rows the reads draw from, and the master data the writes create
src/gatling/kotlin/com/karyo/perf/config/ The shared HTTP protocol, the load profiles and the sequence feeder
src/gatling/kotlin/com/karyo/perf/simulations/ The five simulations
scale/ SQL that repeats a Facility's history to measure a bigger warehouse; no workflow runs it

A new simulation takes its target from PerfRun.target, its protocol from KaryoProtocol, its injection from LoadProfile.inject and ends with an assertion on failed requests. It needs a /api/v1 path that exists, so check the path against the resource before you add it.