From owner-freebsd-questions@FreeBSD.ORG Wed Jun 11 19:43:28 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EA11A1065679 for ; Wed, 11 Jun 2008 19:43:28 +0000 (UTC) (envelope-from kirk@strauser.com) Received: from kanga.honeypot.net (kanga.honeypot.net [206.29.77.83]) by mx1.freebsd.org (Postfix) with ESMTP id 7DB768FC15 for ; Wed, 11 Jun 2008 19:43:27 +0000 (UTC) (envelope-from kirk@strauser.com) Received: from localhost (localhost [127.0.0.1]) by kanga.honeypot.net (Postfix) with ESMTP id 2ED395DCD7D for ; Wed, 11 Jun 2008 14:42:57 -0500 (CDT) X-Virus-Scanned: amavisd-new at honeypot.net Received: from kanga.honeypot.net ([127.0.0.1]) by localhost (kanga.honeypot.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id H3WReyMqcV8C for ; Wed, 11 Jun 2008 14:42:53 -0500 (CDT) Received: from janus.daycos.com (janus.daycos.com [10.45.12.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by kanga.honeypot.net (Postfix) with ESMTPSA id 71E9C5DCD79 for ; Wed, 11 Jun 2008 14:42:53 -0500 (CDT) From: Kirk Strauser To: freebsd-questions@freebsd.org Date: Wed, 11 Jun 2008 14:42:50 -0500 User-Agent: KMail/1.9.9 References: <200806051508.29424.kirk@strauser.com> In-Reply-To: <200806051508.29424.kirk@strauser.com> X-Face: T+/_{qmjgbosI0J/e83I~w[&VF'w)!((xEpj///^bA/6?jHHS?nq+T8_+`nh"WnEWCWG, \}]Y2$)) =?utf-8?q?vLVz4ACChrEcb=7DCO=5EtYmMG=5C=0A=09ts=2Em=3F=5B7=5B6OwE*dAJ*9f+m?= =?utf-8?q?X=2E7R32qeN=5EDJ=5C?=(k@evW?IRQCy.^ MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200806111442.50935.kirk@strauser.com> Subject: Re: Poor read() performance, and I can't profile it X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Jun 2008 19:43:29 -0000 On Thursday 05 June 2008, Kirk Strauser wrote: > I was testing the same software on my desktop PC when I noticed that it > ran *much* faster, and found that it was spending only about 1% as much > time in the kernel on Linux as it was on FreeBSD. I'm almost ready to give up on this. I've gone as far as completely rewriting the original C++ program into straightforward C, and still the performance is terrible on FreeBSD versus Linux. On Linux: $ time ./cdbf /tmp/invoice.dbf >/dev/null ./cdbf /tmp/invoice.dbf > /dev/null 42.65s user 20.09s system 71% cpu 1:28.15 total On FreeBSD: Also note that on the FreeBSD machine, I have enough RAM that to buffer the entire file, and in practice gstat shows that the drives are idle for subsequent runs after the first one. Right now my code looks a lot like: for(recordnum = 0; recordnum < recordcount; recordnum++) { buf = malloc(recordlength); fread(buf, recordlength, 1, dbffile); /* Do stuff with buf */ memoblock = getmemoblock(buf); /* Skip to the requested block if we're not already there */ if(memoblock != currentmemofileblock) { currentmemofileblock = memoblock; fseek(memofile, currentmemofileblock * memoblocksize, SEEK_SET); } memohead = malloc(memoblocksize); fread(memohead, memoblocksize, 1, memofile); currentmemofileblock++; /* Do stuff with memohead */ free(memohead); free(buf); } ...where recordlength == 13 in this one case. Given that the whole file is buffered in RAM, the small reads shouldn't make a difference, should they? I've played with setvbuf() and it shaves off a few percent of runtime, but nothing to write home about. Now, memofile gets quite a lot of seeks. Again, that shouldn't make too much of a difference if it's already buffered in RAM, should it? setvbuf() on that file that gets lots of random access actually made performance worse. What else can I do to make my code run as well on FreeBSD as it does on a much wimpier Linux machine? I'm almost to the point of throwing in the towel and making a Linux server to do nothing more than run this one program if I can't FreeBSD's performance more on parity, and I honestly never thought I'd be considering that. I'll gladly give shell access with my code and sample data files if anyone is interested in testing it. -- Kirk Strauser