首页 > 其他分享 >An Attempt at Reducing Costs of Disk I/O in Go

An Attempt at Reducing Costs of Disk I/O in Go

时间:2023-05-16 22:55:32浏览次数:391  
标签:kernel disk Attempt will AIO Go Reducing block

为了实现磁盘上的IO,go语言使用一组IO线程池用来提高CPU的使用率

本文是在go语言上尝试了接入了linux libaio,并没有发现性能的提升。

使用O_DIRECT意味着数据直接到达磁盘上,这将不能有效的利用pagecache用来加速,合并读写请求;O_DIRECT的方式对读写的大小有限制,必须是block size大小对齐(4k),而对于普通用户来讲是需要传统的字节对齐,带有pagecache缓存的API接口
可以在用户态做一层缓存,这样也会带来一些问题,pagecache是系统全局的,而如果在用户态做缓存,
每个进程需要使用自己独立的缓存,内存的消耗会比pagecache大,
缓存机制可能不如全局的pagecache看到的冷热指标更多,效果可能会有损失;
每次进程重启的时候,之前的用户态缓存就会失效,冷启动时间较长

"In order to facilitate disk I/O, Go keeps a pool of I/O threads around to improve CPU utilization while threads block during I/O."

"While we are unable to see improved performance, we believe this is due to the limited support for AIO provided by the Linux kernel"

"Green threads provide the benefit of reduced overheads present in kernel threads such as the cost of entering the kernel to perform context switches, wasted memory when reserving a whole page for stack, and green threads introduce faster alternatives to futex wait"

"The requesting Goroutines will block until the scheduler has completed their request, but the M that Goroutine is blocking on will take another G from its work queue (or steal one) and continue execution. In order to perform disk operations and continue to receive requests, our scheduler will utilize Linux Asynchronous I/O (AIO) system calls to batch requests and allow the kernel to process them in the background"

"AIO is actually implemented to be blocking due to missing functionality in Linux"

"Opening files with O DIRECT means that access to files now goes directly to disk. This implies that subsequent disk operations on the same block will perform poorly since we will no longer be using kernel disk caching mechanisms. Even worse, reads and writes must be aligned to disk block boundaries and a multiple of disk block size"

"Based on our original goal of modifying IO in Go in a user transparent manner, direct disk access is not an option, neither performance nor read/write semantics match Go's current IO API. Go users expect the traditional, cached (highly performant), byte granular operations provided by the current API"

"To summarize our results, we were unable to improve the performance of scheduling disk IO requests in Go. We believe this is not due to the costs introduced by our AIO scheduler but is due to non-existent kernel support for AIO VFS operations. The restriction to direct disk access means we are unable to modify Go in a transparent manner, direct access would introduce massive performance decreases on re-access of data, and users would not be able to modify files a byte granularity."

"we also see the possibility of layering a disk caching library on top of our scheduler in order to continue using the existing AIO in the Linux kernel while avoiding the uncached performance hits. However, there are quite a few issues with this approach. First, each Go program will now be managing disk caches so they each will be wasting their own program memory space. Second ever time a program starts, it will take time for the disk cache to repopulate. General purpose disk caching is better executed globally in the kernel, so adding caching on top of our scheduler is also not a general purpose solution"

原文链接: https://www.cnblogs.com/zhaojiangkun/p/17407131.html

标签:kernel,disk,Attempt,will,AIO,Go,Reducing,block
From: https://www.cnblogs.com/zhaojiangkun/p/17407131.html

相关文章

  • Typora+PicGo+gitHub搭建自己的免费图床
    相信很多程序员都有记录笔记或写博客的习惯,而要说到好用的写作软件,非Typora莫属,虽然他现在已开始收费了,但大家还可以下载它的旧版,而且也不会强制你更新,但是使用它在编辑的时候,它的图片默认都是保存在本地相对路径。那么就有个问题,当我要把笔记复制到博客或者其他平台的时候,图片......
  • 码良本地化gods-pen脚手架不显示组件标签问题处理
    问题描述先说下问题的现象,在进行码良本地化时,使用gods-pen创建组件时,进行到组件标签选择时,没有选项。问题猜想gods-pen是放在npm上的,应该没有改变,不会出现问题,所以组件标签可能是存在数据库中,码良初始化脚本缺少初始数据。以上猜想可以通过两种方式验证:首先从数据库中查看......
  • Django4全栈进阶之路24 项目实战(报修类型表):CKEditor富文本
    CKEditor是一个强大的富文本编辑器,可以用于在网站或应用程序中创建和编辑内容。以下是在安装和使用CKEditor的一般步骤:安装CKEditor:下载CKEditor:访问CKEditor官方网站(https://ckeditor.com/)并下载适用于您的项目的CKEditor版本。解压文件:将下载的CKEditor压缩包解压到您的项目......
  • Django-rest-framework框架
    web应用模式、API接口、接口测试工具postman、如何在浏览器中测试、restful规范、序列化反序列化、基于Django原生编写五个接口、drf介绍和快速使用、drf之APIView源码分析......
  • Django-rest-framework框架
    目录一、web应用模式二、API接口三、接口测试工具postmanpostman介绍postman下载与使用四、如何在浏览器中测试五、restful规范(重要)六、序列化反序列化七、基于Django原生编写五个接口八、drf介绍和快速使用概念特点(了解一下)安装使用drf编写五个接口九、drf之APIView源码分析基......
  • go语言调度gmp原理(3)
    go语言调度gmp原理(3)调度循环调度器启动之后,go语言运行时会调用runtime.mstart和runtime.mstart1,前者会初始化g0的stackguard0和stackguard1字段,后者会初始化线程并调用runtime.schedule进入调度循环funcschedule(){ mp:=getg().m ifmp.locks!=0{ throw("schedul......
  • go语言调度gmp原理(2)
    go语言调度gmp原理(2)创建goroutine通过runtime.newproc函数调用,runtime.newproc的入参是参数大小和表示函数的指针funcval,它会获取goroutine以及调用方的程序计数器,然后调用runtime.newproc1函数获取新的goroutine、结构体、将其加入处理器的运行队列,并在满足条件时调用runtime......
  • Golang接收者方法语法糖
    1、概述在《Golang常用语法糖》这篇博文中我们讲解Golang中常用的12种语法糖,在本文我们主要讲解下接收者方法语法糖。在介绍Golang接收者方法语法糖前,先简单说下Go语言的指针(Pointer),大致上理解如下:变量名前的& 符号,是取变量的内存地址,不是取值;数据类型前的* 符号,代表......
  • django系列-服务和环境配置(陆续完善中···)
    一、Mysql1、安装服务端yuminstallmariadb-server-ymariadb-server.x86_641:5.5.68-1.el7#版本2、安装客户端yuminstallmariadb-y#软件包1:mariadb-5.5.68-1.el7.x86_64已安装并且是最新版本3、服务配置4、帐号初始化二、Redis三、Python四、虚拟环境......
  • 【Go新手起步01】5步完成 vscode的go插件安装跟激活。
     首先下载vscode,进行两个插件安装,如图所示 然后下载go语言,在官网https://go.dev/doc/install下载 cmd打开,输入goversion验证下载是否成功。在dos页面输入goenv-wGO111MODULE=on                goenv-wGOPROXY=https://goproxy.cn,di......