Weigher performance requirements

8 views
Skip to first unread message

Jonathan Ellis

unread,
Apr 6, 2011, 3:06:14 PM4/6/11
to ConcurrentLinkedHashMap
How frequently does weightOf get called?

Does CLHM assume that the weight of a value stays constant, once
weighed?

I am thinking of using https://github.com/jbellis/jamm to allow sizing
Cassandra caches in bytes instead of entries, but that's a relatively
expensive operation compared to the built-in Weigher implementations.

Ben Manes

unread,
Apr 6, 2011, 3:15:26 PM4/6/11
to ConcurrentLinkedHashMap
It is assumed that the weight remains constant. It is evaluated on the
entry's insertion/update and stored with the entry.

I tried to hint at this without being too verbose in the JavaDoc (I'm
open to any suggested changes to clarify it):
"A change to a value that modifies its weight requires that an update
operation is performed on the map."

On Apr 6, 12:06 pm, Jonathan Ellis <jbel...@gmail.com> wrote:
> How frequently does weightOf get called?
>
> Does CLHM assume that the weight of a value stays constant, once
> weighed?
>
> I am thinking of usinghttps://github.com/jbellis/jammto allow sizing

Jonathan Ellis

unread,
Apr 6, 2011, 3:35:39 PM4/6/11
to ConcurrentLinkedHashMap
Sounds good. Does it matter whether you use put or replace, when
performing an update-for-weight-change?

On Apr 6, 2:15 pm, Ben Manes <ben.ma...@gmail.com> wrote:
> It is assumed that the weight remains constant. It is evaluated on the
> entry's insertion/update and stored with the entry.
>
> I tried to hint at this without being too verbose in the JavaDoc (I'm
> open to any suggested changes to clarify it):
> "A change to a value that modifies its weight requires that an update
> operation is performed on the map."
>
> On Apr 6, 12:06 pm, Jonathan Ellis <jbel...@gmail.com> wrote:
>
>
>
>
>
>
>
> > How frequently does weightOf get called?
>
> > Does CLHM assume that the weight of a value stays constant, once
> > weighed?
>
> > I am thinking of usinghttps://github.com/jbellis/jammtoallow sizing

Ben Manes

unread,
Apr 6, 2011, 3:47:08 PM4/6/11
to ConcurrentLinkedHashMap
Nope.

This behavior should be covered by the
WeigherTest#weightedValue_withCollections() test case if you'd like to
see an example of the expectations w.r.t. various map operations.

Ben Manes

unread,
Apr 9, 2011, 1:28:44 AM4/9/11
to ConcurrentLinkedHashMap
What is your assumption when if an entry is put into the cache, but
its weight exceeds the cache's capacity? For example, the cache is
bounded to 1MB and a 2MB entry is added.

Currently it is added to the map and an eviction is triggered. As the
entry is the most recently used, its the last potential victim to be
evaluated. The cache continues to evict until the weighted size
doesn't exceed the capacity threshold, which results in flushing the
cache.

While logical, this probably isn't the desired behavior. I suspect
that if the weightedSize > capacity then it should bypass the cache
and immediately be evicted. What is your expectation?

P.S. I added a quick tutorial with an example using your Jamm
library. :)
Reply all
Reply to author
Forward
0 new messages