I have a spring boot rest api with a POST endpoint. This is a write heavy endpoint which does 10-15 entries into 2-4 tables (business requirement). So I created a docker-compose.yml for load/stress testing the application using Gatling. I made 2 instances of Postgres, one is master and one is replica. Now to load test the api I assigned different cpu and memory to the service. Below are the results.
-
For 1 cpu and 1024MB memory: The api works best with 70 constant request per second. All requests are under 800ms (Gatling graph) with minimum 15ms and max 75ms response time. The DB cpu goes to 40% while the api cpu utilisation goes upto 105%. Memory usage is 800MB. If I increase the req/sec I start getting letancy.
-
For 2/3/4 cpu and 1024MB memory: cpu utilisation goes to 200/300/400% respectivly and still the 70req/sec is the best the server can handle. If I increase req/sec the same latency comes. DB and memory utilisation is same.
So my question is, shouldn’t I get better results with more cpu? Why my throughput is always 70req/sec irrespective of the number the CPUs I provide?
Spring boot version: 3.2.5
OS: MacOs, 32Gb, 10 cpu core
docker-compose.yml
version: "3.9"
x-postgres-common:
&postgres-common
image: postgres:13
restart: always
user: postgres
services:
postgres_primary:
<<: *postgres-common
ports:
- "5440:5432"
environment:
POSTGRES_USER: user
POSTGRES_DB: cdfsegbdb
POSTGRES_PASSWORD: password
POSTGRES_HOST_AUTH_METHOD: "scram-sha-256nhost replication all 0.0.0.0/0 md5"
POSTGRES_INITDB_ARGS: "--auth-host=scram-sha-256"
command: |
postgres
-c wal_level=replica
-c hot_standby=on
-c max_wal_senders=10
-c max_replication_slots=10
-c hot_standby_feedback=on
volumes:
- ./src/test/resources/db/init.sql:/docker-entrypoint-initdb.d/00_init.sql
networks:
- cdfs-network
postgres_replica:
<<: *postgres-common
ports:
- "5441:5432"
environment:
POSTGRES_USER: user
POSTGRES_DB: cdfsegbdb
POSTGRES_PASSWORD: password
PGUSER: replicator
PGPASSWORD: replicator_password
command: |
bash -c "
rm -rf /var/lib/postgresql/data/*
until pg_basebackup --pgdata=/var/lib/postgresql/data -R --slot=replication_slot --host=cdfs_postgres_primary --port=5432;
do
echo 'Waiting for primary to connect...'
sleep 1s
done
echo 'Backup done, starting replica...'
chmod 0700 /var/lib/postgresql/data
postgres
"
depends_on:
- postgres_primary
my-api-service:
image: my-api:latest
ports:
- "8080:8080"
depends_on:
- postgres_primary
- postgres_replica
deploy:
resources:
limits:
cpus: 4
memory: 2048M
reservations:
cpus: 4
memory: 2048M
The Coder is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3