You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@directmemory.apache.org by Chetan Mehrotra <ch...@gmail.com> on 2013/07/10 13:52:06 UTC

Limiting the number of entries in CacheService

Is it possible to limit the number of entries that CacheService can hold?

With default settings I at times hit OOM error as the cache expands
without any upper bounds. Possibly the CacheService can now use Guava
Cache [1] instead of simple Map and use its maximumSize feature. Some
benefits I see

1. Ability to limit entries by size. Other feature of limit by weight
can also be used in some cases
2. By registering a RemovalListener the CacheService can free up
memory from LRU entries without relying on a timer
3. Access to some useful stats about Cache usage

Approach 1 - This can be made part of CacheService implementation
itself (DM already has dependency on Guava)

Approach 2 - It can be kept as an optional feature as part of Guava
integration (DIRECTMEMORY-131) .
Then client can change the Map registered with the CacheService with
Map provided by Guava Cache

Cache guavaCache = CacheBuilder.newBuilder()....
CacheService cacheService = new
DirectMemory<>.setMap(guavaCache.asMap()....newCacheService()

WDYT?

Chetan Mehrotra
[1] https://code.google.com/p/guava-libraries/wiki/CachesExplained

Re: Limiting the number of entries in CacheService

Posted by Christoph Engelbert <no...@apache.org>.
The new buffer would throw an exception when running out of slices
:-) but you should try to never reach that level because the moment
all threads start to use the last slices (mostly on one partition)
will result in lots of contention (sounds like distribution of last
IPv4 addresses ;-)).

Chris

Am 16.07.2013 13:09, schrieb Tommaso Teofili:
>
>
> 2013/7/16 Raffaele P. Guidi <raffaele.p.guidi@gmail.com
> <ma...@gmail.com>>
>
>     Yeah that's what I was thinking - it shouldn't add too much
>     overhead and I think having OOMs generated by DM is a bit of a
>     shame :D
>
> yes, exactly :-)
>
> Tommaso
>  
>
>     Il giorno 16/lug/2013 10:15, "Tommaso Teofili"
>     <tommaso.teofili@gmail.com <ma...@gmail.com>>
>     ha scritto:
>
>
>
>         2013/7/11 Raffaele P. Guidi <raffaele.p.guidi@gmail.com
>         <ma...@gmail.com>>
>
>             I understand, but we should prevent those OOMs simply
>             checking the size of the object against the free space
>             remaining in the MemoryService bucket before trying to
>             add it - this is a cleaner and more accurate way to
>             handle it
>
>
>         I was wondering if we could add this kind of check during
>         additions, WDYT?
>
>         Tommaso
>          
>
>
>
>             On Thu, Jul 11, 2013 at 10:48 AM, Chetan Mehrotra
>             <chetan.mehrotra@gmail.com
>             <ma...@gmail.com>> wrote:
>
>                 Hi Raffaele,
>
>                 The OOM was coming because of the in memory map
>                 (key -> pointer) that
>                 CacheService maintains as. Hence I was looking for
>                 a way to limit the
>                 number of entries in that map.
>
>                 Chetan Mehrotra
>
>
>                 On Thu, Jul 11, 2013 at 3:29 AM, Raffaele P. Guidi
>                 <raffaele.p.guidi@gmail.com
>                 <ma...@gmail.com>> wrote:
>                 > Well, the ability to limit entries by number is
>                 usually something heap
>                 > caches do because it's hard to calculate an
>                 object's size without
>                 > serializing it - so size is a more accurate way
>                 to set a limit. The OOM
>                 > errors you are having are probably a bug that we
>                 should fix. In any case a
>                 > limit is not hard to implement even though it is
>                 possible to have OOM errors
>                 > even staying under the number limit so I don't
>                 quite see the point.
>                 >
>                 > And which use cases you see for limit by item
>                 weight?
>                 >
>                 > Ciao,
>                 >    R
>                 >
>                 >
>                 > On Wed, Jul 10, 2013 at 1:52 PM, Chetan Mehrotra
>                 <chetan.mehrotra@gmail.com
>                 <ma...@gmail.com>>
>                 > wrote:
>                 >>
>                 >> Is it possible to limit the number of entries
>                 that CacheService can hold?
>                 >>
>                 >> With default settings I at times hit OOM error
>                 as the cache expands
>                 >> without any upper bounds. Possibly the
>                 CacheService can now use Guava
>                 >> Cache [1] instead of simple Map and use its
>                 maximumSize feature. Some
>                 >> benefits I see
>                 >>
>                 >> 1. Ability to limit entries by size. Other
>                 feature of limit by weight
>                 >> can also be used in some cases
>                 >> 2. By registering a RemovalListener the
>                 CacheService can free up
>                 >> memory from LRU entries without relying on a timer
>                 >> 3. Access to some useful stats about Cache usage
>                 >>
>                 >> Approach 1 - This can be made part of
>                 CacheService implementation
>                 >> itself (DM already has dependency on Guava)
>                 >>
>                 >> Approach 2 - It can be kept as an optional
>                 feature as part of Guava
>                 >> integration (DIRECTMEMORY-131) .
>                 >> Then client can change the Map registered with
>                 the CacheService with
>                 >> Map provided by Guava Cache
>                 >>
>                 >> Cache guavaCache = CacheBuilder.newBuilder()....
>                 >> CacheService cacheService = new
>                 >>
>                 DirectMemory<>.setMap(guavaCache.asMap()....newCacheService()
>                 >>
>                 >> WDYT?
>                 >>
>                 >> Chetan Mehrotra
>                 >> [1]
>                 https://code.google.com/p/guava-libraries/wiki/CachesExplained
>                 >
>                 >
>
>
>
>


Re: Limiting the number of entries in CacheService

Posted by Tommaso Teofili <to...@gmail.com>.
2013/7/16 Raffaele P. Guidi <ra...@gmail.com>

> Yeah that's what I was thinking - it shouldn't add too much overhead and I
> think having OOMs generated by DM is a bit of a shame :D
>
yes, exactly :-)

Tommaso


> Il giorno 16/lug/2013 10:15, "Tommaso Teofili" <to...@gmail.com>
> ha scritto:
>
>
>>
>> 2013/7/11 Raffaele P. Guidi <ra...@gmail.com>
>>
>>> I understand, but we should prevent those OOMs simply checking the size
>>> of the object against the free space remaining in the MemoryService bucket
>>> before trying to add it - this is a cleaner and more accurate way to handle
>>> it
>>>
>>
>> I was wondering if we could add this kind of check during additions, WDYT?
>>
>> Tommaso
>>
>>
>>>
>>>
>>> On Thu, Jul 11, 2013 at 10:48 AM, Chetan Mehrotra <
>>> chetan.mehrotra@gmail.com> wrote:
>>>
>>>> Hi Raffaele,
>>>>
>>>> The OOM was coming because of the in memory map (key -> pointer) that
>>>> CacheService maintains as. Hence I was looking for a way to limit the
>>>> number of entries in that map.
>>>>
>>>> Chetan Mehrotra
>>>>
>>>>
>>>> On Thu, Jul 11, 2013 at 3:29 AM, Raffaele P. Guidi
>>>> <ra...@gmail.com> wrote:
>>>> > Well, the ability to limit entries by number is usually something heap
>>>> > caches do because it's hard to calculate an object's size without
>>>> > serializing it - so size is a more accurate way to set a limit. The
>>>> OOM
>>>> > errors you are having are probably a bug that we should fix. In any
>>>> case a
>>>> > limit is not hard to implement even though it is possible to have OOM
>>>> errors
>>>> > even staying under the number limit so I don't quite see the point.
>>>> >
>>>> > And which use cases you see for limit by item weight?
>>>> >
>>>> > Ciao,
>>>> >    R
>>>> >
>>>> >
>>>> > On Wed, Jul 10, 2013 at 1:52 PM, Chetan Mehrotra <
>>>> chetan.mehrotra@gmail.com>
>>>> > wrote:
>>>> >>
>>>> >> Is it possible to limit the number of entries that CacheService can
>>>> hold?
>>>> >>
>>>> >> With default settings I at times hit OOM error as the cache expands
>>>> >> without any upper bounds. Possibly the CacheService can now use Guava
>>>> >> Cache [1] instead of simple Map and use its maximumSize feature. Some
>>>> >> benefits I see
>>>> >>
>>>> >> 1. Ability to limit entries by size. Other feature of limit by weight
>>>> >> can also be used in some cases
>>>> >> 2. By registering a RemovalListener the CacheService can free up
>>>> >> memory from LRU entries without relying on a timer
>>>> >> 3. Access to some useful stats about Cache usage
>>>> >>
>>>> >> Approach 1 - This can be made part of CacheService implementation
>>>> >> itself (DM already has dependency on Guava)
>>>> >>
>>>> >> Approach 2 - It can be kept as an optional feature as part of Guava
>>>> >> integration (DIRECTMEMORY-131) .
>>>> >> Then client can change the Map registered with the CacheService with
>>>> >> Map provided by Guava Cache
>>>> >>
>>>> >> Cache guavaCache = CacheBuilder.newBuilder()....
>>>> >> CacheService cacheService = new
>>>> >> DirectMemory<>.setMap(guavaCache.asMap()....newCacheService()
>>>> >>
>>>> >> WDYT?
>>>> >>
>>>> >> Chetan Mehrotra
>>>> >> [1] https://code.google.com/p/guava-libraries/wiki/CachesExplained
>>>> >
>>>> >
>>>>
>>>
>>>
>>

Re: Limiting the number of entries in CacheService

Posted by "Raffaele P. Guidi" <ra...@gmail.com>.
Yeah that's what I was thinking - it shouldn't add too much overhead and I
think having OOMs generated by DM is a bit of a shame :D
Il giorno 16/lug/2013 10:15, "Tommaso Teofili" <to...@gmail.com>
ha scritto:

>
>
> 2013/7/11 Raffaele P. Guidi <ra...@gmail.com>
>
>> I understand, but we should prevent those OOMs simply checking the size
>> of the object against the free space remaining in the MemoryService bucket
>> before trying to add it - this is a cleaner and more accurate way to handle
>> it
>>
>
> I was wondering if we could add this kind of check during additions, WDYT?
>
> Tommaso
>
>
>>
>>
>> On Thu, Jul 11, 2013 at 10:48 AM, Chetan Mehrotra <
>> chetan.mehrotra@gmail.com> wrote:
>>
>>> Hi Raffaele,
>>>
>>> The OOM was coming because of the in memory map (key -> pointer) that
>>> CacheService maintains as. Hence I was looking for a way to limit the
>>> number of entries in that map.
>>>
>>> Chetan Mehrotra
>>>
>>>
>>> On Thu, Jul 11, 2013 at 3:29 AM, Raffaele P. Guidi
>>> <ra...@gmail.com> wrote:
>>> > Well, the ability to limit entries by number is usually something heap
>>> > caches do because it's hard to calculate an object's size without
>>> > serializing it - so size is a more accurate way to set a limit. The OOM
>>> > errors you are having are probably a bug that we should fix. In any
>>> case a
>>> > limit is not hard to implement even though it is possible to have OOM
>>> errors
>>> > even staying under the number limit so I don't quite see the point.
>>> >
>>> > And which use cases you see for limit by item weight?
>>> >
>>> > Ciao,
>>> >    R
>>> >
>>> >
>>> > On Wed, Jul 10, 2013 at 1:52 PM, Chetan Mehrotra <
>>> chetan.mehrotra@gmail.com>
>>> > wrote:
>>> >>
>>> >> Is it possible to limit the number of entries that CacheService can
>>> hold?
>>> >>
>>> >> With default settings I at times hit OOM error as the cache expands
>>> >> without any upper bounds. Possibly the CacheService can now use Guava
>>> >> Cache [1] instead of simple Map and use its maximumSize feature. Some
>>> >> benefits I see
>>> >>
>>> >> 1. Ability to limit entries by size. Other feature of limit by weight
>>> >> can also be used in some cases
>>> >> 2. By registering a RemovalListener the CacheService can free up
>>> >> memory from LRU entries without relying on a timer
>>> >> 3. Access to some useful stats about Cache usage
>>> >>
>>> >> Approach 1 - This can be made part of CacheService implementation
>>> >> itself (DM already has dependency on Guava)
>>> >>
>>> >> Approach 2 - It can be kept as an optional feature as part of Guava
>>> >> integration (DIRECTMEMORY-131) .
>>> >> Then client can change the Map registered with the CacheService with
>>> >> Map provided by Guava Cache
>>> >>
>>> >> Cache guavaCache = CacheBuilder.newBuilder()....
>>> >> CacheService cacheService = new
>>> >> DirectMemory<>.setMap(guavaCache.asMap()....newCacheService()
>>> >>
>>> >> WDYT?
>>> >>
>>> >> Chetan Mehrotra
>>> >> [1] https://code.google.com/p/guava-libraries/wiki/CachesExplained
>>> >
>>> >
>>>
>>
>>
>

Re: Limiting the number of entries in CacheService

Posted by Tommaso Teofili <to...@gmail.com>.
2013/7/11 Raffaele P. Guidi <ra...@gmail.com>

> I understand, but we should prevent those OOMs simply checking the size of
> the object against the free space remaining in the MemoryService bucket
> before trying to add it - this is a cleaner and more accurate way to handle
> it
>

I was wondering if we could add this kind of check during additions, WDYT?

Tommaso


>
>
> On Thu, Jul 11, 2013 at 10:48 AM, Chetan Mehrotra <
> chetan.mehrotra@gmail.com> wrote:
>
>> Hi Raffaele,
>>
>> The OOM was coming because of the in memory map (key -> pointer) that
>> CacheService maintains as. Hence I was looking for a way to limit the
>> number of entries in that map.
>>
>> Chetan Mehrotra
>>
>>
>> On Thu, Jul 11, 2013 at 3:29 AM, Raffaele P. Guidi
>> <ra...@gmail.com> wrote:
>> > Well, the ability to limit entries by number is usually something heap
>> > caches do because it's hard to calculate an object's size without
>> > serializing it - so size is a more accurate way to set a limit. The OOM
>> > errors you are having are probably a bug that we should fix. In any
>> case a
>> > limit is not hard to implement even though it is possible to have OOM
>> errors
>> > even staying under the number limit so I don't quite see the point.
>> >
>> > And which use cases you see for limit by item weight?
>> >
>> > Ciao,
>> >    R
>> >
>> >
>> > On Wed, Jul 10, 2013 at 1:52 PM, Chetan Mehrotra <
>> chetan.mehrotra@gmail.com>
>> > wrote:
>> >>
>> >> Is it possible to limit the number of entries that CacheService can
>> hold?
>> >>
>> >> With default settings I at times hit OOM error as the cache expands
>> >> without any upper bounds. Possibly the CacheService can now use Guava
>> >> Cache [1] instead of simple Map and use its maximumSize feature. Some
>> >> benefits I see
>> >>
>> >> 1. Ability to limit entries by size. Other feature of limit by weight
>> >> can also be used in some cases
>> >> 2. By registering a RemovalListener the CacheService can free up
>> >> memory from LRU entries without relying on a timer
>> >> 3. Access to some useful stats about Cache usage
>> >>
>> >> Approach 1 - This can be made part of CacheService implementation
>> >> itself (DM already has dependency on Guava)
>> >>
>> >> Approach 2 - It can be kept as an optional feature as part of Guava
>> >> integration (DIRECTMEMORY-131) .
>> >> Then client can change the Map registered with the CacheService with
>> >> Map provided by Guava Cache
>> >>
>> >> Cache guavaCache = CacheBuilder.newBuilder()....
>> >> CacheService cacheService = new
>> >> DirectMemory<>.setMap(guavaCache.asMap()....newCacheService()
>> >>
>> >> WDYT?
>> >>
>> >> Chetan Mehrotra
>> >> [1] https://code.google.com/p/guava-libraries/wiki/CachesExplained
>> >
>> >
>>
>
>

Re: Limiting the number of entries in CacheService

Posted by "Raffaele P. Guidi" <ra...@gmail.com>.
I understand, but we should prevent those OOMs simply checking the size of
the object against the free space remaining in the MemoryService bucket
before trying to add it - this is a cleaner and more accurate way to handle
it


On Thu, Jul 11, 2013 at 10:48 AM, Chetan Mehrotra <chetan.mehrotra@gmail.com
> wrote:

> Hi Raffaele,
>
> The OOM was coming because of the in memory map (key -> pointer) that
> CacheService maintains as. Hence I was looking for a way to limit the
> number of entries in that map.
>
> Chetan Mehrotra
>
>
> On Thu, Jul 11, 2013 at 3:29 AM, Raffaele P. Guidi
> <ra...@gmail.com> wrote:
> > Well, the ability to limit entries by number is usually something heap
> > caches do because it's hard to calculate an object's size without
> > serializing it - so size is a more accurate way to set a limit. The OOM
> > errors you are having are probably a bug that we should fix. In any case
> a
> > limit is not hard to implement even though it is possible to have OOM
> errors
> > even staying under the number limit so I don't quite see the point.
> >
> > And which use cases you see for limit by item weight?
> >
> > Ciao,
> >    R
> >
> >
> > On Wed, Jul 10, 2013 at 1:52 PM, Chetan Mehrotra <
> chetan.mehrotra@gmail.com>
> > wrote:
> >>
> >> Is it possible to limit the number of entries that CacheService can
> hold?
> >>
> >> With default settings I at times hit OOM error as the cache expands
> >> without any upper bounds. Possibly the CacheService can now use Guava
> >> Cache [1] instead of simple Map and use its maximumSize feature. Some
> >> benefits I see
> >>
> >> 1. Ability to limit entries by size. Other feature of limit by weight
> >> can also be used in some cases
> >> 2. By registering a RemovalListener the CacheService can free up
> >> memory from LRU entries without relying on a timer
> >> 3. Access to some useful stats about Cache usage
> >>
> >> Approach 1 - This can be made part of CacheService implementation
> >> itself (DM already has dependency on Guava)
> >>
> >> Approach 2 - It can be kept as an optional feature as part of Guava
> >> integration (DIRECTMEMORY-131) .
> >> Then client can change the Map registered with the CacheService with
> >> Map provided by Guava Cache
> >>
> >> Cache guavaCache = CacheBuilder.newBuilder()....
> >> CacheService cacheService = new
> >> DirectMemory<>.setMap(guavaCache.asMap()....newCacheService()
> >>
> >> WDYT?
> >>
> >> Chetan Mehrotra
> >> [1] https://code.google.com/p/guava-libraries/wiki/CachesExplained
> >
> >
>

Re: Limiting the number of entries in CacheService

Posted by Chetan Mehrotra <ch...@gmail.com>.
Hi Raffaele,

The OOM was coming because of the in memory map (key -> pointer) that
CacheService maintains as. Hence I was looking for a way to limit the
number of entries in that map.

Chetan Mehrotra


On Thu, Jul 11, 2013 at 3:29 AM, Raffaele P. Guidi
<ra...@gmail.com> wrote:
> Well, the ability to limit entries by number is usually something heap
> caches do because it's hard to calculate an object's size without
> serializing it - so size is a more accurate way to set a limit. The OOM
> errors you are having are probably a bug that we should fix. In any case a
> limit is not hard to implement even though it is possible to have OOM errors
> even staying under the number limit so I don't quite see the point.
>
> And which use cases you see for limit by item weight?
>
> Ciao,
>    R
>
>
> On Wed, Jul 10, 2013 at 1:52 PM, Chetan Mehrotra <ch...@gmail.com>
> wrote:
>>
>> Is it possible to limit the number of entries that CacheService can hold?
>>
>> With default settings I at times hit OOM error as the cache expands
>> without any upper bounds. Possibly the CacheService can now use Guava
>> Cache [1] instead of simple Map and use its maximumSize feature. Some
>> benefits I see
>>
>> 1. Ability to limit entries by size. Other feature of limit by weight
>> can also be used in some cases
>> 2. By registering a RemovalListener the CacheService can free up
>> memory from LRU entries without relying on a timer
>> 3. Access to some useful stats about Cache usage
>>
>> Approach 1 - This can be made part of CacheService implementation
>> itself (DM already has dependency on Guava)
>>
>> Approach 2 - It can be kept as an optional feature as part of Guava
>> integration (DIRECTMEMORY-131) .
>> Then client can change the Map registered with the CacheService with
>> Map provided by Guava Cache
>>
>> Cache guavaCache = CacheBuilder.newBuilder()....
>> CacheService cacheService = new
>> DirectMemory<>.setMap(guavaCache.asMap()....newCacheService()
>>
>> WDYT?
>>
>> Chetan Mehrotra
>> [1] https://code.google.com/p/guava-libraries/wiki/CachesExplained
>
>

Re: Limiting the number of entries in CacheService

Posted by "Raffaele P. Guidi" <ra...@gmail.com>.
Well, the ability to limit entries by number is usually something heap
caches do because it's hard to calculate an object's size without
serializing it - so size is a more accurate way to set a limit. The OOM
errors you are having are probably a bug that we should fix. In any case a
limit is not hard to implement even though it is possible to have OOM
errors even staying under the number limit so I don't quite see the point.

And which use cases you see for limit by item weight?

Ciao,
   R


On Wed, Jul 10, 2013 at 1:52 PM, Chetan Mehrotra
<ch...@gmail.com>wrote:

> Is it possible to limit the number of entries that CacheService can hold?
>
> With default settings I at times hit OOM error as the cache expands
> without any upper bounds. Possibly the CacheService can now use Guava
> Cache [1] instead of simple Map and use its maximumSize feature. Some
> benefits I see
>
> 1. Ability to limit entries by size. Other feature of limit by weight
> can also be used in some cases
> 2. By registering a RemovalListener the CacheService can free up
> memory from LRU entries without relying on a timer
> 3. Access to some useful stats about Cache usage
>
> Approach 1 - This can be made part of CacheService implementation
> itself (DM already has dependency on Guava)
>
> Approach 2 - It can be kept as an optional feature as part of Guava
> integration (DIRECTMEMORY-131) .
> Then client can change the Map registered with the CacheService with
> Map provided by Guava Cache
>
> Cache guavaCache = CacheBuilder.newBuilder()....
> CacheService cacheService = new
> DirectMemory<>.setMap(guavaCache.asMap()....newCacheService()
>
> WDYT?
>
> Chetan Mehrotra
> [1] https://code.google.com/p/guava-libraries/wiki/CachesExplained
>