From owner-freebsd-performance@FreeBSD.ORG Tue Sep 26 17:03:07 2006 Return-Path: X-Original-To: freebsd-performance@freebsd.org Delivered-To: freebsd-performance@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8FC4616A49E for ; Tue, 26 Sep 2006 17:03:07 +0000 (UTC) (envelope-from wmoran@collaborativefusion.com) Received: from mx00.pub.collaborativefusion.com (mx00.pub.collaborativefusion.com [206.210.89.199]) by mx1.FreeBSD.org (Postfix) with ESMTP id 11F6D43D55 for ; Tue, 26 Sep 2006 17:03:01 +0000 (GMT) (envelope-from wmoran@collaborativefusion.com) Received: from collaborativefusion.com (mx01.pub.collaborativefusion.com [206.210.89.201]) (TLS: TLSv1/SSLv3,256bits,AES256-SHA) by wingspan with esmtp; Tue, 26 Sep 2006 13:03:01 -0400 id 00056421.45195D45.0000BC46 Received: from Internal Mail-Server (206.210.89.202) by mx01 (envelope-from wmoran@collaborativefusion.com) with AES256-SHA encrypted SMTP; 26 Sep 2006 13:01:08 -0400 Date: Tue, 26 Sep 2006 13:03:00 -0400 From: Bill Moran To: Mark Bucciarelli Message-Id: <20060926130300.3dc4b06a.wmoran@collaborativefusion.com> In-Reply-To: <20060926154643.GA3064@rabbit> References: <20060926154643.GA3064@rabbit> Organization: Collaborative Fusion X-Mailer: Sylpheed version 2.2.7 (GTK+ 2.8.20; i386-portbld-freebsd6.1) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: freebsd-performance@freebsd.org Subject: Re: Why are disk writes so slow? X-BeenThere: freebsd-performance@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Performance/tuning List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Sep 2006 17:03:07 -0000 In response to Mark Bucciarelli : > I am reading Richard Stevens' "Advanced Programming in the UNIX > Environment," a most excellent book. > > Out of curiosity, I tried his I/O efficiency program on my IBM > A30 Thinkpad, running 6.0-RELEASE with default tuning parameters. > The test program reads file on stdin and writes to stdout, and > you modify bufsize to watch how time changes. > > As in his example (with a bufsize of 8192), > > time ./a.out < 1.5M-testfile > /dev/null > > runs five times faster than (clock time) > > time ./a.out < 1.5M-testfile > /a.out.out > > Can someone explain to me why writing is five times as slow as > writing? What's going on in the computer? > > The file is not O_SYNC, so it can't be validating the data on the > disk. > > Later in the same chapter, he shows the impact of O_SYNC flag. I > re-ran this experiment too, and while everything is two orders of > magnitude faster than his times in the book, the relative speed > of writing with O_SYNC is three times slower. > > 1993 2006 > ----- ---- > normal write 2.3s .023s > O_SYNC 13.4s .364s > slowdow factor 5.8 15.8 > > Is this all b/c disks are so much larger? I'm rather confused as to exactly what your question is ... First off, writes are slower than reads if the data you're reading is already cached in RAM. Unless you have _very_ little RAM in your machine, then anything that takes .023s to write is going to be able to fit entirely in the buffer cache, thus repeated access doesn't require any real disk activity. Secondly, as to why Stevens saw less of a slowdown with O_SYNC than you did -- I doubt there's one easy answer. Discs are manufactured differently now than they were in 93, and there's even a huge difference between different brands and different types (i.e. SCSI/SATA) in addition to the differences in hardware connecting the disks, and the drivers for that hardware. There are dozens of places where the difference could be occurring. I would guess that the drive itself does write caching, and this heavily optimizes async writes, but can't improve the performance of sync writes any. -- Bill Moran Collaborative Fusion Inc.