<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
Hi Daniel,
<div class=""><br class="">
</div>
<div class="">
<div>I would like to help you out.  Did you have some numbers about the performance improvement of your evaluation?  I had a <a href="https://github.com/XueleiFan/jdk/blob/jdk-8245576/src/java.base/share/classes/sun/security/ssl/SSLSessionContextImpl.java" class="">draft
 re-write cache</a> by using ConcurrentHashMap, if you have a chance, would you like to evaluate if it could be improved further with your ideas?</div>
<div><br class="">
</div>
<div>Thanks,</div>
<div>Xuelei</div>
<div><br class="">
<blockquote type="cite" class="">
<div class="">On Jan 27, 2021, at 1:28 AM, Daniel JeliƄski <<a href="mailto:djelinski1@gmail.com" class="">djelinski1@gmail.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div dir="ltr" class="">Hi all,
<div class="">I'd like to modify the MemoryCache class that is used for caching SSL sessions in Java 11; when the cache is overloaded (full cache with no expired entries), the computational complexity of put operation is linear in the cache size.</div>
<div class=""><br class="">
</div>
<div class="">I am aware that the current Java versions are using stateless resumption; my company's policy is to use Java LTS, so stateless is not an option to us at the moment.</div>
<div class=""><br class="">
</div>
<div class="">The change I propose would alter the behavior of MemoryCache; currently the cache guarantees that expired entries are removed before live entries when the cache capacity is reached. I'd like to remove that guarantee, and instead always remove
 the least recently used cache entry. Additionally, to keep the memory use in check, I'd like to check the least recently used entries for expiration, and remove them as needed. This operation would be run on every put().</div>
<div class=""><br class="">
</div>
<div class="">Evaluated alternatives:</div>
<div class="">- keep MemoryCache as is, increase cache size to avoid overloading. This would reduce the frequency of check for expired entries, but if the larger cache eventually gets overloaded, the put() operation would take even longer to complete.</div>
<div class="">- keep MemoryCache behavior as is, but improve performance of removing expired entries. This would require a new data structure - we would need to have cache entries sorted both by access time and creation time.</div>
<div class="">- always remove entries in insertion order, regardless if they are used or not.</div>
<div class="">- always remove the least recently used entries, even if they are still valid and there are recently used expired entries somewhere in the cache. This is my preferred option.</div>
<div class=""><br class="">
</div>
<div class="">Additionally, we can choose how to remove stale entries:</div>
<div class="">- all reachable stale entries on every put (that is, iterate over the internal data structure removing stale entries until a non-stale one is found); keeps memory use low, but can occasionally scan the entire cache (computational complexity: linear
 worst case, amortized constant); </div>
<div class="">- fixed number of reachable stale entries on every put (same as above, but stop iterating after a fixed number of removed entries even if more are available); execution time is bounded by a constant, but some entries may stay in cache a bit longer
 than they need to.</div>
<div class="">- all stale entries on put that would otherwise exceed cache capacity (current implementation)<br class="">
</div>
<div class="">- never; once cache reaches full capacity, it stays full until the application is restarted. Fastest implementation, but at a cost of increased memory use.</div>
<div class=""><br class="">
</div>
<div class="">My preference would be to remove either all or a fixed number of reachable stale entries.</div>
<div class=""><br class="">
</div>
<div class="">I'm willing to prepare a patch for 17 and 11u, if I can find a sponsor.</div>
<div class="">Thanks,</div>
<div class="">Daniel</div>
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>