I try to fetch some data from mongodb , but my k8s pods hitting:
Terminating due to java.lang.OutOfMemoryError: Java heap space
Checking the heap dump this seems is causing some trouble:
try (CloseableIterator<A> iter =
mongoTemplate.stream(query(criteria),
DocumentAnnotation.class,
ANNOTATIONS_COLLECTION_NAME)) {
return StreamSupport.stream(
Spliterators.spliteratorUnknownSize(iter, Spliterator.ORDERED), false)
.filter(annotation -> isAnnotationAcceptedByFilter(annotation))
.collect(Collectors.toList());
}
In general, it creates an iterator using Mongo driver streaming API and iterates through all annotations returned by a database using given criteria. It seems that Mongo DB driver is reading annotations in bulks of 47427 items (? at least I see that in heap dump) and despite of the fact that most will be filtered by the filter in Java so not returned to the client, that is causing a problem because each such request allocates 100MB of RAM to keep this bulk.
Does anybody know if that bulk size is configurable?
Thanks