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>Selecting the Cache Size</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="Getting Started with Berkeley DB" />
10    <link rel="up" href="dbconfig.html" title="Chapter��11.��Database Configuration" />
11    <link rel="prev" href="dbconfig.html" title="Chapter��11.��Database Configuration" />
12    <link rel="next" href="btree.html" title="BTree Configuration" />
13  </head>
14  <body>
15    <div class="navheader">
16      <table width="100%" summary="Navigation header">
17        <tr>
18          <th colspan="3" align="center">Selecting the Cache Size</th>
19        </tr>
20        <tr>
21          <td width="20%" align="left"><a accesskey="p" href="dbconfig.html">Prev</a>��</td>
22          <th width="60%" align="center">Chapter��11.��Database Configuration</th>
23          <td width="20%" align="right">��<a accesskey="n" href="btree.html">Next</a></td>
24        </tr>
25      </table>
26      <hr />
27    </div>
28    <div class="sect1" lang="en" xml:lang="en">
29      <div class="titlepage">
30        <div>
31          <div>
32            <h2 class="title" style="clear: both"><a id="cachesize"></a>Selecting the Cache Size</h2>
33          </div>
34        </div>
35      </div>
36      <p>
37        Cache size is important to your application because if it is set to too
38        small of a value, your application's performance will suffer from too
39        much disk I/O. On the other hand, if your cache is too large, then your
40        application will use more memory than it actually needs.
41        Moreover, if your application uses too much memory, then on most
42        operating systems this can result in your application being swapped out
43        of memory, resulting in extremely poor performance.
44    </p>
45      <p>
46        You select your cache size using either
47            
48            
49            <span>
50                <code class="methodname">DatabaseConfig.setCacheSize()</code>, or 
51                <code class="methodname">EnvironmentConfig.setCacheSize()</code>,
52            </span>
53         depending on whether you are using a database environment or not. You
54         cache size must be a power of 2, but it is otherwise limited only by
55         available memory and performance considerations.
56    </p>
57      <p>
58        Selecting a cache size is something of an art, but fortunately you
59        can change it any time, so it can be easily tuned to your
60        application's changing data requirements.  The best way to
61        determine how large your cache needs to be is to put your
62        application into a production environment and watch to see how much
63        disk I/O is occurring. If your application is going to disk quite a
64        lot to retrieve database records, then you should increase the size
65        of your cache (provided that you have enough memory to do so).
66    </p>
67      <p>
68        You can use the <code class="literal">db_stat</code> command line utility with the
69        <code class="literal">-m</code> option to gauge the effectiveness of your cache.
70        In particular, the number of pages found in the cache is shown, along
71        with a percentage value. The closer to 100% that you can get, the
72        better. If this value drops too low, and you are experiencing
73        performance problems, then you should consider increasing the size of
74        your cache, assuming you have memory to support it.
75    </p>
76    </div>
77    <div class="navfooter">
78      <hr />
79      <table width="100%" summary="Navigation footer">
80        <tr>
81          <td width="40%" align="left"><a accesskey="p" href="dbconfig.html">Prev</a>��</td>
82          <td width="20%" align="center">
83            <a accesskey="u" href="dbconfig.html">Up</a>
84          </td>
85          <td width="40%" align="right">��<a accesskey="n" href="btree.html">Next</a></td>
86        </tr>
87        <tr>
88          <td width="40%" align="left" valign="top">Chapter��11.��Database Configuration��</td>
89          <td width="20%" align="center">
90            <a accesskey="h" href="index.html">Home</a>
91          </td>
92          <td width="40%" align="right" valign="top">��BTree Configuration</td>
93        </tr>
94      </table>
95    </div>
96  </body>
97</html>
98