https://bz.apache.org/bugzilla/show_bug.cgi?id=64415

--- Comment #8 from Christopher Schultz <ch...@christopherschultz.net> ---
The only other solution I can see is to scan the map values looking for the
"oldest" one and evict a maximum of one per scan. Make sure not to evict
anything which has changed since the beginning of the scan. Keep scanning until
you have a small enough map.

Pseudocode:

while(queries.size() > maxQueries) {
  QueryStats oldest = null;
  long timestamp = Long.MAX_VALUE;
  for(QueryStats qs : queries.values()) {
    if(qs.lastInvocation < timestamp) {
      timestamp = qs.lastInvocation;
      oldest = qs;
    }
  }

  if(null != qs && timestamp == qs.lastInvocation) {
    queries.remove(qs.query);
  }
}

So you replace a List-creation, possible 1000 temporary objects (the
MiniQueryStats), and a trip through Collections.sort() with zero
object-creations but a bunch of iterations over the collection.

It's probably more efficient to have multiple iterations and not do any of hat
object-create stuff.

I'm guessing that the common case is 1-2 evictions. You don't need to actually
*sort* the whole 1000-item list just to find the one with the oldest
'lastInvocation'.

If you really wanted to instrument the process and see how many evictions are
common, you could even "unroll" the loop a bit by storing not just a single
"oldest" and "timestamp" but *N* oldest/last-timestamp pairs and then evict
them all at once.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to