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

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

问题描述

在以下情况下,顺序写入和随机写入有什么区别:-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.

推荐答案

当人们谈论 sequentialrandom 写入文件时,他们通常是在区分在没有中间查找的写入(顺序")与查找-写入-查找-写入-查找-写入等模式(随机")之间.

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 毫秒.将数据顺序写入同一个磁盘大约需要每 MB 30 毫秒.因此,如果您将 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.

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

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天全站免登陆