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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!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/html; charset=UTF-8" />
<title>Sizing a database environment</title>
<link rel="stylesheet" href="gettingStarted.css" type="text/css" />
<meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
<link rel="start" href="index.html" title="Berkeley DB Programmer's Reference Guide" />
<link rel="up" href="env.html" title="Chapter 9. The Berkeley DB Environment" />
<link rel="prev" href="env_create.html" title="Creating a database environment" />
<link rel="next" href="env_open.html" title="Opening databases within the environment" />
</head>
<body>
<div xmlns="" class="navheader">
<div class="libver">
<p>Library Version 12.1.6.1</p>
</div>
<table width="100%" summary="Navigation header">
<tr>
<th colspan="3" align="center">Sizing a database environment</th>
</tr>
<tr>
<td width="20%" align="left"><a accesskey="p" href="env_create.html">Prev</a> </td>
<th width="60%" align="center">Chapter 9. The Berkeley DB Environment </th>
<td width="20%" align="right"> <a accesskey="n" href="env_open.html">Next</a></td>
</tr>
</table>
<hr />
</div>
<div class="sect1" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both"><a id="env_size"></a>Sizing a database environment</h2>
</div>
</div>
</div>
<p>
The Berkeley DB environment allocates memory to hold shared
structures, either in shared regions or in process data space
(if the <a href="../api_reference/C/envopen.html#envopen_DB_PRIVATE" class="olink">DB_PRIVATE</a> flag is specified). There are three
distinct memory regions:
</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>
The memory pool (also known as the database page
cache),
</p>
</li>
<li>
<p>
the area containing mutexes, and
</p>
</li>
<li>
<p>
the main region which holds all other shared
structures.
</p>
</li>
</ul>
</div>
<p>
The shared structures in the main region are used by the
lock, transaction, logging, thread and replicatoin subsystems.
</p>
<p>
Determining the amount of space allocated for each of these
shared structures is dependent upon the structure in question.
The sizing of the memory pool is discussed in <a class="xref" href="mp_config.html" title="Configuring the memory pool">Configuring the memory pool</a>. The
amount of memory needed for mutexes is calculated from the
number of mutexes needed by various subsystems and can be
adjusted using the <a href="../api_reference/C/mutexset_increment.html" class="olink">DB_ENV->mutex_set_increment()</a> method.
</p>
<p>
For applications using shared memory (that is, they do not
specify <a href="../api_reference/C/envopen.html#envopen_DB_PRIVATE" class="olink">DB_PRIVATE</a>), a maximum memory size for the main
region must be specified or left to default. The maximum
memory size is specified using the <a href="../api_reference/C/envset_memory_max.html" class="olink">DB_ENV->set_memory_max()</a> method.
</p>
<p>
The amount of memory needed by an application is dependent
on the resources that the application uses. For a very rough
estimate, add all of the following together:
</p>
<div class="orderedlist">
<ol type="1">
<li>
<p>
The environment has an overhead of about 80
kilobytes without statistics enabled or 250 kilobytes
with statistics enabled.
</p>
</li>
<li>
<p>
Identify the amount of space you require for your
locks:
</p>
<div class="orderedlist">
<ol type="a">
<li>
<p>
Estimate the number of threads of control
that will simultaneously access the
environment.
</p>
</li>
<li>
<p>
Estimate the number of concurrency locks
that, on average, will be required by each
thread. For information on sizing concurrency
locks, see <a class="xref" href="lock_max.html" title="Configuring locking: sizing the system">Configuring locking: sizing the
system</a>.
</p>
</li>
<li>
<p>
Multiply these two numbers, then multiply
by 1/2 to arrive at the number of kilobytes
required to service your locks.
</p>
</li>
</ol>
</div>
</li>
<li>
<p>
Estimate the number of open database handles you
will use at any given time. For each database handle,
there is an overhead of about 1/2 kilobyte.
</p>
</li>
<li>
<p>
Add 1 kilobyte for each active transaction.
</p>
</li>
</ol>
</div>
<p>
Note that these are very rough guidelines. It is best to
overestimate the needs of your applications, because if the
memory allocation is exhausted the application must be
shutdown to increase the allocation.
</p>
<p>
The estimate for maximum memory need not be exact. In most
situations there is little penalty for over estimating. For
systems using memory mapped files for the shared environment,
this only allocates the address space in the process to hold
the maximum memory. The backing file will only be extended as
needed. For systems running with <a href="../api_reference/C/envopen.html#envopen_DB_PRIVATE" class="olink">DB_PRIVATE</a> specified, the
maximum memory serves only as a limit and memory is allocated
from the process data space as needed. No maximum need be set
for private environments.
</p>
<p>
For locking and thread information, groups of objects are
allocated when needed so that there is less contention in the
allocator during performance critical operations. Once
allocated to a particular use, this memory will only be used
for that structure. To avoid runtime contention, or to ensure
a minimum number of a particular type of object, the
<a href="../api_reference/C/envset_memory_init.html" class="olink">DB_ENV->set_memory_init()</a> method can be used. This method can set
the initial numbers of particular types of structures to
allocate at environment creation time.
</p>
</div>
<div class="navfooter">
<hr />
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left"><a accesskey="p" href="env_create.html">Prev</a> </td>
<td width="20%" align="center">
<a accesskey="u" href="env.html">Up</a>
</td>
<td width="40%" align="right"> <a accesskey="n" href="env_open.html">Next</a></td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Creating a database
environment </td>
<td width="20%" align="center">
<a accesskey="h" href="index.html">Home</a>
</td>
<td width="40%" align="right" valign="top"> Opening databases within the
environment</td>
</tr>
</table>
</div>
</body>
</html>
|