i'm using Keycloak as Identity Manager for the solution i'm working on and in the last months i started experiencing periodically an out of memory error after aproximatly two weeks.
Uncaught server error: java.lang.OutOfMemoryError:Java heap space
I tried different version of keycloak from 13 to 15 but it doesnt seem to make any difference. I started investigating in a docker environment where i only run keycloak and postgres and leave everything idle.
This is the docker-compose.yml file i used to setup the environment:
version: '3'
services:
postgres:
image: postgres:14.1
environment:
POSTGRES_DB: keycloak
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
keycloak:
image: jboss/keycloak:15.1.0
environment:
DB_VENDOR: POSTGRES
DB_ADDR: postgres
DB_DATABASE: keycloak
DB_USER: postgres
DB_SCHEMA: public
DB_PASSWORD: password
KEYCLOAK_USER: admin
KEYCLOAK_PASSWORD: password
ports:
- 8080:8080
depends_on:
- postgres
In the meantime i also launched a standalone container of Keycloak not persisting on Postgres.
I left the containers idle and started monitoring the memory required by Keycloak, these are the results:
Time | Keycloak + Postgres | Keycloak |
---|---|---|
11:50 | 630 MB | 640 MB |
11:55 | 630.1 MB | 645 MB |
12:00 | 630.2 MB | 646.5 MB |
12:10 | 630.3 MB | 653 MB |
12:30 | 630.6 MB | 654.5 MB |
12:40 | 630.7 MB | 655.1 MB |
14:30 | 631 MB | 655.5 MB |
I know the "leak" is almost inconsistent... any ideas on how i could verify if this is actually a leak and in case it is if it is responsible for keycloak out of memory error after weeks of execution? Anyway thanks for your help.
UPDATE
As suggested i modified docker compose file specifying memory reservation and limit for keycloak and postgres services as follows:
version: '3'
services:
postgres:
image: postgres:14.1
environment:
POSTGRES_DB: keycloak
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
deploy:
resources:
limits:
memory: 2G
reservations:
memory: 1G
keycloak:
image: jboss/keycloak:15.1.0
environment:
DB_VENDOR: POSTGRES
DB_ADDR: postgres
DB_DATABASE: keycloak
DB_USER: postgres
DB_SCHEMA: public
DB_PASSWORD: password
KEYCLOAK_USER: admin
KEYCLOAK_PASSWORD: password
ports:
- 8080:8080
depends_on:
- postgres
deploy:
resources:
limits:
memory: 1G
reservations:
memory: 650M
To monitor memory usage i used docker stats
command, with system in idle the memory usage of keycloak container keeps slightly growing over time.