顺序写入和随机写入之间的区别 [英] Difference between sequential write and random write

查看:344
本文介绍了顺序写入和随机写入之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下情况下,顺序写入和随机写入之间有什么区别? 1)基于磁盘的系统 2)基于SSD [Flash Device]的系统

What is the difference between sequential write and random write in case of :- 1)Disk based systems 2)SSD [Flash Device ] based systems

当应用程序写入某些内容并且需要在磁盘上修改信息/数据时,我们如何知道它是顺序写入还是随机写入.到目前为止,不能将写入区分为顺序"写入还是随机".写入将被缓冲,然后在我们刷新缓冲区时将其应用于磁盘.

When the application writes something and the information/data needs to be modified on the disk then how do we know whether it is a sequential write or a random write.As till this point a write cannot be distinguished as "sequential" or "random".The write is just buffered and then applied to the disk when we will flush the buffer.

如果我错了,请纠正我.

Please correct me if I am wrong.

推荐答案

当人们谈论顺序随机写入文件时,他们通常会做出区分在没有中间搜寻的情况下(顺序")与搜寻-写入-搜寻-写入-搜寻-写入"模式(随机")之间的冲突.

When people talk about sequential vs random writes to a file, they're generally drawing a distinction between writing without intermediate seeks ("sequential"), vs. a pattern of seek-write-seek-write-seek-write, etc. ("random").

在传统的基于磁盘的系统中,这种区别非常重要,在传统的基于磁盘的系统中,每个磁盘寻道大约需要10毫秒.将数据顺序写入同一磁盘大约需要30毫秒/MB.因此,如果您顺序将100MB数据写入磁盘,则大约需要3秒钟.但是,如果您进行100次随机写入,每个随机写入1MB,则总共将花费4秒(实际写入需要3秒,而所有查找都需要10ms * 100 == 1秒).

The distinction is very important in traditional disk-based systems, where each disk seek will take around 10ms. Sequentially writing data to that same disk takes about 30ms per MB. So if you sequentially write 100MB of data to a disk, it will take around 3 seconds. But if you do 100 random writes of 1MB each, that will take a total of 4 seconds (3 seconds for the actual writing, and 10ms*100 == 1 second for all the seeking).

随着每次随机写操作变得越来越小,您为磁盘搜索付出的代价越来越多.在极端情况下,如果您执行1亿次随机1字节写入操作,则所有实际写入操作仍将净赚3秒,但是您现在仍有 11.57天值得尝试!因此,很明显,您的写作是顺序写作还是随机写作的程度确实会影响完成任务所需的时间.

As each random write gets smaller, you pay more and more of a penalty for the disk seeks. In the extreme case where you perform 100 million random 1-byte writes, you'll still net 3 seconds for all the actual writes, but you'd now have 11.57 days worth of seeking to do! So clearly the degree to which your writes are sequential vs. random can really affect the time it takes to accomplish your task.

关于闪光灯的情况有些不同.使用闪存时,您没有必须移动的物理磁盘头. (这是传统磁盘10ms寻道成本的来源).但是,闪存设备通常具有较大的页面大小(根据 wikipedia,最小的典型"页面大小约为512字节. ,并且4K页面大小似乎也很常见).因此,如果您要写入少量字节,则Flash仍然会产生开销,因为您必须读出整个页面,修改要写入的字节,然后再写回整个页面.我不知道我头顶上闪过的特征数字.但是经验法则是,在闪存上,如果每次写入的大小通常都与设备的页面大小相当,那么随机写入和顺序写入之间不会有太大的性能差异.如果与设备页面大小相比,每次写操作都小,那么在执行随机写操作时您会看到一些开销.

The situation is a bit different when it comes to flash. With flash, you don't have a physical disk head that you must move around. (This is where the 10ms seek cost comes from for a traditional disk). However, flash devices tend to have large page sizes (the smallest "typical" page size is around 512 bytes according to wikipedia, and 4K page sizes appear to be common as well). So if you're writing a small number of bytes, flash still has overhead in that you must read out an entire page, modify the bytes you're writing, and then write back the entire page. I don't know the characteristic numbers for flash off the top of my head. But the rule of thumb is that on flash if each of your writes is generally comparable in size to the device's page size, then you won't see much performance difference between random and sequential writes. If each of your writes is small compared to the device page size, then you'll see some overhead when doing random writes.

现在,对于上述所有内容,确实在应用程序层中隐藏了很多东西.内核,磁盘/闪存控制器等中存在一些层,例如在顺序"编写过程中可能会插入非显而易见的寻道.但是在大多数情况下,在应用程序层顺序看"(无寻道,许多连续的I/O)的写入将具有顺序写入性能,而在应用程序层随机看"的写入将具有(通常更差)的性能.随机写入性能.

Now for all of the above, it's true that at the application layer much is hidden from you. There are layers in the kernel, disk/flash controller, etc. that could for example interject non-obvious seeks in the middle of your "sequential" writing. But in most cases, writing that "looks" sequential at the application layer (no seeks, lots of continuous I/O) will have sequential-write performance while writing that "looks" random at the application layer will have the (generally worse) random-write performance.

这篇关于顺序写入和随机写入之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆