Debian Codegraph @

docs/programmer_reference/lock_max.html

raw symbols SCIP
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6 <title>Configuring locking: sizing the system</title>
7 <link rel="stylesheet" href="gettingStarted.css" type="text/css" />
8 <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
9 <link rel="start" href="index.html" title="Berkeley DB Programmer's Reference Guide" />
10 <link rel="up" href="lock.html" title="Chapter 16.  The Locking Subsystem" />
11 <link rel="prev" href="lock_config.html" title="Configuring locking" />
12 <link rel="next" href="lock_stdmode.html" title="Standard lock modes" />
13 </head>
14 <body>
15 <div xmlns="" class="navheader">
16 <div class="libver">
17 <p>Library Version 11.2.5.3</p>
18 </div>
19 <table width="100%" summary="Navigation header">
20 <tr>
21 <th colspan="3" align="center">Configuring locking: sizing the system</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="lock_config.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 16. 
26 The Locking Subsystem
27 </th>
28 <td width="20%" align="right"> <a accesskey="n" href="lock_stdmode.html">Next</a></td>
29 </tr>
30 </table>
31 <hr />
32 </div>
33 <div class="sect1" lang="en" xml:lang="en">
34 <div class="titlepage">
35 <div>
36 <div>
37 <h2 class="title" style="clear: both"><a id="lock_max"></a>Configuring locking: sizing the system</h2>
38 </div>
39 </div>
40 </div>
41 <p>
42 The amount of memory available to the locking system is specified
43 using the <a href="../api_reference/C/envset_memory_max.html" class="olink">DB_ENV-&gt;set_memory_max()</a> method. Sizing of the enviroment
44 using the <a href="../api_reference/C/envset_memory_max.html" class="olink">DB_ENV-&gt;set_memory_max()</a> method is discussed in
45 <a class="xref" href="env_size.html" title="Sizing a database environment">Sizing a database environment</a>. Here we will
46 discuss how to estimate the number of objects your application is
47 likely to lock. Since running out of memory for locking structures
48 is a fatal error requiring reconfiguration and restarting the
49 environment it is best to overestimate the numbers.
50 </p>
51 <p>
52 When configuring a Berkeley DB Concurrent Data Store application,
53 the number of lock objects needed is two per open database (one for
54 the database lock, and one for the cursor lock when the
55 <a href="../api_reference/C/envset_flags.html#set_flags_DB_CDB_ALLDB" class="olink">DB_CDB_ALLDB</a> option is not specified). The number of locks
56 needed is one per open database handle plus one per simultaneous
57 cursor or non-cursor operation.
58 </p>
59 <p>
60 Configuring a Berkeley DB Transactional Data Store application is
61 more complicated. The recommended algorithm for selecting the
62 number of locks, lockers, and lock objects is to run the
63 application under stressful conditions and then review the lock
64 system's statistics to determine the number of locks,
65 lockers, and lock objects that were used. Then, double these
66 values for safety. However, in some large applications, finer
67 granularity of control is necessary in order to minimize the size
68 of the Lock subsystem.
69 </p>
70 <p>
71 The number of lockers can be estimated as follows:
72 </p>
73 <div class="itemizedlist">
74 <ul type="disc">
75 <li>
76 If the database environment is using transactions, the
77 number of lockers can be estimated by adding the number of
78 simultaneously active non-transactional cursors and open database
79 handles to the number of simultaneously active transactions and
80 child transactions (where a child transaction is active until
81 it commits or aborts, not until its parent commits or aborts).
82 </li>
83 <li>
84 If the database environment is not using transactions, the
85 number of lockers can be estimated by adding the number
86 of simultaneously active non-transactional cursors and open
87 database handles to the number of simultaneous non-cursor
88 operations.
89 </li>
90 </ul>
91 </div>
92 <p>
93 The number of lock objects needed for a transaction
94 can be estimated as follows:
95 </p>
96 <div class="itemizedlist">
97 <ul type="disc">
98 <li>
99 <p>
100 For each access to a non-Queue database, one lock object is
101 needed for each page that is read or updated.
102 </p>
103 </li>
104 <li>
105 <p>
106 For the Queue access method you will need one lock object per
107 record that is read or updated. Deleted records skipped by a
108 DB_NEXT or DB_PREV operation do not require a separate lock
109 object.
110 </p>
111 </li>
112 <li>
113 <p>
114 For Btree and Recno databases additional lock objects may be
115 needed for each node in the btree that has to be split due to
116 an update.
117 </p>
118 </li>
119 <li>
120 <p>
121 For Hash and Queue databases, every access must obtain a lock on
122 the metadata page for the duration of the access. This is not
123 held to the end of the transaction.
124 </p>
125 </li>
126 <li>
127 <p>
128 If the transaction performs an update that needs to allocate a page
129 to the database then a lock object for the metadata page will
130 be needed to the end of the transaction.
131 </p>
132 </li>
133 </ul>
134 </div>
135 <p>
136 Note that transactions accumulate locks over the transaction lifetime,
137 and the lock objects required by a single transaction is the total lock
138 objects required by all of the database operations in the transaction.
139 However, a database page (or record, in the case of the Queue access
140 method), that is accessed multiple times within a transaction only
141 requires a single lock object for the entire transaction. So if a
142 transaction in your application typically accesses 10 records, that
143 transaction will require about 10 lock objects (it may be a few more if
144 it splits btree nodes). If you have up to 10 concurrent threads in your
145 application, then you need to configure your system to have about 100
146 lock objects. It is always better to configure more than you need so
147 that you don't run out of lock objects. The memory overhead of
148 over-allocating lock objects is minimal as they are small structures.
149 </p>
150 <p>
151 The number of locks required by an application cannot be easily
152 estimated. It is possible to calculate a number of locks by
153 multiplying the number of lockers, times the number of
154 lock objects, times two (two for the two possible lock modes for each
155 object, read and write). However, this is a pessimal value, and real
156 applications are unlikely to actually need that many locks. Reviewing
157 the Lock subsystem statistics is the best way to determine this value.
158 </p>
159 <p>
160 By default a minimum number of locking objects are allocated at
161 startup. To avoid contention due to allocation the application may
162 use the <a href="../api_reference/C/envset_memory_init.html" class="olink">DB_ENV-&gt;set_memory_init()</a> method to preallocate and initialize
163 the following lock structures:
164 </p>
165 <div class="itemizedlist">
166 <ul type="disc">
167 <li>
168 <p>
169 <code class="literal">DB_MEM_LOCK</code>
170 </p>
171 <p>
172 Specifies the number of locks that can be
173 simultaneously requested in the system.
174 </p>
175 </li>
176 <li>
177 <p>
178 <code class="literal">DB_MEM_LOCKER</code>
179 </p>
180 <p>
181 Specifies the number of lockers that can
182 simultaneously request locks in the system.
183 </p>
184 </li>
185 <li>
186 <p>
187 <code class="literal">DB_MEM_LOCKOBJECTS</code>
188 </p>
189 <p>
190 Specifies the number of objects that can
191 simultaneously be locked in the system.
192 </p>
193 </li>
194 </ul>
195 </div>
196 <p>
197 In addition to the above structures, sizing your locking subsystem
198 also requires specifying the number of lock table partitions. You
199 do this using the <a href="../api_reference/C/envset_lk_partitions.html" class="olink">DB_ENV-&gt;set_lk_partitions()</a> method. Each partition
200 may be accessed independently by a thread. More partitions can lead
201 to higher levels of concurrency. The default is to set the number
202 of partitions to be 10 times the number of cpus that the operating
203 system reports at the time the environment is created. Having more
204 than one partition when there is only one cpu is not beneficial
205 because the locking system is more efficient when there is a single
206 partition. Some operating systems (Linux, Solaris) may report
207 thread contexts as cpus, and so it may be necessary to override the
208 default to force a single partition on a single hyperthreaded cpu
209 system. Objects and locks are divided among the partitions so it is
210 best to allocate several locks and objects per partition. The
211 system will force there to be at least one per partition. If a
212 partition runs out of locks or objects it will steal what is needed
213 from the other partitions. This operation could impact performance
214 if it occurs too often. The final values specified for the locks
215 and lock objects should be more than or equal to the number of lock
216 table partitions.
217 </p>
218 </div>
219 <div class="navfooter">
220 <hr />
221 <table width="100%" summary="Navigation footer">
222 <tr>
223 <td width="40%" align="left"><a accesskey="p" href="lock_config.html">Prev</a> </td>
224 <td width="20%" align="center">
225 <a accesskey="u" href="lock.html">Up</a>
226 </td>
227 <td width="40%" align="right"> <a accesskey="n" href="lock_stdmode.html">Next</a></td>
228 </tr>
229 <tr>
230 <td width="40%" align="left" valign="top">Configuring locking </td>
231 <td width="20%" align="center">
232 <a accesskey="h" href="index.html">Home</a>
233 </td>
234 <td width="40%" align="right" valign="top"> Standard lock modes</td>
235 </tr>
236 </table>
237 </div>
238 </body>
239 </html>