| 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>Sizing a database environment</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="env.html" title="Chapter 9. The Berkeley DB Environment" /> |
| 11 | <link rel="prev" href="env_create.html" title="Creating a database environment" /> |
| 12 | <link rel="next" href="env_open.html" title="Opening databases within the environment" /> |
| 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">Sizing a database environment</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="env_create.html">Prev</a> </td> |
| 25 | <th width="60%" align="center">Chapter 9. |
| 26 | The Berkeley DB Environment |
| 27 | </th> |
| 28 | <td width="20%" align="right"> <a accesskey="n" href="env_open.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="env_size"></a>Sizing a database environment</h2> |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | <p> |
| 42 | The Berkeley DB environment allocates memory to hold shared |
| 43 | structures, either in shared regions or in process data space (if the |
| 44 | <a href="../api_reference/C/envopen.html#envopen_DB_PRIVATE" class="olink">DB_PRIVATE</a> flag is specified). There are three distinct memory |
| 45 | regions: |
| 46 | </p> |
| 47 | <div class="itemizedlist"> |
| 48 | <ul type="disc"> |
| 49 | <li> |
| 50 | <p> |
| 51 | The memory pool (also known as the database page cache), |
| 52 | </p> |
| 53 | </li> |
| 54 | <li> |
| 55 | <p> |
| 56 | the area containing mutexes, and |
| 57 | </p> |
| 58 | </li> |
| 59 | <li> |
| 60 | <p> |
| 61 | the main region which holds all other shared structures. |
| 62 | </p> |
| 63 | </li> |
| 64 | </ul> |
| 65 | </div> |
| 66 | <p> |
| 67 | The shared structures in the main region are used by the lock, |
| 68 | transaction, logging, thread and replicatoin subsystems. |
| 69 | </p> |
| 70 | <p> |
| 71 | Determining the amount of space allocated for each of these shared |
| 72 | structures is dependent upon the structure in question. The sizing |
| 73 | of the memory pool is discussed in |
| 74 | <a class="xref" href="mp_config.html" title="Configuring the memory pool">Configuring the memory pool</a>. The amount |
| 75 | of memory needed for mutexes is calculated from the number of |
| 76 | mutexes needed by various subsystems and can be adjusted using the |
| 77 | <a href="../api_reference/C/mutexset_increment.html" class="olink">DB_ENV->mutex_set_increment()</a> method. |
| 78 | </p> |
| 79 | <p> |
| 80 | For applications using shared memory (that is, they do not specify |
| 81 | <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 |
| 82 | specified or left to default. The maximum memory size is specified |
| 83 | using the <a href="../api_reference/C/envset_memory_max.html" class="olink">DB_ENV->set_memory_max()</a> method. |
| 84 | </p> |
| 85 | <p> |
| 86 | The amount of memory needed by an application is dependent |
| 87 | on the resources that the application uses. For a very rough |
| 88 | estimate, add all of the following together: |
| 89 | </p> |
| 90 | <div class="orderedlist"> |
| 91 | <ol type="1"> |
| 92 | <li> |
| 93 | <p> |
| 94 | The environment has an overhead of about 80 kilobytes |
| 95 | without statistics enabled or 250 kilobytes with statistics |
| 96 | enabled. |
| 97 | </p> |
| 98 | </li> |
| 99 | <li> |
| 100 | <p> |
| 101 | Identify the amount of space you require for your locks: |
| 102 | </p> |
| 103 | <div class="orderedlist"> |
| 104 | <ol type="a"> |
| 105 | <li> |
| 106 | <p> |
| 107 | Estimate the number of threads of control that will |
| 108 | simultaneously access the environment. |
| 109 | </p> |
| 110 | </li> |
| 111 | <li> |
| 112 | <p> |
| 113 | Estimate the number of concurrency locks that, on average, |
| 114 | will be required by each thread. For information on |
| 115 | sizing concurrency locks, see |
| 116 | <a class="xref" href="lock_max.html" title="Configuring locking: sizing the system">Configuring locking: sizing the system</a>. |
| 117 | </p> |
| 118 | </li> |
| 119 | <li> |
| 120 | <p> |
| 121 | Multiply these two numbers, then multiply by 1/2 to |
| 122 | arrive at the number of kilobytes required to |
| 123 | service your locks. |
| 124 | </p> |
| 125 | </li> |
| 126 | </ol> |
| 127 | </div> |
| 128 | </li> |
| 129 | <li> |
| 130 | <p> |
| 131 | Estimate the number of open database handles you will use |
| 132 | at any given time. For each database handle, there is an |
| 133 | overhead of about 1/2 kilobyte. |
| 134 | </p> |
| 135 | </li> |
| 136 | <li> |
| 137 | <p> |
| 138 | Add 1 kilobyte for each active transaction. |
| 139 | </p> |
| 140 | </li> |
| 141 | </ol> |
| 142 | </div> |
| 143 | <p> |
| 144 | Note that these are very rough guidelines. It is best to |
| 145 | overestimate the needs of your applications, because if the memory |
| 146 | allocation is exhausted the application must be shutdown to |
| 147 | increase the allocation. |
| 148 | </p> |
| 149 | <p> |
| 150 | The estimate for maximum memory need not be exact. In most |
| 151 | situations there is little penalty for over estimating. For systems |
| 152 | using memory mapped files for the shared environment, this only |
| 153 | allocates the address space in the process to hold the maximum |
| 154 | memory. The backing file will only be extended as needed. For |
| 155 | systems running with <a href="../api_reference/C/envopen.html#envopen_DB_PRIVATE" class="olink">DB_PRIVATE</a> specified, the maximum memory |
| 156 | serves only as a limit and memory is allocated from the process |
| 157 | data space as needed. No maximum need be set for private |
| 158 | environments. |
| 159 | </p> |
| 160 | <p> |
| 161 | For locking and thread information, groups of objects are allocated |
| 162 | when needed so that there is less contention in the allocator |
| 163 | during performance critical operations. Once allocated to a |
| 164 | particular use, this memory will only be used for that structure. |
| 165 | To avoid runtime contention, or to ensure a minimum number of a |
| 166 | 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 |
| 167 | used. This method can set the initial numbers of particular types |
| 168 | of structures to allocate at environment creation time. |
| 169 | </p> |
| 170 | </div> |
| 171 | <div class="navfooter"> |
| 172 | <hr /> |
| 173 | <table width="100%" summary="Navigation footer"> |
| 174 | <tr> |
| 175 | <td width="40%" align="left"><a accesskey="p" href="env_create.html">Prev</a> </td> |
| 176 | <td width="20%" align="center"> |
| 177 | <a accesskey="u" href="env.html">Up</a> |
| 178 | </td> |
| 179 | <td width="40%" align="right"> <a accesskey="n" href="env_open.html">Next</a></td> |
| 180 | </tr> |
| 181 | <tr> |
| 182 | <td width="40%" align="left" valign="top">Creating a database environment </td> |
| 183 | <td width="20%" align="center"> |
| 184 | <a accesskey="h" href="index.html">Home</a> |
| 185 | </td> |
| 186 | <td width="40%" align="right" valign="top"> Opening databases within the environment</td> |
| 187 | </tr> |
| 188 | </table> |
| 189 | </div> |
| 190 | </body> |
| 191 | </html> |