When configuring a new instance, it is impossible to know the correct size for the buffer cache. Typically, a database administrator makes a first estimate for the cache size, then runs a representative workload on the instance and examines the relevant statistics to see whether the cache is under or over configured.
当配置一个新的实例,不可能正确的知道buffer cache的大小。比如,一个数据库管理员第一次需要评估buffer cache的大小,之后在实例运行一个正常的工作量,之后检查相关的统计看buffer cache是高于配置的值,还是低于配置的值。
7.2.2.1Buffer Cache Advisory Statistics
A number of statistics can be used to examine buffer cache activity. These include the following:
V$DB_CACHE_ADVICE
Buffer cache hit ratio
buffer cache 报告的统计
统计的数据能被用于检查buffer cache的活动。
This view is populated when the DB_CACHE_ADVICE
initialization parameter is set toON
. This view shows the simulated miss rates for a range of potential buffer cache sizes.
当db_cache_advice初始化参数设为on,这个视图会一直增加。这个视图显示了一整套的关于buffer cache大小的模拟的缺失率。
Each cache size simulated has its own row in this view, with the predicted physical I/O activity that would take place for that size. TheDB_CACHE_ADVICE
parameter is dynamic, so the advisory can be enabled and disabled dynamically to allow you to collect advisory data for a specific workload.
在视图中每个缓存的模拟大小有他自己的一行数据。设置不同的大小,预测物理i/o的活动。db_cache_advice参数是动态的。所以报告能被开启和关闭允许你收集一个具体的工作量的报告数据。
There is some overhead associated with this advisory. When the advisory is enabled, there is a small increase in CPU usage, because additional bookkeeping is required.
有一些与这个报告相关联的开销,当这个报告被开启,将有少量增加cpu的使用.因为增加额外的记录是必须的.
Oracle uses DBA-based sampling to gather cache advisory statistics. Sampling substantially reduces both CPU and memory overhead associated with bookkeeping. Sampling is not used for a buffer pool if the number of buffers in that buffer pool is small to begin with.
oracle使用dba为基础取样收集缓存的统计报告,取样大大降低了cpu的使用和内存开销和额外的记录.
To use V$DB_CACHE_ADVICE
, the parameter DB_CACHE_ADVICE
should be set toON
, and a representative workload should be running on the instance. Allow the workload to stabilize before querying theV$DB_CACHE_ADVICE
view.
想要使用v$db_cache_advice视图.db_cache_advice参数一定要设置成on状态.和一个典型的工作量应该被运行在实例上.在查询v$db_cache_advice视图之前使工作量稳定.
The following SQL statement returns the predicted I/O requirement for the default buffer pool for various cache sizes:
如下的sql语句各种不同的缓存大小跟不同的I/o关连.
SELECT size_for_estimate, buffers_for_estimate, estd_physical_read_factor, estd_physical_reads FROM V$DB_CACHE_ADVICE WHERE name = 'DEFAULT' AND block_size = (SELECT value FROM V$PARAMETER WHERE name = 'db_block_size') AND advice_status = 'ON';
The following output shows that if the cache was 212 MB, rather than the current size of 304 MB, the estimated number of physical reads would increase by a factor of 1.74 or 74%. This means it would not be advisable to decrease the cache size to 212MB.
下面输出显示如果缓存是212M,而不是当前的304M,估计物理读的数量将增加1.74,这就意味着降低到212M是不可取的.
However, increasing the cache size to 334MB would potentially decrease reads by a factor of .93 or 7%. If an additional 30MB memory is available on the host system and theSGA_MAX_SIZE
setting allows the increment, it would be advisable to increase the default buffer cache pool size to 334MB.
但是,增加缓存到334M将可能减少7%左右的物理读,如果在当前系统有额外30M的内存的可以被使用和通过设置sga_max_size的大小到增加,增加默认的调整缓存到334M是可取的.
Estd Phys Estd Phys Cache Size (MB) Buffers Read Factor Reads ---------------- ------------ ----------- ------------ 30 3,802 18.70 192,317,943 10% of Current Size 60 7,604 12.83 131,949,536 91 11,406 7.38 75,865,861 121 15,208 4.97 51,111,658 152 19,010 3.64 37,460,786 182 22,812 2.50 25,668,196 212 26,614 1.74 17,850,847 243 30,416 1.33 13,720,149 273 34,218 1.13 11,583,180 304 38,020 1.00 10,282,475 Current Size 334 41,822 .93 9,515,878 364 45,624 .87 8,909,026 395 49,426 .83 8,495,039 424 53,228 .79 8,116,496 456 57,030 .76 7,824,764 486 60,832 .74 7,563,180 517 64,634 .71 7,311,729 547 68,436 .69 7,104,280 577 72,238 .67 6,895,122 608 76,040 .66 6,739,731 200% of Current Size
This view assists in cache sizing by providing information that predicts the number of physical reads for each potential cache size. The data also includes a physical read factor, which is a factor by which the current number of physical reads is estimated to change if the buffer cache is resized to a given value.
这个视图帮助提供缓存大小的信息,估计每个可能的缓存大小的物理读.数据也包括物理读的因素,如果调整buffer cache的给定值,当前的物理读可能会发生改变.
The relationship between successfully finding a block in the cache and the size of the cache is not always a smooth distribution. When sizing the buffer pool, avoid the use of additional buffers that contribute little or nothing to the cache hit ratio. In the example illustrated in Figure 7-1, only narrow bands of increments to the cache size may be worthy of consideration.
成功的在缓存中找到一个块和缓存大小不总是正常的分配之间的关系.在设置缓存池的大小,避免增加缓存而只有提升了很少的缓存命中率,在7-1的事例说明,增加了缓存的大小只有很小幅度就值得被重新考虑.
Figure 7-1 Physical I/O and Buffer Cache Size
Examining Figure 7-1 leads to the following observations:
The benefit from increasing buffers from point A to point B is considerably higher than from point B to point C.
The decrease in the physical I/O between points A and B and points B and C is not smooth, as indicated by the dotted line in the graph.
从中可以得到从A到B增加内存比从B到C增加高很多.
减少物理读,在AB和BC是不平滑的,如图中的虚线.
V$SYSSTAT
. The buffer cache hit ratio can be used to verify the physical I/O as predicted by
V$DB_CACHE_
ADVICE
.
The statistics in Table 7-1 are used to calculate the hit ratio.
表7-1计算命中率的统计
Table 7-1 Statistics for Calculating the Hit Ratio
consistent gets from cache 在缓存中得到一致的数据 |
Number of times a consistent read was requested for a block from the buffer cache. 从高速缓存读取一个块的时间量一致性读被要求 |
db block gets from cache 从缓存中得到db块 |
Number of times a CURRENT block was requested from the buffer cache. 在高速缓存中得到当前块的时间量被要求 |
physical reads cache 缓存的物理读 |
Total number of data blocks read from disk into buffer cache. 从磁盘到缓存所有需要读的数据块 |
V$SYSSTAT
table, rather than over an interval. It is best to calculate the delta of these statistics over an interval while your application is running, then use them to determine the hit ratio.
例7-1简化了直接从v$sysstat视图中得到需要的值,而不是一个区间中.你的应用程序正在运行中,最好是计算这些统计的增量区间上.然后用它们来确认命中率.
Example 7-1 Calculating the Buffer Cache Hit Ratio
SELECT NAME, VALUE FROM V$SYSSTAT WHERE NAME IN ('db block gets from cache', 'consistent gets from cache', 'physical reads cache');
Using the values in the output of the query,calculate the hit ratio for the buffer cache with the following formula:
使用查询输出的值,计算缓存的命中率用如下的公式.
1 - (('physical reads cache') / ('consistent gets from cache' + 'db block gets from cache')