-3

Can someone please help? Garbage collector is not collecting these mapper objects and heap free space is not going down.

com.datastax.driver.mapping.Mapper class objects getting created in heap memory. I have given code where we are using mapper, that's only place in whole application.

enter image description here

Code:

public RawPlan retrievePrePPlan(PlanCompleteTrigger planCompleteTrigger) {
        Mapper<PrePPlan> mapper = new MappingManager(session).mapper(PrePPlan.class);

        //TODO Replace Select all with individual column names
        Select select = QueryBuilder.select().all().from(CassandraTableConstants.PRE_P_PLAN);
        select.where(QueryBuilder.eq("runuuid", planCompleteTrigger.getRunUUID()))
                .and(QueryBuilder.eq("groupid", planCompleteTrigger.getGroupId()))
                .and(QueryBuilder.eq("itemnbr", planCompleteTrigger.getItemNumber()))
                .and(QueryBuilder.eq("sl", planCompleteTrigger.getSL()));

        ResultSet resultSet = session.execute(select);
        Result<PrePPlan> prePPlans = mapper.map(resultSet);
        return new RawPlan(prePPlans.all());
    }
Alex Ott
  • 80,552
  • 8
  • 87
  • 132
amitwdh
  • 661
  • 2
  • 9
  • 19
  • Did you get `OutOfMemoryError` because of these objects or is your application operating normally? – Karol Dowbecki Feb 04 '20 at 10:37
  • @Karol Application is running for longer duration. – amitwdh Feb 04 '20 at 10:48
  • 1
    Running for long duration? Can you normally articulate the problem you have? – Eugene Feb 04 '20 at 10:53
  • @Augene We have 4GB of heap size and our application is using ~2GB heap when it runs. We have seen 7 days pattern of heap memory of application after it finish processing. Heap memory occupied is gradually increasing every day after application is done with processing. It means some objects are getting occupied in heap memory every day gradually and JVM is not able to collect those objects. After 7 days of run we saw heap memory uses reached more than ~3 GB, even when application is idle. – amitwdh Feb 05 '20 at 11:26
  • @Augene This would have cause issue if we continue to run application for some more days. We need to restart application to bring down heap memory occupied. After we took heap dump we see com.datastax.driver.mapping.Mapper class objects are getting added everyday in heap. – amitwdh Feb 05 '20 at 11:26

1 Answers1

1

You're incorrectly using the Object Mapper - you're using it only for mapping rows into POJO. You have following problem - you're building an individual CQL queries using the QueryBuilder and this lead to following problem - Cassandra needs to receive & parse every CQL statement separately - this significantly harms the performance. You can build the query with placeholders, prepare it, and then bind parameters - this should be much faster.

But in reality, you just need to use object mapper correctly - if you already have the Mapper instance, then you have following choice:

  1. Use the mapper.get, and other CRUD operations if you have full primary key
  2. Use accessors if your query may return multiple results, or you need to have custom query.

It will make your life easier as you won't need to build query - object mapper will do everything under the hood based on the POJO annotations, and then optimize query execution by preparing it, etc.

Alex Ott
  • 80,552
  • 8
  • 87
  • 132