[Haskell-cafe] How to move files?

Sven Bartscher sven.bartscher at weltraumschlangen.de
Thu Apr 15 09:58:17 UTC 2021


Hi,

Am 15.04.21 um 11:27 schrieb ☂Josh Chia (謝任中):
> That would work but may not be the most efficient in all cases. On many 


> systems, /tmp is a tmpfs, which being memory-backed is more efficient 
> than a file on a physical disk or network, so writing to /tmp has 
> performance advantages.

This isn't necessarily relevant in the case the OP describes.

In the case where the target directory is also on tmpfs, writing there 
directly is just as fast as writing to /tmp first. In the case where the 
target directory is on a slower medium it is not more efficient to write 
to /tmp first, because you will still have the performance penalty once 
you copy from /tmp to the target directory.

The latter case might be slower if you first write something to the file 
and later overwrite parts of it with other content or if you decide that 
you don't need the file at all and just delete it instead of copying it. 
But you can prevent even those performance penalties by not calling 
fsync (or close) on the open file before the file contains exactly the 
data you ultimately want. That way the written content will not actually 
be written to the medium before fsync is called and you get pretty much 
the same performance as writing on tmpfs. Though controlling when fsync 
is called might be tricky if the file is not produced by your own code. 
I'm also not sure if Haskell calls fsync implicitly in some cases other 
than closing the file descriptor.

Regards
Sven



-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20210415/7e7b6bb9/attachment.sig>


More information about the Haskell-Cafe mailing list