热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

bdblogfile预设长度的性能优化

postgres同理的code:backendcdbcdblogsync.c,createZeroFilledNewFile()**Zero-fillt

postgres 同理的code:

backend/cdb/cdblogsync.c, createZeroFilledNewFile()

    /*
     * Zero-fill the file.    We have to do this the hard way to ensure that all
     * the file space has really been allocated --- on platforms that allow
     * "holes" in files, just seeking to the end doesn't allocate intermediate
     * space.  This way, we know that we have all the space and (after the
     * fsync below) that all the indirect blocks are down on disk.    Therefore,
     * fdatasync(2) or O_DSYNC will be sufficient to sync future writes to the
     * log file.
     */
    MemSet(zbuffer, 0, sizeof(zbuffer));

 

 

看代码随手记:log_put.c, __log_write()

    /*
     * If we're writing the first block in a log file on a filesystem that
     * guarantees unwritten blocks are zero-filled, we set the size of the
     * file in advance.  This increases sync performance on some systems,
     * because they don't need to update metadata on every sync.
     *
     * Ignore any error -- we may have run out of disk space, but that's no
     * reason to quit.
     */
#ifdef HAVE_FILESYSTEM_NOTZERO
    if (lp->w_off == 0 && !__os_fs_notzero()) {
#else
    if (lp->w_off == 0) {
#endif
        (void)__db_file_extend(env, dblp->lfhp, lp->log_size);
        if (F_ISSET(dblp, DBLOG_ZERO))
            (void)__db_zero_extend(env, dblp->lfhp,
                 0, lp->log_size/lp->buffer_size, lp->buffer_size);

    }

我的理解:在flush log时使用fdatasync, 若log文件长度发生变化, 则仍需要写文件 metadata。

https://linux.die.net/man/2/fdatasync

fdatasync() is similar to fsync(), but does not flush modified metadata unless that metadata is needed in order to allow a subsequent data retrieval to be correctly handled. For example, changes to st_atime or st_mtime (respectively, time of last access and time of last modification; see stat(2)) do not require flushing because they are not necessary for a subsequent data read to be handled correctly. On the other hand, a change to the file size (st_size, as made by say ftruncate(2)), would require a metadata flush. 


推荐阅读
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • Linux服务器密码过期策略、登录次数限制、私钥登录等配置方法
    本文介绍了在Linux服务器上进行密码过期策略、登录次数限制、私钥登录等配置的方法。通过修改配置文件中的参数,可以设置密码的有效期、最小间隔时间、最小长度,并在密码过期前进行提示。同时还介绍了如何进行公钥登录和修改默认账户用户名的操作。详细步骤和注意事项可参考本文内容。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • 本文介绍了贝叶斯垃圾邮件分类的机器学习代码,代码来源于https://www.cnblogs.com/huangyc/p/10327209.html,并对代码进行了简介。朴素贝叶斯分类器训练函数包括求p(Ci)和基于词汇表的p(w|Ci)。 ... [详细]
  • node.jsrequire和ES6导入导出的区别原 ... [详细]
  • 本文介绍了解决mysql 5.1启动问题的方法,通过修改my.ini文件中的相关配置,包括innodb_data_home_dir和skip-innodb等,可以解决启动问题。同时还介绍了如何调整内存池来存储metadata信息。 ... [详细]
  • GO语言 包 if..else.. for循环 switch 数组
    包1.什么是包1.新建一个文件夹,内部写很多go文件,但是包名必须一致,改文件夹就是一个包2.作用和优点包用于组织Go源代码,提供了更好的可重用性与可读性。由于包提供了代码的封装, ... [详细]
  • Apple iPad:过渡设备还是平板电脑?
    I’vebeenagonizingoverwhethertopostaniPadarticle.Applecertainlydon’tneedmorepublicityandthe ... [详细]
  • 语法必须遵守的语法推荐遵守语法不做要求文件格式文件应该使用Unicode(UTF-8)编码保存。同时不要使用字节序标记(BOM)。与UTF-16和 ... [详细]
  • linuxmint20.3 安装anaconda、换源及创建新环境
    本文用来记录linuxmint20.3安装anaconda、换源及创建新环境的过程,同时记录一些相关命令目录anaconda安装相关命令创建新环境显示问题 ... [详细]
  • Spring源码解密之默认标签的解析方式分析
    本文分析了Spring源码解密中默认标签的解析方式。通过对命名空间的判断,区分默认命名空间和自定义命名空间,并采用不同的解析方式。其中,bean标签的解析最为复杂和重要。 ... [详细]
  • 本文介绍了数据库的存储结构及其重要性,强调了关系数据库范例中将逻辑存储与物理存储分开的必要性。通过逻辑结构和物理结构的分离,可以实现对物理存储的重新组织和数据库的迁移,而应用程序不会察觉到任何更改。文章还展示了Oracle数据库的逻辑结构和物理结构,并介绍了表空间的概念和作用。 ... [详细]
  • 2019独角兽企业重金招聘Python工程师标准
    本文介绍了2019独角兽企业对Python工程师的招聘标准,包括在AndroidManifest中定义meta-data的方法和获取meta-data值的代码。同时提供了获取meta-data值的具体实现方法。转载文章链接:https://my.oschina.net/u/244918/blog/685127 ... [详细]
  • 初始化_SQL Server 2017 AlwaysOn AG 自动初始化
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了SQLServer2017AlwaysOnAG自动初始化相关的知识,希望对你有一定的参考价值。 ... [详细]
author-avatar
谢淑萍066347
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有