<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On 2 Apr 2009, at 09:10, Mircea Markus wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Manik Surtani wrote:<br><blockquote type="cite">Hello all.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I have finished my work with the eviction code in Infinispan, here is a summary of what has happened.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">From a user perspective (including API and configuration) as well as a design overview, please have a look at <br></blockquote><blockquote type="cite"><a href="http://www.jboss.org/community/docs/DOC-13449">http://www.jboss.org/community/docs/DOC-13449</a><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">From an implementation perspective, have a look at the srcs of FIFODataContainer and LRUDataContainer. &nbsp;These two classes are where everything happens. &nbsp;The javadocs should explain the details, but in a nutshell you can expect constant time operations for all puts, gets, removes, iterations. &nbsp;:-) &nbsp;<br></blockquote><blockquote type="cite">Feedback on the impls would be handy. &nbsp;:-)<br></blockquote>I like to concept - it's nice and clear for users to grasp. Also took a look at implementation, nice and complex, so I'd rather have you and a white board to understand it completely :) .<br>Some notes though: EvictionException is never used, same for SpinLock.rl field.</div></blockquote><div><br></div><div>Good point, EvictionException was a carry-over from JBC which can go away.</div><div><br></div><div>SpinLock.rl was something I used for debugging/tracking race conditions - it should go away now as well.</div><br><blockquote type="cite"><div>And a question:<br>with this impl, we're doing locking twice for cache operations: on LockInterceptor and on DataContainer itself. Why is this necessary? I think this is needed so that eviction thread and user threads not to conflict( am I right?).</div></blockquote><div><br></div><div>Well, the locking is done on a different level. &nbsp;The LockingInterceptor locks a key. &nbsp;So keep in mind that 2 threads may lock 2 separate keys concurrently, but these may map to the same hash bucket in the data container. &nbsp;In which case, since the DC uses a CHM, this would mean that the same stripe is locked preventing concurrent reorganisation of the stripe.</div><div><br></div><blockquote type="cite"><div>Isn't it possible to use the same locking (i.e. LockManager) for both these threads?</div></blockquote><div><br></div><div>Possible, but again not ideal, for example if you have TX 1 which writes to key K1. &nbsp;The way this currently works, here is what happens:</div><div><br></div><div>1. &nbsp;Acquire lock for key K1 in the lock manager</div><div>2. &nbsp;Write to K1</div><div>3. &nbsp;Sleep?</div><div>4. &nbsp;Commit:</div><div>5. &nbsp;Write changes to DC. &nbsp;This will lock the stripe in the CHM for the duration of this step only.</div><div>6. &nbsp;Release lock acquired in 1</div><div><br></div><div>Now if you have a concurrent write to K2, which *happens* to be in the same stripe as K1 in the CHM, this second thread will *not* block for TX 1 since TX 1 only locks the CHM stripe for a short duration (step 5 above). &nbsp;</div><div><br></div><div>Now if we used the same locks thoughout (e.g., step 1 *is* the lock stripe in the CHM) then you have far less concurrency.</div><div><br></div><div>Of course, the above premise only holds true if you have enough shared locks for the lock manager such that K1 and K2 do not map to the same lock, even if they are in the same stripe in the CHM. &nbsp;Also holds true if lock striping is disabled and you have a lock per key.</div><div><br></div><blockquote type="cite"><div>(also, why are we using &nbsp;ConcurrentHashMaps in default container - isn't access to data guarded by the lock interceptor?</div></blockquote><div><br></div><div>See above. &nbsp;:-)</div><div><br></div><div>Cheers</div><div>Manik</div><div><br></div><div>--</div></div><div apple-content-edited="true"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-infinispantal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-infinispantal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Manik Surtani</div><div>Lead, JBoss Cache</div><div><a href="http://www.jbosscache.org">http://www.jbosscache.org</a><br><a href="mailto:manik@jboss.org" target="_blank">manik@jboss.org</a></div><div><br></div></div></span><br class="Apple-interchange-newline"></div></span><br class="Apple-interchange-newline"> </div><br></body></html>