From owner-freebsd-hackers Mon Jan 10 18: 6:19 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from monty.pp.sci.fi (monty.pp.sci.fi [195.74.24.156]) by hub.freebsd.org (Postfix) with ESMTP id 834B2152F0 for ; Mon, 10 Jan 2000 18:06:08 -0800 (PST) (envelope-from monty@monty.pp.sci.fi) Received: (from monty@localhost) by monty.pp.sci.fi (8.9.3/8.8.7) id EAA22715; Tue, 11 Jan 2000 04:08:22 +0200 From: Michael Widenius MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <14458.37014.846894.473677@monty.pp.sci.fi> Date: Tue, 11 Jan 2000 04:08:22 +0200 (EET) To: "Scott Hess" Cc: , Subject: Concept check: iothreads addition to pthreads for MYSQL+FreeBSD. In-Reply-To: <1a6101bf5bc1$4e364b20$1e80000a@avantgo.com> References: <1a6101bf5bc1$4e364b20$1e80000a@avantgo.com> X-Mailer: VM 6.72 under 21.1 (patch 7) "Biscayne" XEmacs Lucid Reply-To: monty@tcx.se Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG >>>>> "Scott" == Scott Hess writes: Scott> Recently I was tasked to find a way to scale up our MYSQL server, running Scott> MYSQL3.22.15 on FreeBSD3.3. I've been testing a hardware RAID solution, Scott> and found that with 6 disks in a RAID5 configuration, the system was only Scott> perhaps 30% faster than when running on a single disk. [The 6 disks in the Scott> RAID5 are the same model as the single-disk test I was comparing against.] Scott> Experimentation determined that pthreads was the problem. FreeBSD's Scott> implementation of pthreads using a select() loop, and select() always says Scott> that disk I/O is ready to proceed, and disk I/O never return EWOULDBLOCK. Scott> Essentially, pthreads was serializing the MYSQL read() requests, and if the Scott> dataset exceeds memory size, performance becomes entirely seek bound. Scott> I've implemented a rough fix, which is to rfork() processes which I label Scott> "iothreads" to handle the disk I/O. The parent process running pthreads Scott> has a socketpair() to each of the iothreads. The iothreads wait for Scott> requests on the socketpair, and since socketpairs can block, pthreads can Scott> handle them efficiently. This essentially allows me to turn blocking disk Scott> I/O calls into non-blocking calls. Having multiple pending seeks turns out Scott> to be a huge win for MYSQL, allowing it to scale much better as disks are Scott> added to the RAID5 array. Scott> Unfortunately, I'm concerned about using this code in production, because Scott> it needs a fair amount of cleanup to handle signals and administrative Scott> functions correctly. For this reason and others, I'm starting a project to Scott> move it into the pthreads library itself. Before I embark on that effort, Scott> I have a couple questions: Scott> 1) Does this seem like a reasonable approach? [It _works_, and well. But Scott> it tastes strongly of hack.] If you can't get the freebsd team to add blocking reads, then this may one solution to speed this up. Scott> 2) Does anyone have suggestions for a solution that will be cleaner and Scott> won't take man-months to implement? [Which is the redeeming quality of Scott> what I've got - it took me two days to zero in on a very workable Scott> solution.] Everything depends of how neatly you can get this into the FreeBSD kernel and if you can get the FreeBSD developers to incorporate your patch in the offical kernel. If not, then this may be a problem. Scott> 3) Is anyone working on something I might leverage off of in this area? Scott> [For instance, a select()-based interface to async I/O? Or support for Scott> blocking disk I/O in select() and read()?] blocking reads would probably be the best option. Scott> 4) Is there anyone willing to commit to testing my modified pthreads Scott> library against MYSQL? [I'll be stress testing it quite heavily, of Scott> course. It would probably also be testable against Squid with async I/O Scott> and multithreaded Apache 2.0.] Sorry, but I don't have a FreeBSD system available that I can use for testing (and I don't have any real good application to use for testing this). Regards, Monty To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message