📄 cachesize.so
字号:
m4_comment([$Id: cachesize.so,v 10.20 2003/02/19 17:41:58 bostic Exp $])m4_ref_title(Access Methods, Selecting a cache size, selecting a @cache size, am_conf/pagesize, am_conf/byteorder)m4_p([dnlThe size of the cache used for the underlying database can be specifiedby calling the m4_refT(dbh_set_cachesize).Choosing a cache size is, unfortunately, an art. Your cache must be atleast large enough for your working set plus some overlap for unexpectedsituations.])m4_p([dnlWhen using the Btree access method, you must have a cache big enough forthe minimum working set for a single access. This will include a rootpage, one or more internal pages (depending on the depth of your tree),and a leaf page. If your cache is any smaller than that, each new pagewill force out the least-recently-used page, and m4_db will re-read theroot page of the tree anew on each database request.])m4_p([dnlIf your keys are of moderate size (a few tens of bytes) and your pagesare on the order of 4KB to 8KB, most Btree applications will be onlythree levels. For example, using 20 byte keys with 20 bytes of dataassociated with each key, a 8KB page can hold roughly 400 keys (or 200key/data pairs), so a fully populated three-level Btree will hold 32million key/data pairs, and a tree with only a 50% page-fill factor willstill hold 16 million key/data pairs. We rarely expect trees to exceedfive levels, although m4_db will support trees up to 255 levels.])m4_p([dnlThe rule-of-thumb is that cache is good, and more cache is better.Generally, applications benefit from increasing the cache size up to apoint, at which the performance will stop improving as the cache sizeincreases. When this point is reached, one of two things have happened:either the cache is large enough that the application is almost neverhaving to retrieve information from disk, or, your application is doingtruly random accesses, and therefore increasing size of the cache doesn'tsignificantly increase the odds of finding the next requested informationin the cache. The latter is fairly rare -- almost all applications showsome form of locality of reference.])m4_p([dnlThat said, it is important not to increase your cache size beyond thecapabilities of your system, as that will result in reduced performance.Under many operating systems, tying down enough virtual memory will causeyour memory and potentially your program to be swapped. This isespecially likely on systems without unified OS buffer caches and virtualmemory spaces, as the buffer cache was allocated at boot time and socannot be adjusted based on application requests for large amounts ofvirtual memory.])m4_p([dnlFor example, even if accesses are truly random within a Btree, youraccess pattern will favor internal pages to leaf pages, so your cacheshould be large enough to hold all internal pages. In the steady state,this requires at most one I/O per operation to retrieve the appropriateleaf page.])m4_p([dnlYou can use the m4_ref(db_stat) utility to monitor the effectiveness ofyour cache. The following output is excerpted from the output of thatutility's m4_option(m) option:])m4_indent([dnlprompt: db_stat -m131072 Cache size (128K).4273 Requested pages found in the cache (97%).134 Requested pages not found in the cache.18 Pages created in the cache.116 Pages read into the cache.93 Pages written from the cache to the backing file.5 Clean pages forced from the cache.13 Dirty pages forced from the cache.0 Dirty buffers written by trickle-sync thread.130 Current clean buffer count.4 Current dirty buffer count.])m4_p([dnlThe statistics for this cache say that there have been 4,273 requests ofthe cache, and only 116 of those requests required an I/O from disk. Thismeans that the cache is working well, yielding a 97% cache hit rate. Them4_ref(db_stat) utility will present these statistics both for the cacheas a whole and for each file within the cache separately.])m4_page_footer
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -