管道与临时文件 [英] Pipe vs. Temporary File

查看:114
本文介绍了管道与临时文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下两者之间是否存在较大的性能差异?

Is there a big performance difference between:

  • 进程A写入临时文件,进程B读取该文件
  • 处理A写入管道,然后处理B从该管道读取

我很好奇知道Windows和* nix的答案是什么.

I'm curious to know what the answer is for both Windows and *nix.

我应该问过:缓冲区缓存是否消除了临时文件和管道之间的差异?

I should have asked: Does the buffer cache eliminate the difference between a temp file and a pipe?

推荐答案

一个很大的不同是,通过管道,进程A和B可以同时运行,因此B在A完成之前就可以处理A的输出.生产它.而且,管道的大小是有限的,因此A将无法产生比B所消耗的数据更多的数据.它将等待B赶上.

One big difference is that with the pipe, processes A and B can be running concurrently, so that B gets to work on the output from A before A has finished producing it. Further, the size of the pipe is limited, so A won't be able to produce vastly more data than B has consumed; it will be made to wait for B to catch up.

如果数据量很大,则写入临时文件将涉及磁盘活动,即使仅用于创建然后销毁文件也是如此.数据很可能会保留在内存缓冲池中-因此那里没有磁盘I/O-即使是非常大的文件也是如此.写入管道从不"涉及写入磁盘.

If the volume of data is big, then writing to the temporary file involves disk activity, even if only for creating and then destroying the file. The data might well stay in the in-memory buffer pools - so no disk I/O there - even for surprisingly large files. Writing to the pipe 'never' involves writing to disk.

这篇关于管道与临时文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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