Marcin-Pankowski opened a new issue, #2427:
URL: https://github.com/apache/incubator-kie-issues/issues/2427
**Describe the bug**
`KafkaProcessInstances` (Quarkus Kafka persistence addon) opens a RocksDB
iterator via `ReadOnlyKeyValueStore.prefixScan(...)` in `clearEventTypes(...)`
and `waitingForEventType(...)` and never closes it. `clearEventTypes` runs for
every created, updated and finished process instance, so every instance leaves
an open iterator behind. Open RocksDB iterators pin native memory outside the
Java heap, so the process grows until the container is killed.
File:
`kogito-quarkus/addons/persistence/kafka/runtime/src/main/java/org/kie/kogito/persistence/kafka/KafkaProcessInstances.java`
(now in `incubator-kie-drools`, unchanged since 2025-05-29; same code in
Kogito 10.2.0).
```java
KeyValueIterator<String, byte[]> iterator = getStore().prefixScan("events-"
+ getProcess().id(), Serdes.String().serializer());
if (!iterator.hasNext()) {
return new HashSet<>();
}
KeyValue<String, byte[]> entry = iterator.next();
// iterator is never closed
```
`stream(...)` in the same class already closes its iterator via
`onClose(iterator::close)`; the two methods above do not.
**How to reproduce**
Kogito 10.2.0 on Quarkus with `kie-addons-quarkus-persistence-kafka`, a
short process started via REST (three script tasks, ends immediately), constant
load with k6. Pod limited to 1 CPU / 2 GB.
**Measured impact** (same pod, run directly one after another, original
class vs. class with closed iterators):
| Concurrent users | Original | Pod memory | With fix | Pod memory |
|---:|---:|---:|---:|---:|
| 10 | 68/s · p95 169 ms | 274 MiB | 66/s · p95 169 ms | 218 MiB |
| 25 | 298/s · p95 106 ms | 873 MiB | 328/s · p95 94 ms | 239 MiB |
| 50 | 489/s · p95 129 ms | 1,620 MiB | 581/s · p95 103 ms | 271 MiB |
| 100 | 25/s · p95 5,603 ms, pod **OOMKilled** and restarted | 306 MiB
(after restart) | 571/s · p95 219 ms | 322 MiB |
With the fix, memory stays flat; the same holds for the GraalVM native image.
**Expected behavior**
Iterators are closed after reading the single `events-<processId>` entry,
memory stays flat under load.
**Proposed fix**
Wrap both `prefixScan` calls in try-with-resources and read the value inside
the block (PR follows).
**Environment**
Kogito 10.2.0, Quarkus 3.27.2, Java 21 (JVM and Mandrel native),
Kafka-compatible broker (Kafgres 0.3.1), k3d on Apple M1 Max.
**More details**
Found while benchmarking BPMN engines; full setup, raw numbers and the
patched class:
https://github.com/Marcin-Pankowski/camunda7-alternatives-benchmark
Video (English, the finding is in chapter "What we found along the way" at
9:40): https://youtu.be/-7zLxZNt198?t=580
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]