src/main/java/org/deduplogger/logger/LogCache.java
/*
   * if cache memory usage exceeds the allocated limit, flush some messages to reduce memory consumption to 50%
   */
if cache memory usage exceeds the allocated limit, flush some messages to reduce memory consumption to 50%
if cache memory usage exceeds the allocated limit flush some messages to reduce memory consumption to 50%
private List<String> flushMessageIfOutOfMemory(List<String> evictionMessages) {
    if (PQ_MEMORY_USAGE + LRU_MEMORY_USAGE >= MEMORY_LIMIT) {
      int targetSize = pq.size() / 2;
      String msg;
      Iterator<Entry<String, Long>> itr = pq.entrySet().iterator();
      while (pq.size() > 0 && pq.size() > targetSize) {
        Map.Entry<String, Long> e = itr.next();
        msg = e.getKey();
        PQ_MEMORY_USAGE = PQ_MEMORY_USAGE - calculateStringSize(msg) - LONG_SIZE;
        LRU_MEMORY_USAGE = LRU_MEMORY_USAGE - calculateStringSize(msg) - cache.get(msg).getTimeStamp().size() * LONG_SIZE;
        LogMetadata metadata = cache.get(msg);
        if (metadata.getTimeStamp().size() > LOG_CACHE_THRESHOLD) {
          evictionMessages.add(generateSingleEvictionSummary(msg, MESSAGE.MEMORY_EVICTION.toString(), metadata));
        }
        cache.remove(msg);
        itr.remove();
      }
    }
    return evictionMessages;
  }
private List < String > flushMessageIfOutOfMemory ( List < String > evictionMessages ) { if ( PQ_MEMORY_USAGE + LRU_MEMORY_USAGE >= MEMORY_LIMIT ) { int targetSize = pq . size ( ) / 2 ; String msg ; Iterator < Entry < String , Long > > itr = pq . entrySet ( ) . iterator ( ) ; while ( pq . size ( ) > 0 && pq . size ( ) > targetSize ) { Map . Entry < String , Long > e = itr . next ( ) ; msg = e . getKey ( ) ; PQ_MEMORY_USAGE = PQ_MEMORY_USAGE - calculateStringSize ( msg ) - LONG_SIZE ; LRU_MEMORY_USAGE = LRU_MEMORY_USAGE - calculateStringSize ( msg ) - cache . get ( msg ) . getTimeStamp ( ) . size ( ) * LONG_SIZE ; LogMetadata metadata = cache . get ( msg ) ; if ( metadata . getTimeStamp ( ) . size ( ) > LOG_CACHE_THRESHOLD ) { evictionMessages . add ( generateSingleEvictionSummary ( msg , MESSAGE . MEMORY_EVICTION . toString ( ) , metadata ) ) ; } cache . remove ( msg ) ; itr . remove ( ) ; } } return evictionMessages ; }
if cache memory usage exceeds the allocated limit, flush some messages to reduce memory consumption to 50%
if cache memory usage exceeds the allocated limit flush some messages to reduce memory consumption to 50%
//      System.out.printf("Reach Memory Limit, Starting to flush the messages LRU : %d kb, PQ : %d kb\n", //                              LRU_MEMORY_USAGE / 1024, PQ_MEMORY_USAGE / 1024); // Update the memory counter for LRU and cache // Remove from cache and pq