Files
rippled/md_ripple_nodestore_ShardPool.html
2023-04-13 17:45:50 +00:00

113 lines
5.9 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.17"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>rippled: Open Shard Management</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">rippled
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.17 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
</div><!-- top -->
<div class="PageDoc"><div class="header">
<div class="headertitle">
<div class="title">Open Shard Management </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h1><a class="anchor" id="autotoc_md204"></a>
Overview</h1>
<p>Shard NuDB and SQLite databases consume server resources. This can be unnecessarily taxing on servers with many shards. The open shard management feature aims to improve the situation by managing a limited number of open shard database connections. The feature, which is integrated into the existing DatabaseShardImp and Shard classes, maintains a limited pool of open databases prioritized by their last use time stamp. The following sections describe the feature in greater detail.</p>
<h2><a class="anchor" id="autotoc_md205"></a>
Open Shard Management</h2>
<p>The open shard management feature is integrated into the DatabaseShardImp and Shard classes. As the DatabaseShardImp sweep function is periodically called, the number of finalized open shards, which constitutes the open pool, are examined. Upon the pool exceeding a pool limit, an attempt is made to close enough open shards to remain within the limit. Shards to be closed are selected based on their last use time stamp,&#160;which is automatically updated on database access. If necessary, shards will automatically open their databases when accessed.</p>
<div class="fragment"><div class="line">{C++}</div>
<div class="line"> if (openFinals.size() &gt; openFinalLimit_)</div>
<div class="line"> {</div>
<div class="line"> // Try to close enough shards to be within the limit.</div>
<div class="line"> // Sort on largest elapsed time since last use.</div>
<div class="line"> std::sort(</div>
<div class="line"> openFinals.begin(),</div>
<div class="line"> openFinals.end(),</div>
<div class="line"> [&amp;](std::shared_ptr&lt;Shard&gt; const&amp; lhsShard,</div>
<div class="line"> std::shared_ptr&lt;Shard&gt; const&amp; rhsShard) {</div>
<div class="line"> return lhsShard-&gt;getLastUse() &gt; rhsShard-&gt;getLastUse();</div>
<div class="line"> });</div>
<div class="line"> </div>
<div class="line"> for (auto it{openFinals.cbegin()};</div>
<div class="line"> it != openFinals.cend() &amp;&amp; openFinals.size() &gt; openFinalLimit_;)</div>
<div class="line"> {</div>
<div class="line"> if ((*it)-&gt;tryClose())</div>
<div class="line"> it = openFinals.erase(it);</div>
<div class="line"> else</div>
<div class="line"> ++it;</div>
<div class="line"> }</div>
<div class="line"> }</div>
</div><!-- fragment --><h2><a class="anchor" id="autotoc_md206"></a>
Shard</h2>
<p>When closing an open shard, DatabaseShardImp will call the Shard 'tryClose' function. This function will only close the shard databases if there are no outstanding references.</p>
<p>DatabaseShardImp will use the Shard 'isOpen' function to determine the state of a shard's database.</p>
<h2><a class="anchor" id="autotoc_md207"></a>
Caveats</h2>
<p>The Shard class must check the state of its databases before use. Prior use assumed databases were always open, that is no longer the case with the open shard management feature. </p>
</div></div><!-- contents -->
</div><!-- PageDoc -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.17
</small></address>
</body>
</html>