commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "l0co (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (COLLECTIONS-469) PassiveExpiringMap performance improvemend and refreshing policy
Date Tue, 14 May 2013 19:25:15 GMT

    [ https://issues.apache.org/jira/browse/COLLECTIONS-469?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13657405#comment-13657405
] 

l0co commented on COLLECTIONS-469:
----------------------------------

No, but if you have only single youngestTimeout, you just can do:

{code}
Object get() {
  long newTimeout = Date().getTime();
  if (newTimeout < youngestTimeout) {
    youngestTimeout = newTimeout;
  }
  ...
}
{code}

That's all, no additional processing. Same for put(). You only need to recalculate timeouts
by reviewing whole map when you remove element with timeout==youngestTimeout.
                
> PassiveExpiringMap performance improvemend and refreshing policy
> ----------------------------------------------------------------
>
>                 Key: COLLECTIONS-469
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-469
>             Project: Commons Collections
>          Issue Type: New Feature
>          Components: Map
>    Affects Versions: 4.0-beta-1
>            Reporter: l0co
>            Priority: Minor
>             Fix For: 4.0
>
>
> A copy from COLLECTIONS-467.
> Two remarks about current trunk implementation of PassiveExpiringMap.
> You should additionally keep the value of the next element timeout (the youngest timeout)
in object field, so that you don't need to iterate through whole map to find elements for
expiration on each call. It improves performance by calculating only simple if for most cases:
> {code}
> public class PassiveExpiringMap {
>   long youngestTimeoutMs = 0; // assert to have next timeout time for youngest element
here always, or 0 if map is empty
>   
>   private void removeAllExpired(final long now) {
>     if (youngestTimeoutMs>0 && youngestTimeoutMs<=now) {
>       // do the cleanup
>     }
>   }
> }
> {code}
> The second remark concerns the refreshing policy. As I can see there's no refreshing
policy in current implementation, there should be at last two policies: NoRefresh (working
as the current) and RefreshOnHit - which updates element expiration time when the element
is "hit" (eg. by get()), so that the map always removes the least used resources.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message