博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
对PostgreSQL中bufmgr.c 中 bufs_to_lap的初步理解
阅读量:7081 次
发布时间:2019-06-28

本文共 4763 字,大约阅读时间需要 15 分钟。

开始,在代码中加入调试信息。无关部分设省略。

bool                                BgBufferSync(void)                                {                                    ……                                                                int            bufs_to_lap;                    ……                                if (saved_info_valid)                                {
//added by gaojian fprintf(stderr,"saved_info_valid true\n"); int32 passes_delta = strategy_passes - prev_strategy_passes; strategy_delta = strategy_buf_id - prev_strategy_buf_id; strategy_delta += (long) passes_delta *NBuffers; ...... if ((int32) (next_passes - strategy_passes) > 0) { fprintf(stderr,"next_pass > strategy_passes.\n"); /* we're one pass ahead of the strategy point */ bufs_to_lap = strategy_buf_id - next_to_clean; …… } else if (next_passes == strategy_passes && next_to_clean >= strategy_buf_id) {
fprintf(stderr,"next_passes == strategy_passes.\n"); /* on same pass, but ahead or at least not behind */ bufs_to_lap = NBuffers - (next_to_clean - strategy_buf_id); …… } else { fprintf(stderr,"we are behind.\n"); /* * We're behind, so skip forward to the strategy point and start * cleaning from there. */ next_to_clean = strategy_buf_id; next_passes = strategy_passes; bufs_to_lap = NBuffers; …… } } else { fprintf(stderr,"saved_info_valid false\n"); …… bufs_to_lap = NBuffers; } …… bufs_ahead = NBuffers - bufs_to_lap; …… num_to_scan = bufs_to_lap; ...... /* Execute the LRU scan */ while (num_to_scan > 0 && reusable_buffers < upcoming_alloc_est) { //added by gaojian fprintf(stderr,"num_to_scan is: %d \n",num_to_scan); int buffer_state = SyncOneBuffer(next_to_clean, true); if (++next_to_clean >= NBuffers) { next_to_clean = 0; elog(INFO,"------------------next_passes++.\n"); next_passes++; } num_to_scan--; …… } …… new_strategy_delta = bufs_to_lap - num_to_scan; new_recent_alloc = reusable_buffers - reusable_buffers_est; if (new_strategy_delta > 0 && new_recent_alloc > 0) { scans_per_alloc = (float) new_strategy_delta / (float) new_recent_alloc; smoothed_density += (scans_per_alloc - smoothed_density) / smoothing_samples; …… } ...... }

运行的结果会如何呢? 

[postgres@localhost bin]$ ./postgres -D /usr/local/pgsql/dataLOG:  database system was shut down at 2012-11-02 13:51:46 CSTsaved_info_valid false.LOG:  autovacuum launcher startedLOG:  database system is ready to accept connectionssaved_info_valid true.next_passes == strategy_passes.saved_info_valid true.next_passes == strategy_passes.saved_info_valid true.next_passes == strategy_passes.saved_info_valid true.next_passes == strategy_passes.saved_info_valid true.......

也就是说,一开始  saved_info_valid 是 false, 后来经过一次运行后,其值才发生转变,变成 true。

而之后, next_passes == startegy_passes  (其实,一开始都是零)

结束

转载地址:http://sgoml.baihongyu.com/

你可能感兴趣的文章
我的友情链接
查看>>
我的友情链接
查看>>
网页中的一些细节,在轻轻的“凹平凸”之间
查看>>
python字符串格式化输出及相关操作代码举例
查看>>
浅谈php和.net的不同(一)
查看>>
刚来报个道~!
查看>>
C++STL之二叉堆
查看>>
华为5700系列作DHCP Server的配置
查看>>
C++STL之堆排序算法
查看>>
安装KVM虚拟机并管理
查看>>
linux 单网卡绑定多IP及BONGDING的实现
查看>>
java 多线程—线程怎么来的?
查看>>
tomcat环境下服务器文件句柄耗尽(Too Many Open Files)的问题排查
查看>>
NPOI操作excel——利用反射机制,NPOI读取excel数据准确映射到数据库字段
查看>>
为什么要选择云计算?
查看>>
SSL/TLS协议详解
查看>>
我的友情链接
查看>>
使用开源组件slidingmenu_library来模拟实现人人客户端的主页侧滑界面
查看>>
Struts2学习笔记(七)之文件的下载
查看>>
我的友情链接
查看>>