jpmml / jpmml-evaluator

Java Evaluator API for PMML
GNU Affero General Public License v3.0
892 stars 255 forks source link

LoadingCache maybe lead to OOM,Does the jpmml support scene of Model Iteration? #47

Closed yeying1993 closed 3 years ago

yeying1993 commented 7 years ago

Hi,I have got a problem,my scene is Model iteration by every day,but the framework of jpmml use LoadingCache as cache, that has a characteristics of delaying to delete.so jpmml leads to jvm memory is very big, even OOM. The solution : At the same time using weakKeys() and weakValues():

private static LoadingCache<MiningModel, BiMap<String, Segment>> entityCache = CacheUtil.buildLoadingCache(new CacheLoader<MiningModel, BiMap<String, Segment>>(){

        @Override
        public BiMap<String, Segment> load(MiningModel miningModel){
            Segmentation segmentation = miningModel.getSegmentation();

            return EntityUtil.buildBiMap(segmentation.getSegments());
        }
    });
vruusmann commented 7 years ago

Are you trying to completely replace the yesterday's ("old") model with a today's ("new") model?

Guava Caches should purge unused keys/values automatically when the memory starts to run low. Cache keys are typically subclasses of org.dmg.pmml.PMMLObject, whereas cache values are typically something else. Looks like entity registry caches violate that convention, because the cache value is a BiMap<String, subclass of org.dmg.pmml.PMMLObject>, which may prevent purging.

Will have to analyze what other caches may be affected. Definitely don't want to make weakValues() the default policy all of a sudden.

You can set a custom Cache policy for your application using the org.jpmml.evaluator.CacheUtil#setCacheBuilderSpec(CacheBuilderSpec) utility method. Something like this should do:

class MyPMMLApplication {
  static {
    CacheUtil.setCacheBuilderSpec(CacheBuilderSpec.parse("weakKeys,weakValues"));
  }
}
yeying1993 commented 7 years ago

OK,thank you very much