<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
<BR>
I agree. There are two ways to determine what the memory usage is, polling or notifications. The notification mechanism is not guaranteed, so we could have a background thread that polls to determine whether or not the threshold has been passed. Then in the put and replace methods, it would be the cost of checking a boolean value.<BR>
<BR>
<HR id=stopSpelling>
From: manik@jboss.org<BR>Date: Fri, 14 Jan 2011 11:45:29 +0000<BR>To: infinispan-dev@lists.jboss.org<BR>Subject: Re: [infinispan-dev] ISPN-863 - Thoughts / Questions<BR><BR>
<META content="Microsoft SafeHTML" name=Generator><BASE>I'll let Vladimir comment more as he wrote most of this code originally, but it sounds OK in principle.
<DIV><BR></DIV>
<DIV>Would you need to check the memory usage on every put and replace? Wouldn't this be expensive? Couldn't this happen periodically?
<DIV><BR>
<DIV>
<DIV>On 14 Jan 2011, at 03:22, david marion wrote:</DIV><BR class=ecxApple-interchange-newline>
<BLOCKQUOTE><SPAN class=ecxApple-style-span style="WORD-SPACING: 0px; FONT: medium Helvetica; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate">
<DIV class=ecxhmmessage style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">
<DIV style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; MARGIN-BOTTOM: 0pt; PADDING-BOTTOM: 0px; MARGIN-LEFT: 0in; MARGIN-RIGHT: 0in; PADDING-TOP: 0px"><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">I have been looking at the code and think I have a starting point on the design. Remember, the goal here is to be able to create a cache that uses expiration but has no defined cache size limit. Reading through the code, if ‘-1’ is specified for the eviction maxEntries, then a ConcurrentHashMap is created and used as the data container and no eviction is performed. Otherwise a BoundedConcurrentHashMap is created and used as the data container and eviction is performed according to the specified strategy.</SPAN></DIV>
<DIV style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; MARGIN-BOTTOM: 0pt; PADDING-BOTTOM: 0px; MARGIN-LEFT: 0in; MARGIN-RIGHT: 0in; PADDING-TOP: 0px"><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"> </SPAN></DIV>
<DIV style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; MARGIN-BOTTOM: 0pt; PADDING-BOTTOM: 0px; MARGIN-LEFT: 0in; MARGIN-RIGHT: 0in; PADDING-TOP: 0px"><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">Eviction currently appears to happen in two different ways:</SPAN></DIV>
<DIV style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; MARGIN-BOTTOM: 0pt; PADDING-BOTTOM: 0px; MARGIN-LEFT: 0in; MARGIN-RIGHT: 0in; PADDING-TOP: 0px"><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"> </SPAN></DIV>
<DIV style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; MARGIN-BOTTOM: 0pt; PADDING-BOTTOM: 0px; MARGIN-LEFT: 0.75in; TEXT-INDENT: -0.25in; MARGIN-RIGHT: 0in; PADDING-TOP: 0px"><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">1.</SPAN><SPAN style="FONT-SIZE: 7pt; COLOR: navy"><FONT face="Times New Roman"> <SPAN class=ecxApple-converted-space> </SPAN></FONT></SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">If an entry is expired, then it can be evicted.</SPAN></DIV>
<DIV style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; MARGIN-BOTTOM: 0pt; PADDING-BOTTOM: 0px; MARGIN-LEFT: 0.75in; TEXT-INDENT: -0.25in; MARGIN-RIGHT: 0in; PADDING-TOP: 0px"><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">2.</SPAN><SPAN style="FONT-SIZE: 7pt; COLOR: navy"><FONT face="Times New Roman"> <SPAN class=ecxApple-converted-space> </SPAN></FONT></SPAN><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">If the number of entries in a segment of the cache contains more entries than “allowed” by the configuration.</SPAN></DIV>
<DIV style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; MARGIN-BOTTOM: 0pt; PADDING-BOTTOM: 0px; MARGIN-LEFT: 0in; MARGIN-RIGHT: 0in; PADDING-TOP: 0px"><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"> </SPAN></DIV>
<DIV style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; MARGIN-BOTTOM: 0pt; PADDING-BOTTOM: 0px; MARGIN-LEFT: 0in; MARGIN-RIGHT: 0in; PADDING-TOP: 0px"><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">Here are the modifications that I think need to be made. I have not made any code mods yet, so I don’t know for sure if this will work. Definitely looking for feedback.</SPAN></DIV>
<DIV style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; MARGIN-BOTTOM: 0pt; PADDING-BOTTOM: 0px; MARGIN-LEFT: 0in; MARGIN-RIGHT: 0in; PADDING-TOP: 0px"><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"> </SPAN></DIV>
<OL type=1>
<LI class=ecxMsoNormal style="MARGIN-BOTTOM: 0pt; MARGIN-LEFT: 0in; COLOR: navy; MARGIN-RIGHT: 0in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Modify configuration in some way so that the following can be specified:</SPAN></LI>
<OL type=a>
<LI class=ecxMsoNormal style="MARGIN-BOTTOM: 0pt; MARGIN-LEFT: 0in; COLOR: navy; MARGIN-RIGHT: 0in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">The percentage value of used JVM memory (i.e. 95) at which entries should be evicted to try and avoid an OOM error.</SPAN></LI>
<LI class=ecxMsoNormal style="MARGIN-BOTTOM: 0pt; MARGIN-LEFT: 0in; COLOR: navy; MARGIN-RIGHT: 0in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">The number of items that should be evicted when memory reaches this threshold</SPAN></LI></OL>
<LI class=ecxMsoNormal style="MARGIN-BOTTOM: 0pt; MARGIN-LEFT: 0in; COLOR: navy; MARGIN-RIGHT: 0in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Modify LRU and LIRS Eviction class so that the accessQueue member can be accessed by the new Eviction class so that two access queues don’t have to be maintained.</SPAN></LI>
<LI class=ecxMsoNormal style="MARGIN-BOTTOM: 0pt; MARGIN-LEFT: 0in; COLOR: navy; MARGIN-RIGHT: 0in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Create a new Eviction class, a subclass of LIRS, where the accessQueue is used from the Eviction strategy the user specifies and the for loop in the execute method is exited when the evicted set equals value from 1.b above.</SPAN></LI>
<LI class=ecxMsoNormal style="MARGIN-BOTTOM: 0pt; MARGIN-LEFT: 0in; COLOR: navy; MARGIN-RIGHT: 0in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Modify DataContainerFactory.construct() to call DefaultDataContainer.boundedDataContainer() regardless of eviction policy. This will always create a BoundedConcurrentHashMap</SPAN></LI>
<LI class=ecxMsoNormal style="MARGIN-BOTTOM: 0pt; MARGIN-LEFT: 0in; COLOR: navy; MARGIN-RIGHT: 0in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Create an instance of the new Eviction class in each segment.</SPAN></LI>
<LI class=ecxMsoNormal style="MARGIN-BOTTOM: 0pt; MARGIN-LEFT: 0in; COLOR: navy; MARGIN-RIGHT: 0in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Modify BoundedConcurrentHashMap.Segment put and replace methods such that when new values are going to be put into the Segment, the memory usage is checked and the execute method is called on the new Eviction class.</SPAN></LI></OL>
<DIV style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; MARGIN-BOTTOM: 0pt; PADDING-BOTTOM: 0px; MARGIN-LEFT: 0in; MARGIN-RIGHT: 0in; PADDING-TOP: 0px"><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"> </SPAN></DIV>
<DIV style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; MARGIN-BOTTOM: 0pt; PADDING-BOTTOM: 0px; MARGIN-LEFT: 0in; MARGIN-RIGHT: 0in; PADDING-TOP: 0px"><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">Questions:</SPAN></DIV>
<DIV style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; MARGIN-BOTTOM: 0pt; PADDING-BOTTOM: 0px; MARGIN-LEFT: 0in; MARGIN-RIGHT: 0in; PADDING-TOP: 0px"><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"> </SPAN></DIV>
<OL type=1>
<LI class=ecxMsoNormal style="MARGIN-BOTTOM: 0pt; MARGIN-LEFT: 0in; COLOR: navy; MARGIN-RIGHT: 0in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">What are the implications of using a BoundedConcurrentHashMap instead of a ConcurrentHashMap when maxEntries is set to -1?</SPAN></LI></OL>
<DIV style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; MARGIN-BOTTOM: 0pt; PADDING-BOTTOM: 0px; MARGIN-LEFT: 0in; MARGIN-RIGHT: 0in; PADDING-TOP: 0px"><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"> </SPAN></DIV>
<DIV style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; MARGIN-BOTTOM: 0pt; PADDING-BOTTOM: 0px; MARGIN-LEFT: 0in; MARGIN-RIGHT: 0in; PADDING-TOP: 0px"><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">Thoughts</SPAN></DIV>
<DIV style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; MARGIN-BOTTOM: 0pt; PADDING-BOTTOM: 0px; MARGIN-LEFT: 0in; MARGIN-RIGHT: 0in; PADDING-TOP: 0px"><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"> </SPAN></DIV>
<OL type=1>
<LI class=ecxMsoNormal style="MARGIN-BOTTOM: 0pt; MARGIN-LEFT: 0in; COLOR: navy; MARGIN-RIGHT: 0in"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">This will not guarantee that an OOM error does not occur. It will attempt to guard against an OOM caused by putting new values into the cache. This will probably be more effective when the cache is being used in client/server mode, and less effective when used in embedded mode as to other code running in the JVM.</SPAN></LI></OL>
<DIV style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; MARGIN-BOTTOM: 0pt; PADDING-BOTTOM: 0px; MARGIN-LEFT: 0in; MARGIN-RIGHT: 0in; PADDING-TOP: 0px"><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"> </SPAN></DIV>
<DIV style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; MARGIN-BOTTOM: 0pt; PADDING-BOTTOM: 0px; MARGIN-LEFT: 0in; MARGIN-RIGHT: 0in; PADDING-TOP: 0px"><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial"> </SPAN></DIV>
<DIV style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; MARGIN-BOTTOM: 0pt; PADDING-BOTTOM: 0px; MARGIN-LEFT: 0in; MARGIN-RIGHT: 0in; PADDING-TOP: 0px"><SPAN style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: Arial">-- Dave Marion</SPAN></DIV><BR> <BR>
<HR id=ecxstopSpelling>
From:<SPAN class=ecxApple-converted-space> </SPAN><A href="mailto:manik@jboss.org">manik@jboss.org</A><BR>Date: Tue, 11 Jan 2011 11:46:40 +0000<BR>To:<SPAN class=ecxApple-converted-space> </SPAN><A href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</A><BR>Subject: [infinispan-dev] Poor man's size-based eviction Re: ISPN-863<BR><BR>
<DIV>Hi Dave</DIV>
<DIV><BR></DIV>
<DIV>Just saw that you signed the contributor agreement.</DIV>
<DIV><BR></DIV>
<DIV>So yeah, what you may want to look into is the EvictionManager [1] which will periodically have its processEviction() [2] method called. This doesn't actually do any evictions here (named so for legacy reasons) since the current data container is self-sizing/evicting. However it is still periodically invoked to purge expired entries. </DIV>
<DIV><BR></DIV>
<DIV>You can piggyback on the same invocation to test upper and lower bounds of memory utilisation (if enabled), but the bit that I still think you need to figure out is deciding which entries to evict, and how many of them to evict.</DIV>
<DIV><BR></DIV>
<DIV>Cheers</DIV>
<DIV>Manik</DIV>
<DIV><BR></DIV>
<DIV>[1] <A href="https://github.com/infinispan/infinispan/blob/master/core/src/main/java/org/infinispan/eviction/EvictionManagerImpl.java" target=_blank>https://github.com/infinispan/infinispan/blob/master/core/src/main/java/org/infinispan/eviction/EvictionManagerImpl.java</A></DIV>
<DIV>[2] <A href="https://github.com/infinispan/infinispan/blob/master/core/src/main/java/org/infinispan/eviction/EvictionManagerImpl.java#L84" target=_blank>https://github.com/infinispan/infinispan/blob/master/core/src/main/java/org/infinispan/eviction/EvictionManagerImpl.java#L84</A></DIV><BR>
<DIV>
<DIV>On 10 Jan 2011, at 11:08, Manik Surtani wrote:</DIV><BR class=ecxApple-interchange-newline>
<BLOCKQUOTE>
<DIV style="WORD-WRAP: break-word">Excellent, Dave.
<DIV><BR></DIV>
<DIV>You should probably come up with a design first - or maybe a prototype on your fork of the project on GitHub - and post it here for comment.</DIV>
<DIV><BR></DIV>
<DIV>Cheers</DIV>
<DIV>Manik</DIV>
<DIV><BR>
<DIV>
<DIV>On 8 Jan 2011, at 00:34, david marion wrote:</DIV><BR class=ecxApple-interchange-newline>
<BLOCKQUOTE>
<DIV class=ecxhmmessage style="FONT-SIZE: 10pt; FONT-FAMILY: Tahoma">
<DIV style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; MARGIN-BOTTOM: 0pt; PADDING-BOTTOM: 0px; MARGIN-LEFT: 0in; MARGIN-RIGHT: 0in; PADDING-TOP: 0px"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Manik,</SPAN></DIV>
<DIV style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; MARGIN-BOTTOM: 0pt; PADDING-BOTTOM: 0px; MARGIN-LEFT: 0in; MARGIN-RIGHT: 0in; PADDING-TOP: 0px"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> </SPAN></DIV>
<DIV style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; MARGIN-BOTTOM: 0pt; PADDING-BOTTOM: 0px; MARGIN-LEFT: 0in; TEXT-INDENT: 6pt; MARGIN-RIGHT: 0in; PADDING-TOP: 0px"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">I am on the list. I will start getting my dev environment setup according to instructions on site.</SPAN></DIV>
<DIV style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; MARGIN-BOTTOM: 0pt; PADDING-BOTTOM: 0px; MARGIN-LEFT: 0in; MARGIN-RIGHT: 0in; PADDING-TOP: 0px"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> </SPAN></DIV>
<DIV style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; MARGIN-BOTTOM: 0pt; PADDING-BOTTOM: 0px; MARGIN-LEFT: 0in; MARGIN-RIGHT: 0in; PADDING-TOP: 0px"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Dave Marion</SPAN></DIV><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"> </SPAN><SPAN class=ecxApple-converted-space> </SPAN>_______________________________________________<BR>infinispan-dev mailing list<BR><A href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</A><BR><A href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" target=_blank>https://lists.jboss.org/mailman/listinfo/infinispan-dev</A></DIV></BLOCKQUOTE></DIV><BR>
<DIV>
<DIV>
<DIV>--</DIV>
<DIV>Manik Surtani</DIV>
<DIV><A href="mailto:manik@jboss.org">manik@jboss.org</A></DIV>
<DIV><A href="http://twitter.com/maniksurtani" target=_blank>twitter.com/maniksurtani</A></DIV>
<DIV><BR></DIV>
<DIV>Lead, Infinispan</DIV>
<DIV><A href="http://www.infinispan.org/" target=_blank>http://www.infinispan.org</A></DIV>
<DIV><BR></DIV></DIV><BR class=ecxApple-interchange-newline></DIV><BR></DIV></DIV>_______________________________________________<BR>infinispan-dev mailing list<BR><A href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</A><BR><A href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" target=_blank>https://lists.jboss.org/mailman/listinfo/infinispan-dev</A></BLOCKQUOTE></DIV><BR>
<DIV><SPAN class=ecxApple-style-span style="WORD-SPACING: 0px; FONT: medium Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate">
<DIV>
<DIV>--</DIV>
<DIV>Manik Surtani</DIV>
<DIV><A href="mailto:manik@jboss.org">manik@jboss.org</A></DIV>
<DIV><A href="http://twitter.com/maniksurtani" target=_blank>twitter.com/maniksurtani</A></DIV>
<DIV><BR></DIV>
<DIV>Lead, Infinispan</DIV>
<DIV><A href="http://www.infinispan.org/" target=_blank>http://www.infinispan.org</A></DIV>
<DIV><BR></DIV></DIV></SPAN><BR class=ecxApple-interchange-newline></DIV><BR><BR>_______________________________________________ infinispan-dev mailing list<SPAN class=ecxApple-converted-space> </SPAN><A href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</A><SPAN class=ecxApple-converted-space> </SPAN><A href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" target=_blank>https://lists.jboss.org/mailman/listinfo/infinispan-dev</A>_______________________________________________<BR>infinispan-dev mailing list<BR><A href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</A><BR><A href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" target=_blank>https://lists.jboss.org/mailman/listinfo/infinispan-dev</A></DIV></SPAN></BLOCKQUOTE></DIV><BR>
<DIV><SPAN class=ecxApple-style-span style="WORD-SPACING: 0px; FONT: medium Helvetica; TEXT-TRANSFORM: none; COLOR: rgb(0,0,0); TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate">
<DIV>
<DIV>--</DIV>
<DIV>Manik Surtani</DIV>
<DIV><A href="mailto:manik@jboss.org">manik@jboss.org</A></DIV>
<DIV><A href="http://twitter.com/maniksurtani" target=_blank>twitter.com/maniksurtani</A></DIV>
<DIV><BR></DIV>
<DIV>Lead, Infinispan</DIV>
<DIV><A href="http://www.infinispan.org/" target=_blank>http://www.infinispan.org</A></DIV>
<DIV><BR></DIV></DIV></SPAN><BR class=ecxApple-interchange-newline></DIV><BR></DIV></DIV><BR>_______________________________________________ infinispan-dev mailing list infinispan-dev@lists.jboss.org https://lists.jboss.org/mailman/listinfo/infinispan-dev                                            </body>
</html>