[#58149] [ruby-trunk - Feature #9076][Open] New one-argument block syntax: &. — "asterite (Ary Borenszweig)" <ary@...>

23 messages 2013/11/04

[#58176] [ruby-trunk - Bug #9082][Open] popen3 hangs when stderr gets lots of output — "rosenfeld (Rodrigo Rosenfeld Rosas)" <rr.rosas@...>

15 messages 2013/11/05

[#58207] [ruby-trunk - Bug #9089][Open] rb_fix2uint no longer raises a RangeError when given negative values — "NoKarma (Arthur Schreiber)" <schreiber.arthur@...>

9 messages 2013/11/06

[#58243] [ruby-trunk - Feature #9098][Open] Indent heredoc against the left margin by default when "indented closing identifier" is turned on. — "sikachu (Prem Sichanugrist)" <s@...>

24 messages 2013/11/09

[#58306] [ruby-trunk - Bug #9106][Open] 'gem install' doesn't copy .so files of ext libs — "tagomoris (Satoshi TAGOMORI)" <tagomoris@...>

15 messages 2013/11/13

[#58324] [ruby-trunk - Feature #9108][Open] Hash sub-selections — "wardrop (Tom Wardrop)" <tom@...>

28 messages 2013/11/14

[#58342] [ruby-trunk - Feature #9112][Open] Make module lookup more dynamic (Including modules into a module after it has already been included) — "PragTob (Tobias Pfeiffer)" <pragtob@...>

16 messages 2013/11/14

[#58350] [ruby-trunk - Feature #9113][Open] Ship Ruby for Linux with jemalloc out-of-the-box — "sam.saffron (Sam Saffron)" <sam.saffron@...>

59 messages 2013/11/15

[#58374] [ruby-trunk - Bug #9115][Open] Logger traps all exceptions; breaks Timeout — "cphoenix (Chris Phoenix)" <cphoenix@...>

10 messages 2013/11/16

[#58375] [ruby-trunk - Feature #9116][Open] String#rsplit missing — "artagnon (Ramkumar Ramachandra)" <artagnon@...>

12 messages 2013/11/16

[#58396] [ruby-trunk - Bug #9121][Open] [PATCH] Remove rbtree implementation of SortedSet due to performance regression — "xshay (Xavier Shay)" <contact@...>

15 messages 2013/11/18

[#58404] [ruby-trunk - Feature #9123][Open] Make Numeric#nonzero? behavior consistent with Numeric#zero? — "sferik (Erik Michaels-Ober)" <sferik@...>

40 messages 2013/11/18

[#58411] [ruby-trunk - Bug #9124][Open] TestSocket errors in test-all on Arch 64-bit — "jonforums (Jon Forums)" <redmine@...>

14 messages 2013/11/18

[#58438] [ruby-trunk - Bug #9129][Open] Regression in support for IPv6 literals in URIs with Net::HTTP — "kallistec (Daniel DeLeo)" <dan@...>

11 messages 2013/11/19

[#58545] [ruby-trunk - Feature #9145][Open] Queue#pop(true) return nil if empty instead of raising ThreadError — "jsc (Justin Collins)" <redmine@...>

9 messages 2013/11/24

[#58653] [ruby-trunk - Bug #9170][Open] Math.sqrt returns different types when mathn is included; breaks various gems - this bug can be reproduced in Ruby 1.8 as well — "kranzky (Jason Hutchens)" <JasonHutchens@...>

7 messages 2013/11/28

[ruby-core:58680] [ruby-trunk - Bug #9153] IO#flush causes unnecessary fsync on Windows

From: "hsbt (Hiroshi SHIBATA)" <shibata.hiroshi@...>
Date: 2013-11-29 09:51:09 UTC
List: ruby-core #58680
Issue #9153 has been updated by hsbt (Hiroshi SHIBATA).

Assignee set to usa (Usaku NAKAMURA)


----------------------------------------
Bug #9153: IO#flush causes unnecessary fsync on Windows
https://bugs.ruby-lang.org/issues/9153#change-43247

Author: snaury (Alexey Borzenkov)
Status: Open
Priority: Normal
Assignee: usa (Usaku NAKAMURA)
Category: core
Target version: 
ruby -v: ruby 2.0.0p353 (2013-11-22) [i386-mingw32]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


On Windows calling IO#flush is effectively identical to calling IO#fsync, i.e. contents of the file are committed to disk platters instead of just being flushed. I traced it back to bug #776 where the original "bug" was worked around by forcing fsync to happen on flushes. Unfortunately due to this change IO#flush becomes unusable, as fsync are very expensive, e.g. on one of my machines I had fsync taking up to 150ms and I heard stories of machines where fsync takes on the order of 2000ms.

Originally I discovered this problem where my script would print out a couple hundred lines using Kernel#p, and to my astonishment when I redirected to a file script started taking several seconds to complete.

The problem with original fix (adding fsync during flush) is that there was no issue to begin with. It's not even due to Windows per se why file size is not updated, it's due to how NTFS driver is optimized to not update file size (in the directory entry) until the file is closed. Please read this blog post on details about what's going on: http://blogs.msdn.com/b/oldnewthing/archive/2011/12/26/10251026.aspx

What I mean is that IO#flush without fsync properly flushes all the data to the file, you can read all this data from another process, the only thing that is not updated is directory entry metadata (until the file is closed), which is by design, it's how it's supposed to work on Windows with NTFS filesystem. The workaround (i.e. fsync) working is more of an accident, it's just when OS is forced to write all that data to disk it currently tries to create a consistent picture and updates directory metadata as well, there's nothing saying that it would keep doing that in the future. Worst of all is that original bug was about temporary files, and fsync during IO#flush forces them to be written to disk, even if they are short lived.

Please remove fsync from IO#flush on Windows. You shouldn't workaround correct Windows behavior and make it unbearably slow. Instead, people need to learn how filesystems work on Windows and learn to close files if they are finished writing to them and really need directory metadata to be updated (however most of the time people shouldn't care about directory metadata like file size, it's just some arbitrary cached value and is not necessarily true all of the time).


-- 
http://bugs.ruby-lang.org/

In This Thread