From owner-freebsd-performance@FreeBSD.ORG Sun Jan 27 12:25:57 2008 Return-Path: Delivered-To: freebsd-performance@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id ADEBF16A417 for ; Sun, 27 Jan 2008 12:25:57 +0000 (UTC) (envelope-from 000.fbsd@quip.cz) Received: from mail.sweeplist.com (mail.sweeplist.com [77.93.199.51]) by mx1.freebsd.org (Postfix) with ESMTP id 6F18813C447 for ; Sun, 27 Jan 2008 12:25:57 +0000 (UTC) (envelope-from 000.fbsd@quip.cz) Received: from [192.168.1.2] (r3a200.net.upc.cz [213.220.192.200]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.sweeplist.com (Postfix) with ESMTPSA id 0F2EB67808; Sun, 27 Jan 2008 13:25:56 +0100 (CET) Message-ID: <479C7859.2060703@quip.cz> Date: Sun, 27 Jan 2008 13:26:01 +0100 From: Miroslav Lachman <000.fbsd@quip.cz> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 X-Accept-Language: cz, cs, en, en-us MIME-Version: 1.0 To: Thomas Hurst References: <479B1185.8020604@quip.cz> <20080127112911.GA4024@voi.aagh.net> In-Reply-To: <20080127112911.GA4024@voi.aagh.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-performance@freebsd.org Subject: Re: PHP with open_basedir performance problem 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: Sun, 27 Jan 2008 12:25:57 -0000 Thomas Hurst wrote: > * Miroslav Lachman (000.fbsd@quip.cz) wrote: > > >>I found a painful performance problem with Apache + PHP 5 when >>open_basedir directive is enabled. > > > Looks like it's lstat()/readlink() overhead. I wrote a simple bit of > PHP similar to yours, but doing 10 * 1000 require "foo/%d/%d.php" calls > from the command line: > > -% time ktrace php main.php > Real: 0:09.61 CPU: 99.8% (3.725/5.885) Page: 0 Swap: 0 I/O: (0/0) Mem: > 13704 > > -% time ktrace php -d open_basedir='/home/freaky/openbasedir/foo' > main.php > Real: 0:16.21 CPU: 86.4% (8.185/5.840) Page: 0 Swap: 0 I/O: (0/0) Mem: > 13696 > > Without open_basedir, a simple script to parse the kdump syscall times > produces: > > lstat : 1.147s/70065 calls = 0.000s per call. Max=0.000s Min=0.0000s > fcntl : 0.408s/60007 calls = 0.000s per call. Max=0.000s Min=0.0000s > sigprocmask : 0.229s/40311 calls = 0.000s per call. Max=0.000s Min=0.0000s > open : 0.223s/10085 calls = 0.000s per call. Max=0.000s Min=0.0000s > > With open_basedir: > > lstat : 4.182s/270065 calls = 0.000s per call. Max=0.005s Min=0.0000s > readlink : 2.142s/10006 calls = 0.000s per call. Max=2.020s Min=0.0000s > fcntl : 0.421s/60007 calls = 0.000s per call. Max=0.002s Min=0.0000s > close : 0.295s/10085 calls = 0.000s per call. Max=0.115s Min=0.0000s > sigprocmask : 0.237s/40311 calls = 0.000s per call. Max=0.000s Min=0.0000s > open : 0.222s/10085 calls = 0.000s per call. Max=0.000s Min=0.0000s > > The top two syscalls seem to account for most of the 6.mumble seconds of > additional runtime; presumably these are much cheaper on Linux. I did some more research on saturday - test with old PHP 5 version 5.1.4 on FreeBSD 7.0 machine. It seems there is some significant change in PHP code. (on = with open_basedir / off = without open_basedir): # real webapplication FreeBSD 6.0 + PHP 5.1.4 on / off = 6.8 / 13.5 req/s FreeBSD 7.0 + PHP 5.2.5 on / off = 3.6 / 12.9 req/s FreeBSD 7.0 + PHP 5.1.4 on / off = 8.0 / 11.8 req/s # synthetic test FreeBSD 6.0 + PHP 5.1.4 on / off = 98.3 / 144.2 req/s FreeBSD 7.0 + PHP 5.2.5 on / off = 20.6 / 245.4 req/s FreeBSD 7.0 + PHP 5.1.4 on / off = 204.3 / 239.5 req/s It demonstrates my performance problem from year ago (also reported on this list 2007-02-03 with subject "PHP Performance problem after upgrade to 5.1.6 or 5.2.0"). It is still unsolved problem, but now I know it is influenced by open_basedir. As I reported a year ago - problem occured in 5.1.6 (maybe 5.1.5 - I never tried it, I jumped from 5.1.4 to 5.1.6 or newer). Can somebody look at PHP sources of those two versions and find the "bad change"? This was reported to PHP developers by me http://bugs.php.net/bug.php?id=38940 but marked as "bogus" with comment "We only support our own sources, not ports or patched source or binary packages." Is there any chance to fix this on FreeBSD side (patch in ports) or in PHP itself? I don't want to lose performance with each "security" upgrade of PHP. :( Miroslav Lachman