-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtune_cache.html
125 lines (125 loc) · 10.8 KB
/
tune_cache.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://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"/>
<title>WiredTiger: Cache and eviction tuning</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="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
$(window).load(resizeHeight);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="wiredtiger.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="projectlogo"><a href="http://wiredtiger.com/"><img alt="Logo" src="LogoFinal-header.png" alt="WiredTiger" /></a></td>
<td style="padding-left: 0.5em;">
<div id="projectname">
 <span id="projectnumber">Version 2.9.2</span>
</div>
<div id="projectbrief"><!-- 2.9.2 --></div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="banner">
<a href="https://github.com/wiredtiger/wiredtiger">Fork me on GitHub</a>
<a class="last" href="http://groups.google.com/group/wiredtiger-users">Join my user group</a>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.10 -->
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main Page</span></a></li>
<li class="current"><a href="pages.html"><span>Related Pages</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="examples.html"><span>Examples</span></a></li>
<li><a href="community.html"><span>Community</span></a></li>
<li><a href="license.html"><span>License</span></a></li>
</ul>
</div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('tune_cache.html','');});
</script>
<div id="doc-content">
<div class="header">
<div class="headertitle">
<div class="title">Cache and eviction tuning </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h1><a class="anchor" id="tuning_cache_size"></a>
Cache size</h1>
<p>The size of the cache is the single most important tuning knob for a WiredTiger application. Ideally the cache should be configured to be large enough to hold an application's working set.</p>
<p>The cache size for the database is normally configured by setting the <code>cache_size</code> configuration string when calling the <a class="el" href="group__wt.html#ga9e6adae3fc6964ef837a62795c7840ed" title="Open a connection to a database. ">wiredtiger_open</a> function. The cache size can be adjusted after the open call with <a class="el" href="struct_w_t___c_o_n_n_e_c_t_i_o_n.html#a579141678af06217b22869cbc604c6d4" title="Reconfigure a connection handle. ">WT_CONNECTION::reconfigure</a>.</p>
<p>An example of setting a cache size to 5GB:</p>
<div class="fragment"><div class="line"> ret = <a class="code" href="group__wt.html#ga9e6adae3fc6964ef837a62795c7840ed">wiredtiger_open</a>(home, NULL,</div>
<div class="line"> <span class="stringliteral">"create,cache_size=5GB,log=(enabled,recover=on)"</span>, &conn);</div>
</div><!-- fragment --><p> The effectiveness of the chosen cache size can be measured by reviewing the page eviction statistics for the database.</p>
<h1><a class="anchor" id="tuning_cache_resident"></a>
Cache resident objects</h1>
<p>Objects can be created as cache resident - that is their contents will remain in cache and never be considered for the purposes of cache eviction. Cache residence can be configured with the <a class="el" href="struct_w_t___s_e_s_s_i_o_n.html#a358ca4141d59c345f401c58501276bbb" title="Create a table, column group, index or file. ">WT_SESSION::create</a> "cache_resident" configuration string. LSM tree objects do not support the "cache_resident" setting.</p>
<p>Configuring a cache resident object has several effects:</p>
<ul>
<li>Once the object's pages have been created or instantiated in memory no further I/O cost is ever paid for object access, minimizing potential latency.</li>
<li>Cache resident objects can be accessed faster than objects tracked for potential eviction.</li>
<li>If cache resident objects require a significant proportion of the configured cache size then non cache-resident objects can incur significantly higher I/O churn.</li>
<li>If cache resident objects require more space than the configured cache size, then further operations will either return error or stall until space is made available by closing objects.</li>
</ul>
<p>An example of configuring a cache-resident object:</p>
<div class="fragment"><div class="line"> ret = session->create(session,</div>
<div class="line"> <span class="stringliteral">"table:mytable"</span>, <span class="stringliteral">"key_format=r,value_format=S,cache_resident=true"</span>);</div>
</div><!-- fragment --> <h1><a class="anchor" id="cache_eviction"></a>
Eviction tuning</h1>
<p>When an application approaches the maximum cache size, WiredTiger begins eviction to stop memory use from growing too large, approximating a least-recently-used algorithm.</p>
<p>WiredTiger provides several configuration options for tuning how pages are evicted from the cache. Different settings will improve performance depending on an application's particular workload. Customizing the eviction configuration settings can reduce latency spikes in application threads and can improve throughput in some applications.</p>
<p>WiredTiger eviction tuning options can be configured when first opening a database via <a class="el" href="group__wt.html#ga9e6adae3fc6964ef837a62795c7840ed" title="Open a connection to a database. ">wiredtiger_open</a>, or changed after open with <a class="el" href="struct_w_t___c_o_n_n_e_c_t_i_o_n.html#a579141678af06217b22869cbc604c6d4" title="Reconfigure a connection handle. ">WT_CONNECTION::reconfigure</a>.</p>
<p>The <code>eviction_target</code> configuration value (default 80%) is the level at which WiredTiger attempts to keep the overall cache usage. Eviction worker threads are active when the cache contains at least this much content, expressed as a percentage of the total cache size.</p>
<p>The <code>eviction_trigger</code> configuration value (default 95%) is the level at which application threads start to perform eviction. This will throttle application operations, increasing operation latency, usually resulting in the cache usage staying at this level when there is more cache pressure than eviction worker threads can handle in the background.</p>
<p>Operations will stall when the cache reaches 100% of the cache size. Application may want to change these settings from their defaults to either increase the range in which worker threads operate before application threads are throttled, or to use a larger proportion of RAM, if eviction worker threads have no difficulty handling the cache pressure generated by the application.</p>
<p>The <code>eviction_dirty_target</code> (default 5%) and <code>eviction_dirty_trigger</code> (default 20%) operate in a similar way to the overall targets, but only apply to dirty data in cache. In particular, application threads will be throttled if the percentage of dirty data reaches the <code>eviction_dirty_trigger</code>. Any page that has been modified since it was read from disk is considered dirty.</p>
<p>The dirty eviction settings control how much work checkpoints have to do in the worst case, and also limit how much memory fragmentation is likely for memory allocations related to the cache. Most memory fragmentation is caused by workloads that generate a mix of updates (small allocations) with cache misses (large allocations). Limiting the percentage of cache that can be dirty limits the worst case fragmentation to the approximately the same level.</p>
<div class="fragment"><div class="line"> <span class="comment">/*</span></div>
<div class="line"><span class="comment"> * Configure eviction to begin at 90% full, and run until the cache</span></div>
<div class="line"><span class="comment"> * is only 75% dirty.</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"> ret = <a class="code" href="group__wt.html#ga9e6adae3fc6964ef837a62795c7840ed">wiredtiger_open</a>(home, NULL,</div>
<div class="line"> <span class="stringliteral">"create,eviction_trigger=90,eviction_dirty_target=75"</span>, &conn);</div>
</div><!-- fragment --><p> By default, WiredTiger cache eviction is handled by a single, separate thread. In a large, busy cache, a single thread will be insufficient (especially when the eviction thread must wait for I/O). The <code>eviction=</code>(threads_min) and <code>eviction=</code>(threads_max) configuration values can be used to configure the minimum and maximum number of additional threads WiredTiger will create to keep up with the application eviction load. Finally, if the Wiredtiger eviction threads are unable to keep up with application demand for cache space, application threads will be tasked with eviction as well, potentially resulting in latency spikes.</p>
<div class="fragment"><div class="line"> <span class="comment">/* Configure up to four eviction threads */</span></div>
<div class="line"> ret = <a class="code" href="group__wt.html#ga9e6adae3fc6964ef837a62795c7840ed">wiredtiger_open</a>(home, NULL,</div>
<div class="line"> <span class="stringliteral">"create,eviction_trigger=90,eviction=(threads_max=4)"</span>, &conn);</div>
</div><!-- fragment --></div></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="index.html">Reference Guide</a></li><li class="navelem"><a class="el" href="programming_lang_java.html">Writing WiredTiger applications in Java</a></li>
<li class="footer">Copyright (c) 2008-2016 MongoDB, Inc. All rights reserved. Contact <a href="mailto:[email protected]">[email protected]</a> for more information.</li>
</ul>
</div>
</body>
</html>