-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
In our project, we are using the ReactiveCrudRepository (ReactiveElasticsearchRepositor) with elastic search documents to load data from elastic. We have found the problem of memory leak (metaspace) in our project. The reason is that the class loader loads a class per every request because the map "entityInstantiators" in class "ClassGeneratingEntityInstantiator" is empty for every request. I have noticed that in the "MappingElasticsearchConverter" class is created a new Reader, so there is a new object that's the reason why the map in "ClassGeneratingEntityInstantiator" is empty. When I have pulled your repository and change Reader to singleton the map of instantiator is right and the memory leak is no more present. I did not notice that Reader holds some context that has to be removed. The question is why the Reader is created per request, might it be a singleton?
ClassGeneratingEntityInstantiator:
public <T, E extends PersistentEntity<? extends T, P>, P extends PersistentProperty
> T createInstance(E entity,
ParameterValueProvider
provider) {
EntityInstantiator instantiator = this.entityInstantiators.get(entity.getTypeInformation());
if (instantiator == null) {
instantiator = potentiallyCreateAndRegisterEntityInstantiator(entity);
}
return instantiator.createInstance(entity, provider);
}
MappingElasticsearchConverter:
public R read(Class type, Document source) {
Reader reader = new Reader(mappingContext, conversionService, getConversions());
return reader.read(type, source);
}