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