| 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>Transaction throughput</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="transapp.html" title="Chapter 11. Berkeley DB Transactional Data Store Applications" /> |
| 11 | <link rel="prev" href="transapp_tune.html" title="Transaction tuning" /> |
| 12 | <link rel="next" href="transapp_faq.html" title="Transaction FAQ" /> |
| 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">Transaction throughput</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="transapp_tune.html">Prev</a> </td> |
| 25 | <th width="60%" align="center">Chapter 11. |
| 26 | Berkeley DB Transactional Data Store Applications |
| 27 | </th> |
| 28 | <td width="20%" align="right"> <a accesskey="n" href="transapp_faq.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="transapp_throughput"></a>Transaction throughput</h2> |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | <p>Generally, the speed of a database system is measured by the |
| 42 | <span class="emphasis"><em>transaction throughput</em></span>, expressed as a number of |
| 43 | transactions per second. The two gating factors for Berkeley DB performance |
| 44 | in a transactional system are usually the underlying database files and |
| 45 | the log file. Both are factors because they require disk I/O, which is |
| 46 | slow relative to other system resources such as CPU.</p> |
| 47 | <p>In the worst-case scenario:</p> |
| 48 | <div class="itemizedlist"> |
| 49 | <ul type="disc"> |
| 50 | <li>Database access is truly random and the database is too large for any |
| 51 | significant percentage of it to fit into the cache, resulting in a |
| 52 | single I/O per requested key/data pair.</li> |
| 53 | <li>Both the database and the log are on a single disk.</li> |
| 54 | </ul> |
| 55 | </div> |
| 56 | <p>This means that for each transaction, Berkeley DB is potentially performing |
| 57 | several filesystem operations:</p> |
| 58 | <div class="itemizedlist"> |
| 59 | <ul type="disc"> |
| 60 | <li>Disk seek to database file</li> |
| 61 | <li>Database file read</li> |
| 62 | <li>Disk seek to log file</li> |
| 63 | <li>Log file write</li> |
| 64 | <li>Flush log file information to disk</li> |
| 65 | <li>Disk seek to update log file metadata (for example, inode information)</li> |
| 66 | <li>Log metadata write</li> |
| 67 | <li>Flush log file metadata to disk</li> |
| 68 | </ul> |
| 69 | </div> |
| 70 | <p>There are a number of ways to increase transactional throughput, all of |
| 71 | which attempt to decrease the number of filesystem operations per |
| 72 | transaction. First, the Berkeley DB software includes support for |
| 73 | <span class="emphasis"><em>group commit</em></span>. Group commit simply means that when the |
| 74 | information about one transaction is flushed to disk, the information |
| 75 | for any other waiting transactions will be flushed to disk at the same |
| 76 | time, potentially amortizing a single log write over a large number of |
| 77 | transactions. There are additional tuning parameters which may be |
| 78 | useful to application writers:</p> |
| 79 | <div class="itemizedlist"> |
| 80 | <ul type="disc"> |
| 81 | <li>Tune the size of the database cache. If the Berkeley DB key/data pairs used |
| 82 | during the transaction are found in the database cache, the seek and read |
| 83 | from the database are no longer necessary, resulting in two fewer |
| 84 | filesystem operations per transaction. To determine whether your cache |
| 85 | size is too small, see <a class="xref" href="general_am_conf.html#am_conf_cachesize" title="Selecting a cache size">Selecting a cache size</a>.</li> |
| 86 | <li>Put the database and the log files on different disks. This allows reads |
| 87 | and writes to the log files and the database files to be performed |
| 88 | concurrently.</li> |
| 89 | <li>Set the filesystem configuration so that file access and modification times |
| 90 | are not updated. Note that although the file access and modification times |
| 91 | are not used by Berkeley DB, this may affect other programs -- so be careful.</li> |
| 92 | <li>Upgrade your hardware. When considering the hardware on which to run your |
| 93 | application, however, it is important to consider the entire system. The |
| 94 | controller and bus can have as much to do with the disk performance as |
| 95 | the disk itself. It is also important to remember that throughput is |
| 96 | rarely the limiting factor, and that disk seek times are normally the true |
| 97 | performance issue for Berkeley DB.</li> |
| 98 | <li> |
| 99 | Turn on the <a href="../api_reference/C/envset_flags.html#envset_flags_DB_TXN_NOSYNC" class="olink">DB_TXN_NOSYNC</a> or <a href="../api_reference/C/envset_flags.html#set_flags_DB_TXN_WRITE_NOSYNC" class="olink">DB_TXN_WRITE_NOSYNC</a> flags. This |
| 100 | changes the Berkeley DB behavior so that the log files are not written |
| 101 | and/or flushed when transactions are committed. Although this change |
| 102 | will greatly increase your transaction throughput, it means that |
| 103 | transactions will exhibit the ACI (atomicity, consistency, and |
| 104 | isolation) properties, but not D (durability). Database integrity will |
| 105 | be maintained, but it is possible that some number of the most recently |
| 106 | committed transactions may be undone during recovery instead of being |
| 107 | redone. |
| 108 | </li> |
| 109 | </ul> |
| 110 | </div> |
| 111 | <p>If you are bottlenecked on logging, the following test will help you |
| 112 | confirm that the number of transactions per second that your application |
| 113 | does is reasonable for the hardware on which you are running. Your test |
| 114 | program should repeatedly perform the following operations:</p> |
| 115 | <div class="itemizedlist"> |
| 116 | <ul type="disc"> |
| 117 | <li>Seek to the beginning of a file</li> |
| 118 | <li>Write to the file</li> |
| 119 | <li>Flush the file write to disk</li> |
| 120 | </ul> |
| 121 | </div> |
| 122 | <p>The number of times that you can perform these three operations per |
| 123 | second is a rough measure of the minimum number of transactions per |
| 124 | second of which the hardware is capable. This test simulates the |
| 125 | operations applied to the log file. (As a simplifying assumption in this |
| 126 | experiment, we assume that the database files are either on a separate |
| 127 | disk; or that they fit, with some few exceptions, into the database |
| 128 | cache.) We do not have to directly simulate updating the log file |
| 129 | directory information because it will normally be updated and flushed |
| 130 | to disk as a result of flushing the log file write to disk.</p> |
| 131 | <p>Running this test program, in which we write 256 bytes for 1000 operations |
| 132 | on reasonably standard commodity hardware (Pentium II CPU, SCSI disk), |
| 133 | returned the following results:</p> |
| 134 | <pre class="programlisting">% testfile -b256 -o1000 |
| 135 | running: 1000 ops |
| 136 | Elapsed time: 16.641934 seconds |
| 137 | 1000 ops: 60.09 ops per second</pre> |
| 138 | <p>Note that the number of bytes being written to the log as part of each |
| 139 | transaction can dramatically affect the transaction throughput. The |
| 140 | test run used 256, which is a reasonable size log write. Your log |
| 141 | writes may be different. To determine your average log write size, use |
| 142 | the <a href="../api_reference/C/db_stat.html" class="olink">db_stat</a> utility to display your log statistics.</p> |
| 143 | <p>As a quick sanity check, the average seek time is 9.4 msec for this |
| 144 | particular disk, and the average latency is 4.17 msec. That results in |
| 145 | a minimum requirement for a data transfer to the disk of 13.57 msec, or |
| 146 | a maximum of 74 transfers per second. This is close enough to the |
| 147 | previous 60 operations per second (which was not done on a quiescent |
| 148 | disk) that the number is believable.</p> |
| 149 | <p>An implementation of the previous <a class="ulink" href="writetest.cs" target="_top">example test |
| 150 | program</a> for IEEE/ANSI Std 1003.1 (POSIX) standard systems is included in the Berkeley DB |
| 151 | distribution.</p> |
| 152 | </div> |
| 153 | <div class="navfooter"> |
| 154 | <hr /> |
| 155 | <table width="100%" summary="Navigation footer"> |
| 156 | <tr> |
| 157 | <td width="40%" align="left"><a accesskey="p" href="transapp_tune.html">Prev</a> </td> |
| 158 | <td width="20%" align="center"> |
| 159 | <a accesskey="u" href="transapp.html">Up</a> |
| 160 | </td> |
| 161 | <td width="40%" align="right"> <a accesskey="n" href="transapp_faq.html">Next</a></td> |
| 162 | </tr> |
| 163 | <tr> |
| 164 | <td width="40%" align="left" valign="top">Transaction tuning </td> |
| 165 | <td width="20%" align="center"> |
| 166 | <a accesskey="h" href="index.html">Home</a> |
| 167 | </td> |
| 168 | <td width="40%" align="right" valign="top"> Transaction FAQ</td> |
| 169 | </tr> |
| 170 | </table> |
| 171 | </div> |
| 172 | </body> |
| 173 | </html> |