Re: [PHP] Performance / AB issue?
> >> On Fri, May 11, 2012 at 9:53 AM, Camilo Sperberg >> wrote: >>> >>> >>> Sent from my iPhone 5 Beta [Confidential use only] >>> >>> On 11 mei 2012, at 07:09, "Lars Nielsen" wrote: >>> > > On 10 mei 2012, at 23:26, Lars Nielsen wrote: > >> >>> >>> >>> Sent from my iPhone 5 Beta [Confidential use only] >>> >>> On 10 mei 2012, at 17:40, Matijn Woudt wrote: >>> On Thu, May 10, 2012 at 9:04 AM, Lars Nielsen wrote: > Hi there, > > I have apache-2.22/php 5.3.10 set up on a dedicated server but I > have > a > strange issue. > > I have made a Drupal 7 site with a mysql db. > > If I stress-test the site with : ab -c 1 -n 150 http://sitename/ > it > works > fine. > If I stress-test the site with : ab -c 2 -n 20 http://sitename/ > it > kills > apache. > If I stress-test the site with : ab -c 50 -n 1500 > http://sitename/static.html it works fine. > > I have set apache's errorlog to debug. But it writes nothing, > either > in > the virtualhost or in the server-file. > > Can anyone give a hint about what can be wrong? > > What do you mean with 'kills apache', does it terminate apache or does apache hang (eg. 100% cpu), and respond normal after the stress test is over? And what is the index of your site? A php script, or..? Do you have ModRewrite redirects etc? - Matijn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php >>> >>> Can you visit the site normally? Try less verbosing in apache, that >>> is >>> pretty intensive, but as you can benchmark a static file well (with >>> moderate high settings), i assume it is some configuration problem >>> in >>> drupal. >>> >>> Greeting. >>> -- >>> PHP General Mailing List (http://www.php.net/) >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >>> >> >> Hi, >> >> I can visit the site normaly, but with 2-3 concurrent ab test it >> fails. >> seen from 'ps' and 'htop' it seems that both apache and mysql >> continues >> to >> run normaly but it doesnt respond. >> >> If i run netstat -an after the test it shows this : >> Active Internet connections (servers and established) >> Proto Recv-Q Send-Q Local Address      Foreign Address >>  State >> tcp     0    0 0.0.0.0:22        0.0.0.0:* >>     LISTEN >> tcp     0    0 127.0.0.1:25       0.0.0.0:* >>  >>    LISTEN >> tcp     0    0 127.0.0.1:3306      0.0.0.0:*  >>    LISTEN >> tcp     0    0 0.0.0.0:80        0.0.0.0:* >>     LISTEN >> tcp     1    0 x.x.x.x:80     x.x.x.x:39237  >> CLOSE_WAIT >> tcp     1    0 x.x.x.x:80     x.x.x.x:39236  >>  CLOSE_WAIT >> tcp     0    0 x.x.x.x:22     x.x.x.x:47383  >>  ESTABLISHED >> tcp     0    0 127.0.0.1:80      >>  127.0.0.1:34775 >> ESTABLISHED >> tcp     1    0 x.x.x.x:80     x.x.x.x:39300  >>  CLOSE_WAIT >> ESTABLISHED >> tcp     0    0 127.0.0.1:34775     127.0.0.1:80 >> ESTABLISHED >> tcp     0    0 x.x.x.x:80     x.x.x.x:39330  >>  ESTABLISHED >> tcp6    0    0 :::22          :::* >> LISTEN >> tcp6    0    0 ::1:25          :::* >> LISTEN >> >> So it does seem like there should be room for new tcp connections? >> >> But if I restart apache then it works again... So I guess it is a >> apache/php configuration issue? >> >> -- >> Med venlig hilsen / Best Regards >> >> LFWeb >> Lars Nielsen >> Thorsensvej 30 >> 4800 Nykøbing Falster >> Tlf: +45 20 64 85 76 >> email : l...@lfweb.dk >> www : http://www.lfweb.dk >> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> > > Have you tried benchmarking a really simple php page, such as > > > > ? > > It that works, than it is definitely an issue in Drupal's > configuration > and not in PHP/Apache. Additionally, you could check what happens > when > you > try to establish a session or make a database call to rule out those > as > well, just make really simple tests that you know wouldn't fail
Re: [PHP] Performance / AB issue?
> On Fri, May 11, 2012 at 9:53 AM, Camilo Sperberg > wrote: >> >> >> Sent from my iPhone 5 Beta [Confidential use only] >> >> On 11 mei 2012, at 07:09, "Lars Nielsen" wrote: >> >>> On 10 mei 2012, at 23:26, Lars Nielsen wrote: > >> >> >> Sent from my iPhone 5 Beta [Confidential use only] >> >> On 10 mei 2012, at 17:40, Matijn Woudt wrote: >> >>> On Thu, May 10, 2012 at 9:04 AM, Lars Nielsen >>> wrote: Hi there, I have apache-2.22/php 5.3.10 set up on a dedicated server but I have a strange issue. I have made a Drupal 7 site with a mysql db. If I stress-test the site with : ab -c 1 -n 150 http://sitename/ it works fine. If I stress-test the site with : ab -c 2 -n 20 http://sitename/ it kills apache. If I stress-test the site with : ab -c 50 -n 1500 http://sitename/static.html it works fine. I have set apache's errorlog to debug. But it writes nothing, either in the virtualhost or in the server-file. Can anyone give a hint about what can be wrong? >>> >>> What do you mean with 'kills apache', does it terminate apache or >>> does >>> apache hang (eg. 100% cpu), and respond normal after the stress >>> test >>> is over? >>> And what is the index of your site? A php script, or..? Do you have >>> ModRewrite redirects etc? >>> >>> - Matijn >>> >>> -- >>> PHP General Mailing List (http://www.php.net/) >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >> >> Can you visit the site normally? Try less verbosing in apache, that >> is >> pretty intensive, but as you can benchmark a static file well (with >> moderate high settings), i assume it is some configuration problem >> in >> drupal. >> >> Greeting. >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > > Hi, > > I can visit the site normaly, but with 2-3 concurrent ab test it > fails. > seen from 'ps' and 'htop' it seems that both apache and mysql > continues > to > run normaly but it doesnt respond. > > If i run netstat -an after the test it shows this : > Active Internet connections (servers and established) > Proto Recv-Q Send-Q Local Address      Foreign Address >  State > tcp     0    0 0.0.0.0:22        0.0.0.0:* >     LISTEN > tcp     0    0 127.0.0.1:25       0.0.0.0:*  >    LISTEN > tcp     0    0 127.0.0.1:3306      0.0.0.0:*  >    LISTEN > tcp     0    0 0.0.0.0:80        0.0.0.0:* >     LISTEN > tcp     1    0 x.x.x.x:80     x.x.x.x:39237  > CLOSE_WAIT > tcp     1    0 x.x.x.x:80     x.x.x.x:39236  >  CLOSE_WAIT > tcp     0    0 x.x.x.x:22     x.x.x.x:47383  >  ESTABLISHED > tcp     0    0 127.0.0.1:80      >  127.0.0.1:34775 > ESTABLISHED > tcp     1    0 x.x.x.x:80     x.x.x.x:39300  >  CLOSE_WAIT > ESTABLISHED > tcp     0    0 127.0.0.1:34775     127.0.0.1:80 > ESTABLISHED > tcp     0    0 x.x.x.x:80     x.x.x.x:39330  >  ESTABLISHED > tcp6    0    0 :::22          :::* > LISTEN > tcp6    0    0 ::1:25          :::* > LISTEN > > So it does seem like there should be room for new tcp connections? > > But if I restart apache then it works again... So I guess it is a > apache/php configuration issue? > > -- > Med venlig hilsen / Best Regards > > LFWeb > Lars Nielsen > Thorsensvej 30 > 4800 Nykøbing Falster > Tlf: +45 20 64 85 76 > email : l...@lfweb.dk > www : http://www.lfweb.dk > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > Have you tried benchmarking a really simple php page, such as ? It that works, than it is definitely an issue in Drupal's configuration and not in PHP/Apache. Additionally, you could check what happens when you try to establish a session or make a database call to rule out those as well, just make really simple tests that you know wouldn't fail and run ab on them. Greetings. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance / AB issue?
> On Fri, May 11, 2012 at 9:53 AM, Camilo Sperberg > wrote: >> >> >> Sent from my iPhone 5 Beta [Confidential use only] >> >> On 11 mei 2012, at 07:09, "Lars Nielsen" wrote: >> >>> On 10 mei 2012, at 23:26, Lars Nielsen wrote: > >> >> >> Sent from my iPhone 5 Beta [Confidential use only] >> >> On 10 mei 2012, at 17:40, Matijn Woudt wrote: >> >>> On Thu, May 10, 2012 at 9:04 AM, Lars Nielsen >>> wrote: Hi there, I have apache-2.22/php 5.3.10 set up on a dedicated server but I have a strange issue. I have made a Drupal 7 site with a mysql db. If I stress-test the site with : ab -c 1 -n 150 http://sitename/ it works fine. If I stress-test the site with : ab -c 2 -n 20 http://sitename/ it kills apache. If I stress-test the site with : ab -c 50 -n 1500 http://sitename/static.html it works fine. I have set apache's errorlog to debug. But it writes nothing, either in the virtualhost or in the server-file. Can anyone give a hint about what can be wrong? >>> >>> What do you mean with 'kills apache', does it terminate apache or >>> does >>> apache hang (eg. 100% cpu), and respond normal after the stress >>> test >>> is over? >>> And what is the index of your site? A php script, or..? Do you have >>> ModRewrite redirects etc? >>> >>> - Matijn >>> >>> -- >>> PHP General Mailing List (http://www.php.net/) >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >> >> Can you visit the site normally? Try less verbosing in apache, that >> is >> pretty intensive, but as you can benchmark a static file well (with >> moderate high settings), i assume it is some configuration problem >> in >> drupal. >> >> Greeting. >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > > Hi, > > I can visit the site normaly, but with 2-3 concurrent ab test it > fails. > seen from 'ps' and 'htop' it seems that both apache and mysql > continues > to > run normaly but it doesnt respond. > > If i run netstat -an after the test it shows this : > Active Internet connections (servers and established) > Proto Recv-Q Send-Q Local Address      Foreign Address >  State > tcp     0    0 0.0.0.0:22        0.0.0.0:* >     LISTEN > tcp     0    0 127.0.0.1:25       0.0.0.0:*  >    LISTEN > tcp     0    0 127.0.0.1:3306      0.0.0.0:*  >    LISTEN > tcp     0    0 0.0.0.0:80        0.0.0.0:* >     LISTEN > tcp     1    0 x.x.x.x:80     x.x.x.x:39237  > CLOSE_WAIT > tcp     1    0 x.x.x.x:80     x.x.x.x:39236  >  CLOSE_WAIT > tcp     0    0 x.x.x.x:22     x.x.x.x:47383  >  ESTABLISHED > tcp     0    0 127.0.0.1:80      >  127.0.0.1:34775 > ESTABLISHED > tcp     1    0 x.x.x.x:80     x.x.x.x:39300  >  CLOSE_WAIT > ESTABLISHED > tcp     0    0 127.0.0.1:34775     127.0.0.1:80 > ESTABLISHED > tcp     0    0 x.x.x.x:80     x.x.x.x:39330  >  ESTABLISHED > tcp6    0    0 :::22          :::* > LISTEN > tcp6    0    0 ::1:25          :::* > LISTEN > > So it does seem like there should be room for new tcp connections? > > But if I restart apache then it works again... So I guess it is a > apache/php configuration issue? > > -- > Med venlig hilsen / Best Regards > > LFWeb > Lars Nielsen > Thorsensvej 30 > 4800 Nykøbing Falster > Tlf: +45 20 64 85 76 > email : l...@lfweb.dk > www : http://www.lfweb.dk > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > Have you tried benchmarking a really simple php page, such as ? It that works, than it is definitely an issue in Drupal's configuration and not in PHP/Apache. Additionally, you could check what happens when you try to establish a session or make a database call to rule out those as well, just make really simple tests that you know wouldn't fail and run ab on them. Greetings. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance / AB issue?
How is PHP running, fast-cgi, sapi, etc..? Is there anything in the error_log for apache? Could be an issue with prefork/worker. Thanks, Mike Mackintosh PHP, the drug of choice - www.highonphp.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance / AB issue?
On Fri, May 11, 2012 at 9:53 AM, Camilo Sperberg wrote: > > > Sent from my iPhone 5 Beta [Confidential use only] > > On 11 mei 2012, at 07:09, "Lars Nielsen" wrote: > >> >>> >>> On 10 mei 2012, at 23:26, Lars Nielsen wrote: >>> > > > Sent from my iPhone 5 Beta [Confidential use only] > > On 10 mei 2012, at 17:40, Matijn Woudt wrote: > >> On Thu, May 10, 2012 at 9:04 AM, Lars Nielsen wrote: >>> Hi there, >>> >>> I have apache-2.22/php 5.3.10 set up on a dedicated server but I have >>> a >>> strange issue. >>> >>> I have made a Drupal 7 site with a mysql db. >>> >>> If I stress-test the site with : ab -c 1 -n 150 http://sitename/ it >>> works >>> fine. >>> If I stress-test the site with : ab -c 2 -n 20 http://sitename/ it >>> kills >>> apache. >>> If I stress-test the site with : ab -c 50 -n 1500 >>> http://sitename/static.html it works fine. >>> >>> I have set apache's errorlog to debug. But it writes nothing, either >>> in >>> the virtualhost or in the server-file. >>> >>> Can anyone give a hint about what can be wrong? >>> >>> >> >> What do you mean with 'kills apache', does it terminate apache or does >> apache hang (eg. 100% cpu), and respond normal after the stress test >> is over? >> And what is the index of your site? A php script, or..? Do you have >> ModRewrite redirects etc? >> >> - Matijn >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> > > Can you visit the site normally? Try less verbosing in apache, that is > pretty intensive, but as you can benchmark a static file well (with > moderate high settings), i assume it is some configuration problem in > drupal. > > Greeting. > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > Hi, I can visit the site normaly, but with 2-3 concurrent ab test it fails. seen from 'ps' and 'htop' it seems that both apache and mysql continues to run normaly but it doesnt respond. If i run netstat -an after the test it shows this : Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN tcp 1 0 x.x.x.x:80 x.x.x.x:39237 CLOSE_WAIT tcp 1 0 x.x.x.x:80 x.x.x.x:39236 CLOSE_WAIT tcp 0 0 x.x.x.x:22 x.x.x.x:47383 ESTABLISHED tcp 0 0 127.0.0.1:80 127.0.0.1:34775 ESTABLISHED tcp 1 0 x.x.x.x:80 x.x.x.x:39300 CLOSE_WAIT ESTABLISHED tcp 0 0 127.0.0.1:34775 127.0.0.1:80 ESTABLISHED tcp 0 0 x.x.x.x:80 x.x.x.x:39330 ESTABLISHED tcp6 0 0 :::22 :::* LISTEN tcp6 0 0 ::1:25 :::* LISTEN So it does seem like there should be room for new tcp connections? But if I restart apache then it works again... So I guess it is a apache/php configuration issue? -- Med venlig hilsen / Best Regards LFWeb Lars Nielsen Thorsensvej 30 4800 Nykøbing Falster Tlf: +45 20 64 85 76 email : l...@lfweb.dk www : http://www.lfweb.dk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php >>> >>> Have you tried benchmarking a really simple php page, such as >>> >>> >>> >>> ? >>> >>> It that works, than it is definitely an issue in Drupal's configuration >>> and not in PHP/Apache. Additionally, you could check what happens when you >>> try to establish a session or make a database call to rule out those as >>> well, just make really simple tests that you know wouldn't fail and run ab >>> on them. >>> >>> Greetings. >>> >>> >>> -- >>> PHP General Mailing List (http://www.php.net/) >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >>> >> Thanks! >> >> Now I have made >> > echo "Hey from PHP!"; >> ?> >> >> It runs fine from a little concurrency. But with "-c 5 -n 500" it fails >> after 308 requests! >> >> >> >> Best Regards / Med venlig hilsen >> >> LFWeb >> Lars Nielsen >> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> > > Have you tried benchmarking from localhost? Do you have any active firewall? > Selinux? Shorewall? Anything that could block a ddos att
Re: [PHP] Performance / AB issue?
Sent from my iPhone 5 Beta [Confidential use only] On 11 mei 2012, at 07:09, "Lars Nielsen" wrote: > >> >> On 10 mei 2012, at 23:26, Lars Nielsen wrote: >> >>> Sent from my iPhone 5 Beta [Confidential use only] On 10 mei 2012, at 17:40, Matijn Woudt wrote: > On Thu, May 10, 2012 at 9:04 AM, Lars Nielsen wrote: >> Hi there, >> >> I have apache-2.22/php 5.3.10 set up on a dedicated server but I have >> a >> strange issue. >> >> I have made a Drupal 7 site with a mysql db. >> >> If I stress-test the site with : ab -c 1 -n 150 http://sitename/ it >> works >> fine. >> If I stress-test the site with : ab -c 2 -n 20 http://sitename/ it >> kills >> apache. >> If I stress-test the site with : ab -c 50 -n 1500 >> http://sitename/static.html it works fine. >> >> I have set apache's errorlog to debug. But it writes nothing, either >> in >> the virtualhost or in the server-file. >> >> Can anyone give a hint about what can be wrong? >> >> > > What do you mean with 'kills apache', does it terminate apache or does > apache hang (eg. 100% cpu), and respond normal after the stress test > is over? > And what is the index of your site? A php script, or..? Do you have > ModRewrite redirects etc? > > - Matijn > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > Can you visit the site normally? Try less verbosing in apache, that is pretty intensive, but as you can benchmark a static file well (with moderate high settings), i assume it is some configuration problem in drupal. Greeting. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php >>> >>> Hi, >>> >>> I can visit the site normaly, but with 2-3 concurrent ab test it fails. >>> seen from 'ps' and 'htop' it seems that both apache and mysql continues >>> to >>> run normaly but it doesnt respond. >>> >>> If i run netstat -an after the test it shows this : >>> Active Internet connections (servers and established) >>> Proto Recv-Q Send-Q Local Address Foreign Address State >>> tcp0 0 0.0.0.0:22 0.0.0.0:*LISTEN >>> tcp0 0 127.0.0.1:250.0.0.0:*LISTEN >>> tcp0 0 127.0.0.1:3306 0.0.0.0:*LISTEN >>> tcp0 0 0.0.0.0:80 0.0.0.0:*LISTEN >>> tcp1 0 x.x.x.x:80x.x.x.x:39237 CLOSE_WAIT >>> tcp1 0 x.x.x.x:80x.x.x.x:39236CLOSE_WAIT >>> tcp0 0 x.x.x.x:22x.x.x.x:47383ESTABLISHED >>> tcp0 0 127.0.0.1:80127.0.0.1:34775 >>> ESTABLISHED >>> tcp1 0 x.x.x.x:80x.x.x.x:39300CLOSE_WAIT >>> ESTABLISHED >>> tcp0 0 127.0.0.1:34775 127.0.0.1:80 >>> ESTABLISHED >>> tcp0 0 x.x.x.x:80x.x.x.x:39330ESTABLISHED >>> tcp6 0 0 :::22 :::* >>> LISTEN >>> tcp6 0 0 ::1:25 :::* >>> LISTEN >>> >>> So it does seem like there should be room for new tcp connections? >>> >>> But if I restart apache then it works again... So I guess it is a >>> apache/php configuration issue? >>> >>> -- >>> Med venlig hilsen / Best Regards >>> >>> LFWeb >>> Lars Nielsen >>> Thorsensvej 30 >>> 4800 Nykøbing Falster >>> Tlf: +45 20 64 85 76 >>> email : l...@lfweb.dk >>> www : http://www.lfweb.dk >>> >>> >>> -- >>> PHP General Mailing List (http://www.php.net/) >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >> >> Have you tried benchmarking a really simple php page, such as >> >> >> >> ? >> >> It that works, than it is definitely an issue in Drupal's configuration >> and not in PHP/Apache. Additionally, you could check what happens when you >> try to establish a session or make a database call to rule out those as >> well, just make really simple tests that you know wouldn't fail and run ab >> on them. >> >> Greetings. >> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > Thanks! > > Now I have made > echo "Hey from PHP!"; > ?> > > It runs fine from a little concurrency. But with "-c 5 -n 500" it fails > after 308 requests! > > > > Best Regards / Med venlig hilsen > > LFWeb > Lars Nielsen > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > Have you tried benchmarking from localhost? Do you have any active firewall? Selinux? Shorewall? Anything that could block a ddos attack? Greetings. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance / AB issue?
> > On 10 mei 2012, at 23:26, Lars Nielsen wrote: > >> >>> >>> >>> Sent from my iPhone 5 Beta [Confidential use only] >>> >>> On 10 mei 2012, at 17:40, Matijn Woudt wrote: >>> On Thu, May 10, 2012 at 9:04 AM, Lars Nielsen wrote: > Hi there, > > I have apache-2.22/php 5.3.10 set up on a dedicated server but I have > a > strange issue. > > I have made a Drupal 7 site with a mysql db. > > If I stress-test the site with : ab -c 1 -n 150 http://sitename/ it > works > fine. > If I stress-test the site with : ab -c 2 -n 20 http://sitename/ it > kills > apache. > If I stress-test the site with : ab -c 50 -n 1500 > http://sitename/static.html it works fine. > > I have set apache's errorlog to debug. But it writes nothing, either > in > the virtualhost or in the server-file. > > Can anyone give a hint about what can be wrong? > > What do you mean with 'kills apache', does it terminate apache or does apache hang (eg. 100% cpu), and respond normal after the stress test is over? And what is the index of your site? A php script, or..? Do you have ModRewrite redirects etc? - Matijn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php >>> >>> Can you visit the site normally? Try less verbosing in apache, that is >>> pretty intensive, but as you can benchmark a static file well (with >>> moderate high settings), i assume it is some configuration problem in >>> drupal. >>> >>> Greeting. >>> -- >>> PHP General Mailing List (http://www.php.net/) >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >>> >> >> Hi, >> >> I can visit the site normaly, but with 2-3 concurrent ab test it fails. >> seen from 'ps' and 'htop' it seems that both apache and mysql continues >> to >> run normaly but it doesnt respond. >> >> If i run netstat -an after the test it shows this : >> Active Internet connections (servers and established) >> Proto Recv-Q Send-Q Local Address Foreign Address State >> tcp0 0 0.0.0.0:22 0.0.0.0:*LISTEN >> tcp0 0 127.0.0.1:250.0.0.0:*LISTEN >> tcp0 0 127.0.0.1:3306 0.0.0.0:*LISTEN >> tcp0 0 0.0.0.0:80 0.0.0.0:*LISTEN >> tcp1 0 x.x.x.x:80x.x.x.x:39237 CLOSE_WAIT >> tcp1 0 x.x.x.x:80x.x.x.x:39236CLOSE_WAIT >> tcp0 0 x.x.x.x:22x.x.x.x:47383ESTABLISHED >> tcp0 0 127.0.0.1:80127.0.0.1:34775 >> ESTABLISHED >> tcp1 0 x.x.x.x:80x.x.x.x:39300CLOSE_WAIT >> ESTABLISHED >> tcp0 0 127.0.0.1:34775 127.0.0.1:80 >> ESTABLISHED >> tcp0 0 x.x.x.x:80x.x.x.x:39330ESTABLISHED >> tcp6 0 0 :::22 :::* >> LISTEN >> tcp6 0 0 ::1:25 :::* >> LISTEN >> >> So it does seem like there should be room for new tcp connections? >> >> But if I restart apache then it works again... So I guess it is a >> apache/php configuration issue? >> >> -- >> Med venlig hilsen / Best Regards >> >> LFWeb >> Lars Nielsen >> Thorsensvej 30 >> 4800 Nykøbing Falster >> Tlf: +45 20 64 85 76 >> email : l...@lfweb.dk >> www : http://www.lfweb.dk >> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> > > Have you tried benchmarking a really simple php page, such as > > > > ? > > It that works, than it is definitely an issue in Drupal's configuration > and not in PHP/Apache. Additionally, you could check what happens when you > try to establish a session or make a database call to rule out those as > well, just make really simple tests that you know wouldn't fail and run ab > on them. > > Greetings. > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > Thanks! Now I have made It runs fine from a little concurrency. But with "-c 5 -n 500" it fails after 308 requests! Best Regards / Med venlig hilsen LFWeb Lars Nielsen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance / AB issue?
On 10 mei 2012, at 23:26, Lars Nielsen wrote: > >> >> >> Sent from my iPhone 5 Beta [Confidential use only] >> >> On 10 mei 2012, at 17:40, Matijn Woudt wrote: >> >>> On Thu, May 10, 2012 at 9:04 AM, Lars Nielsen wrote: Hi there, I have apache-2.22/php 5.3.10 set up on a dedicated server but I have a strange issue. I have made a Drupal 7 site with a mysql db. If I stress-test the site with : ab -c 1 -n 150 http://sitename/ it works fine. If I stress-test the site with : ab -c 2 -n 20 http://sitename/ it kills apache. If I stress-test the site with : ab -c 50 -n 1500 http://sitename/static.html it works fine. I have set apache's errorlog to debug. But it writes nothing, either in the virtualhost or in the server-file. Can anyone give a hint about what can be wrong? >>> >>> What do you mean with 'kills apache', does it terminate apache or does >>> apache hang (eg. 100% cpu), and respond normal after the stress test >>> is over? >>> And what is the index of your site? A php script, or..? Do you have >>> ModRewrite redirects etc? >>> >>> - Matijn >>> >>> -- >>> PHP General Mailing List (http://www.php.net/) >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >> >> Can you visit the site normally? Try less verbosing in apache, that is >> pretty intensive, but as you can benchmark a static file well (with >> moderate high settings), i assume it is some configuration problem in >> drupal. >> >> Greeting. >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > > Hi, > > I can visit the site normaly, but with 2-3 concurrent ab test it fails. > seen from 'ps' and 'htop' it seems that both apache and mysql continues to > run normaly but it doesnt respond. > > If i run netstat -an after the test it shows this : > Active Internet connections (servers and established) > Proto Recv-Q Send-Q Local Address Foreign Address State > tcp0 0 0.0.0.0:22 0.0.0.0:*LISTEN > tcp0 0 127.0.0.1:250.0.0.0:*LISTEN > tcp0 0 127.0.0.1:3306 0.0.0.0:*LISTEN > tcp0 0 0.0.0.0:80 0.0.0.0:*LISTEN > tcp1 0 x.x.x.x:80x.x.x.x:39237 CLOSE_WAIT > tcp1 0 x.x.x.x:80x.x.x.x:39236CLOSE_WAIT > tcp0 0 x.x.x.x:22x.x.x.x:47383ESTABLISHED > tcp0 0 127.0.0.1:80127.0.0.1:34775 > ESTABLISHED > tcp1 0 x.x.x.x:80x.x.x.x:39300CLOSE_WAIT > ESTABLISHED > tcp0 0 127.0.0.1:34775 127.0.0.1:80 > ESTABLISHED > tcp0 0 x.x.x.x:80x.x.x.x:39330ESTABLISHED > tcp6 0 0 :::22 :::*LISTEN > tcp6 0 0 ::1:25 :::*LISTEN > > So it does seem like there should be room for new tcp connections? > > But if I restart apache then it works again... So I guess it is a > apache/php configuration issue? > > -- > Med venlig hilsen / Best Regards > > LFWeb > Lars Nielsen > Thorsensvej 30 > 4800 Nykøbing Falster > Tlf: +45 20 64 85 76 > email : l...@lfweb.dk > www : http://www.lfweb.dk > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > Have you tried benchmarking a really simple php page, such as ? It that works, than it is definitely an issue in Drupal's configuration and not in PHP/Apache. Additionally, you could check what happens when you try to establish a session or make a database call to rule out those as well, just make really simple tests that you know wouldn't fail and run ab on them. Greetings. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance / AB issue?
On Thu, May 10, 2012 at 11:26 PM, Lars Nielsen wrote: > >> >> >> Sent from my iPhone 5 Beta [Confidential use only] >> >> On 10 mei 2012, at 17:40, Matijn Woudt wrote: >> >>> On Thu, May 10, 2012 at 9:04 AM, Lars Nielsen wrote: Hi there, I have apache-2.22/php 5.3.10 set up on a dedicated server but I have a strange issue. I have made a Drupal 7 site with a mysql db. If I stress-test the site with : ab -c 1 -n 150 http://sitename/ it works fine. If I stress-test the site with : ab -c 2 -n 20 http://sitename/ it kills apache. If I stress-test the site with : ab -c 50 -n 1500 http://sitename/static.html it works fine. I have set apache's errorlog to debug. But it writes nothing, either in the virtualhost or in the server-file. Can anyone give a hint about what can be wrong? >>> >>> What do you mean with 'kills apache', does it terminate apache or does >>> apache hang (eg. 100% cpu), and respond normal after the stress test >>> is over? >>> And what is the index of your site? A php script, or..? Do you have >>> ModRewrite redirects etc? >>> >>> - Matijn >>> >>> -- >>> PHP General Mailing List (http://www.php.net/) >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >> >> Can you visit the site normally? Try less verbosing in apache, that is >> pretty intensive, but as you can benchmark a static file well (with >> moderate high settings), i assume it is some configuration problem in >> drupal. >> >> Greeting. >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > > Hi, > > I can visit the site normaly, but with 2-3 concurrent ab test it fails. > seen from 'ps' and 'htop' it seems that both apache and mysql continues to > run normaly but it doesnt respond. > That sounds like a deadlock or something.. It's also possible it is waiting for MySQL to respond and some deadlock might happen there > If i run netstat -an after the test it shows this : > Active Internet connections (servers and established) > Proto Recv-Q Send-Q Local Address Foreign Address State > tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN > tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN > tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN > tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN > tcp 1 0 x.x.x.x:80 x.x.x.x:39237 CLOSE_WAIT > tcp 1 0 x.x.x.x:80 x.x.x.x:39236 CLOSE_WAIT > tcp 0 0 x.x.x.x:22 x.x.x.x:47383 ESTABLISHED > tcp 0 0 127.0.0.1:80 127.0.0.1:34775 > ESTABLISHED > tcp 1 0 x.x.x.x:80 x.x.x.x:39300 CLOSE_WAIT > ESTABLISHED > tcp 0 0 127.0.0.1:34775 127.0.0.1:80 > ESTABLISHED > tcp 0 0 x.x.x.x:80 x.x.x.x:39330 ESTABLISHED > tcp6 0 0 :::22 :::* LISTEN > tcp6 0 0 ::1:25 :::* LISTEN > > So it does seem like there should be room for new tcp connections? even 10.000 connections at the same time should be fine > > But if I restart apache then it works again... So I guess it is a > apache/php configuration issue? > Did you try to run ab from the same server (with http://localhost/) too? Also, are you running any optimization stuff, like memcached? - Matijn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance / AB issue?
> > > Sent from my iPhone 5 Beta [Confidential use only] > > On 10 mei 2012, at 17:40, Matijn Woudt wrote: > >> On Thu, May 10, 2012 at 9:04 AM, Lars Nielsen wrote: >>> Hi there, >>> >>> I have apache-2.22/php 5.3.10 set up on a dedicated server but I have a >>> strange issue. >>> >>> I have made a Drupal 7 site with a mysql db. >>> >>> If I stress-test the site with : ab -c 1 -n 150 http://sitename/ it >>> works >>> fine. >>> If I stress-test the site with : ab -c 2 -n 20 http://sitename/ it >>> kills >>> apache. >>> If I stress-test the site with : ab -c 50 -n 1500 >>> http://sitename/static.html it works fine. >>> >>> I have set apache's errorlog to debug. But it writes nothing, either in >>> the virtualhost or in the server-file. >>> >>> Can anyone give a hint about what can be wrong? >>> >>> >> >> What do you mean with 'kills apache', does it terminate apache or does >> apache hang (eg. 100% cpu), and respond normal after the stress test >> is over? >> And what is the index of your site? A php script, or..? Do you have >> ModRewrite redirects etc? >> >> - Matijn >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> > > Can you visit the site normally? Try less verbosing in apache, that is > pretty intensive, but as you can benchmark a static file well (with > moderate high settings), i assume it is some configuration problem in > drupal. > > Greeting. > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > Hi, I can visit the site normaly, but with 2-3 concurrent ab test it fails. seen from 'ps' and 'htop' it seems that both apache and mysql continues to run normaly but it doesnt respond. If i run netstat -an after the test it shows this : Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp0 0 0.0.0.0:22 0.0.0.0:*LISTEN tcp0 0 127.0.0.1:250.0.0.0:*LISTEN tcp0 0 127.0.0.1:3306 0.0.0.0:*LISTEN tcp0 0 0.0.0.0:80 0.0.0.0:*LISTEN tcp1 0 x.x.x.x:80x.x.x.x:39237 CLOSE_WAIT tcp1 0 x.x.x.x:80x.x.x.x:39236CLOSE_WAIT tcp0 0 x.x.x.x:22x.x.x.x:47383ESTABLISHED tcp0 0 127.0.0.1:80127.0.0.1:34775 ESTABLISHED tcp1 0 x.x.x.x:80x.x.x.x:39300CLOSE_WAIT ESTABLISHED tcp0 0 127.0.0.1:34775 127.0.0.1:80 ESTABLISHED tcp0 0 x.x.x.x:80x.x.x.x:39330ESTABLISHED tcp6 0 0 :::22 :::*LISTEN tcp6 0 0 ::1:25 :::*LISTEN So it does seem like there should be room for new tcp connections? But if I restart apache then it works again... So I guess it is a apache/php configuration issue? -- Med venlig hilsen / Best Regards LFWeb Lars Nielsen Thorsensvej 30 4800 Nykøbing Falster Tlf: +45 20 64 85 76 email : l...@lfweb.dk www : http://www.lfweb.dk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance / AB issue?
Sent from my iPhone 5 Beta [Confidential use only] On 10 mei 2012, at 17:40, Matijn Woudt wrote: > On Thu, May 10, 2012 at 9:04 AM, Lars Nielsen wrote: >> Hi there, >> >> I have apache-2.22/php 5.3.10 set up on a dedicated server but I have a >> strange issue. >> >> I have made a Drupal 7 site with a mysql db. >> >> If I stress-test the site with : ab -c 1 -n 150 http://sitename/ it works >> fine. >> If I stress-test the site with : ab -c 2 -n 20 http://sitename/ it kills >> apache. >> If I stress-test the site with : ab -c 50 -n 1500 >> http://sitename/static.html it works fine. >> >> I have set apache's errorlog to debug. But it writes nothing, either in >> the virtualhost or in the server-file. >> >> Can anyone give a hint about what can be wrong? >> >> > > What do you mean with 'kills apache', does it terminate apache or does > apache hang (eg. 100% cpu), and respond normal after the stress test > is over? > And what is the index of your site? A php script, or..? Do you have > ModRewrite redirects etc? > > - Matijn > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > Can you visit the site normally? Try less verbosing in apache, that is pretty intensive, but as you can benchmark a static file well (with moderate high settings), i assume it is some configuration problem in drupal. Greeting. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance / AB issue?
On Thu, May 10, 2012 at 9:04 AM, Lars Nielsen wrote: > Hi there, > > I have apache-2.22/php 5.3.10 set up on a dedicated server but I have a > strange issue. > > I have made a Drupal 7 site with a mysql db. > > If I stress-test the site with : ab -c 1 -n 150 http://sitename/ it works > fine. > If I stress-test the site with : ab -c 2 -n 20 http://sitename/ it kills > apache. > If I stress-test the site with : ab -c 50 -n 1500 > http://sitename/static.html it works fine. > > I have set apache's errorlog to debug. But it writes nothing, either in > the virtualhost or in the server-file. > > Can anyone give a hint about what can be wrong? > > What do you mean with 'kills apache', does it terminate apache or does apache hang (eg. 100% cpu), and respond normal after the stress test is over? And what is the index of your site? A php script, or..? Do you have ModRewrite redirects etc? - Matijn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance gain when not using prepared statements?
On Fri, Jun 17, 2011 at 4:55 AM, Vitalii Demianets wrote: > On Friday 17 June 2011 04:50:00 Daevid Vincent wrote: >> > I've seen too many people over the years try and rally against common >> > sense practices like using prepared statements for perhaps a marginal >> > gain of performance on one page while their load averages are 0,0,0. >> >> Agreed. The ONLY time prepared statements are useful, is in a loop where >> you're changing a few variables but within the same SQL statement. That is >> a rare case for most people. >> > > Not ONLY. I love prepared statements because with them I can store arbitrary > strings in DB without need to worry about fancy escaping and SQL injection. > And do it in DB-independent way. > Think about all that extra escaping and performance gain of not using prepared > statement will shrink a lot ) Don't have actual numbers though. > > -- > Vitalii > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > You can implement caching at so many levels of the app that using a prepared statement should be at the lower spectrum of your worries. It is too easy to forget calling escape whether it be for a DB or output to the browser as proven by all the various bug trackers and hacked websites across the net. Just to drive this point home, if you do a quick search on Secunia for 'SQL Injection' [1] you get 4,158 advisories. Worth the risk? http://secunia.com/advisories/search/?search=sql+injection -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance Improvement on Calling C++ executable from PHP
On Sun, Dec 19, 2010 at 15:35, Shiplu wrote: > === > Recently I my this php-general doesn't accept my mail for some > reason. So I send it again from anther email > === No, actually, you sent it from the exact same address --- but both came through anyway. > I am developing a php application that interfaces with an external > executable binary. The program is written in C++. > I open the program (say a.out) using proc_open. Write some command at > its stdin and fetch data stdout. Then close the program. > > The timing of only "a.out" is > real 490ms > usr 160ms > sys 290ms > > When I invoke it using proc_open in php-cli, the timing becomes > real 530ms > usr 50ms > sys 450ms > > Look closely, the cpu time and the real elapsed time increases. I run > the php version from command line. As an apache handler this will > surly take more time. Is this just the processing time of the a.out file, or is this considering the PHP script's execution time including the a.out processing? If so, this increase is, of course, to be completely expected. Also, were the input and output exactly the same size in bytes as the direct test? > The program a.out can not be converted in php unless I write an > extension. But this will need a lot of effort to write it in PHP. Extensions aren't written in PHP, they're binary packages. > Some of my ideas are, > 1. Create a standalone multi-threaded server that calls a.out and php > calls that server. This is the same basic idea that Facebook's HipHop project uses. > 2. Call a.out as a CGI and convert it that way. This would likely be your best bet, as you're stripping away all of the excess interfacing by PHP (or another scripting language), and would instead just be accessing it directly via the web server. That said, it would depend on whether or not your program is (or could be) written to handle everything itself, so that PHP - or any capable language, for that matter - would no longer be necessary. -- Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting (866-) 725-4321 http://www.parasane.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance of while(true) loop
APseudoUtopia wrote: > Hey list, > > I have a php cli script that listens on a UDP socket and, when data is > sent to the socket, the script inserts it into a database. I'm using > the real BSD socket functions, not fsock. > > The script runs socket_create(), then socket_bind(). Then it starts a > while(TRUE) loop. Within the loop, it runs socket_recvfrom(). I have > it running 24/7 inside a screen window. > > I'm curious as to the cpu/memory/etc usage of a while(true) loop. The > `top` command shows that the process is in the sbwait state (the OS is > FreeBSD). I'm contemplating adding a usleep or even a sleep inside to > loop. Would this be beneficial? I'm not too sure of how the internals > of PHP work in terms of loops and such. > > Thanks. > Here is something I wrote a few years ago. I still have this running on my system today... #!/usr/local/bin/php -q # # Version: 0.0.1 # set -e DESC="Name of service" DAEMON=/path/to/file.php PIDFILE=/var/run/.pid SCRIPTNAME=tms_daemon # Gracefully exit if the package has been removed. test -x $DAEMON || exit 0 # # Function that starts the daemon/service. # d_start() { if [ -f $PIDFILE ]; then echo "$DESC already running: PID# `cat $PIDFILE`" exit 1 else echo -n "Starting $DESC" nohup $DAEMON 2>&1 1>/dev/null & sleep 0.5 ps aux | grep $DAEMON | grep -v grep | awk -F' ' '{print $2} ' > $PIDFILE echo ". [`cat $PIDFILE`]" fi } # # Function that stops the daemon/service. # d_stop() { if [ -f $PIDFILE ]; then echo -n "Stopping $DESC" kill `cat $PIDFILE` rm $PIDFILE echo "." else echo "$DESC is not running" exit 1 fi } case "$1" in start) d_start ;; stop) d_stop ;; status) if [ -f $PIDFILE ]; then echo "$DESC is running: PID# `cat $PIDFILE`" else echo "$DESC is not running" fi ;; cleanup) PID="`ps aux | grep $DAEMON | grep -v grep | awk -F' ' '{print $2}'`" kill $PID rm $PIDFILE ;; restart|force-reload) d_stop sleep 0.5 d_start ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 exit 1 ;; esac exit 0 ##END Jim Lucas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance of while(true) loop
I have a php cli script that listens on a UDP socket and, when data is [8<] >> So I think the the MSG_WAITALL is causing it to block until incoming >> data connection is closed (it never reaches the 512 byte mark before [8<] > your "clients" are not maintaining an open connection to the socket, > so it'll output as soon as the remote client disconnects from your > "server". [8<] > if you will) on the socket until a connection is made and it reads 512 > bytes / the client disconnects, which seems to be doing well for your > usage. Sorry if I'm missing something obvious, but do the concepts of "connection", "close", and "disconnect" even apply in this case, since it's a UDP socket? Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance of while(true) loop
On Wed, Sep 9, 2009 at 10:53 PM, APseudoUtopia wrote: > On Wed, Sep 9, 2009 at 10:39 PM, Eddie Drapkin wrote: >> On Wed, Sep 9, 2009 at 10:32 PM, APseudoUtopia >> wrote: >>> Hey list, >>> >>> I have a php cli script that listens on a UDP socket and, when data is >>> sent to the socket, the script inserts it into a database. I'm using >>> the real BSD socket functions, not fsock. >>> >>> The script runs socket_create(), then socket_bind(). Then it starts a >>> while(TRUE) loop. Within the loop, it runs socket_recvfrom(). I have >>> it running 24/7 inside a screen window. >>> >>> I'm curious as to the cpu/memory/etc usage of a while(true) loop. The >>> `top` command shows that the process is in the sbwait state (the OS is >>> FreeBSD). I'm contemplating adding a usleep or even a sleep inside to >>> loop. Would this be beneficial? I'm not too sure of how the internals >>> of PHP work in terms of loops and such. >>> >>> Thanks. >>> >>> -- >>> PHP General Mailing List (http://www.php.net/) >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >>> >> >> Is your socket blocking? If so, what's the timeout? >> >> while(true) { >> >> //wait for socket timeout >> >> } >> >> is the same as: >> >> while(true) { >> >> //read nothing from socket and sleep >> >> } >> >> Without the usleep(), the loop is going to loop as fast as your CPU >> will let it - meaning 100% CPU usage, all the time, at least in linux, >> although I'm pretty sure BSD would behave the same. >> >> As far as I'm aware, sockets in PHP behave almost identically to the >> way that they behave in C. I had an asynchronous TCP server written >> with the socket_* functions and noticed that the while(true) loop used >> 100% of the CPU because of the nonblocking sockets in use, but a >> usleep() solved that quite easily. Using blocking sockets with >> socket_select and a sane timeout relieved the high CPU usage as well. >> > > I believe it is blocking. Here's my socket_recvfrom: > $Recv = socket_recvfrom($Socket, $Data, 512, MSG_WAITALL, $Name, $Port); > > So I think the the MSG_WAITALL is causing it to block until incoming > data connection is closed (it never reaches the 512 byte mark before > it echos the data). Here's the full script, minus the debugging/error > catching stuff: > > $Socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); > $Bind = socket_bind($Socket, '127.0.0.1', 1223); > while(TRUE){ > $Recv = socket_recvfrom($Socket, $Data, 512, MSG_WAITALL, $Name, $Port); > print_r($Data); > } > > As soon as the message is sent on the socket, it displays it. There's > no delay until it builds up 512 bytes or anything. Also, I was playing > around with ps and it looks like it's using 0% CPU, so I suppose it > must be blocking. > > In the case that it is blocking, would it still be wise to throw a > usleep in there just to be sure? > > Thanks. > MSG_WAITALL will block until 512 bytes of $Data has been received (or a disconnect), so unless you're receiving a ridiculous amount of data every iteration, forcing your CPU usage to be very high (which you've said isn't the case :P) then there's no real reason to sleep every while iteration. The reason why you're not getting a delay is because your "clients" are not maintaining an open connection to the socket, so it'll output as soon as the remote client disconnects from your "server". I wouldn't necessarily say it's unwise or wise to sleep after every iteration, but it would depend on what kind of latency you need from your application, how much data it's receiving, etc. etc. Another thing you might want to consider about your design is that function, as you're using it, blocks until those 512 bytes have been read, so if a normal "request" (assuming a persistent connection) to your socket is <512 bytes, it could potentially sit there and wait indefinitely (not very likely). As it is, though, your server blocks (or sleeps, if you will) on the socket until a connection is made and it reads 512 bytes / the client disconnects, which seems to be doing well for your usage. The old adage "if it ain't broke, don't fix it" sort of applies here. Your program idles about at 0% CPU usage most of the time, for now. Until something changes, I'd leave it alone :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance of while(true) loop
On Wed, Sep 9, 2009 at 10:39 PM, Eddie Drapkin wrote: > On Wed, Sep 9, 2009 at 10:32 PM, APseudoUtopia > wrote: >> Hey list, >> >> I have a php cli script that listens on a UDP socket and, when data is >> sent to the socket, the script inserts it into a database. I'm using >> the real BSD socket functions, not fsock. >> >> The script runs socket_create(), then socket_bind(). Then it starts a >> while(TRUE) loop. Within the loop, it runs socket_recvfrom(). I have >> it running 24/7 inside a screen window. >> >> I'm curious as to the cpu/memory/etc usage of a while(true) loop. The >> `top` command shows that the process is in the sbwait state (the OS is >> FreeBSD). I'm contemplating adding a usleep or even a sleep inside to >> loop. Would this be beneficial? I'm not too sure of how the internals >> of PHP work in terms of loops and such. >> >> Thanks. >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > > Is your socket blocking? If so, what's the timeout? > > while(true) { > > //wait for socket timeout > > } > > is the same as: > > while(true) { > > //read nothing from socket and sleep > > } > > Without the usleep(), the loop is going to loop as fast as your CPU > will let it - meaning 100% CPU usage, all the time, at least in linux, > although I'm pretty sure BSD would behave the same. > > As far as I'm aware, sockets in PHP behave almost identically to the > way that they behave in C. I had an asynchronous TCP server written > with the socket_* functions and noticed that the while(true) loop used > 100% of the CPU because of the nonblocking sockets in use, but a > usleep() solved that quite easily. Using blocking sockets with > socket_select and a sane timeout relieved the high CPU usage as well. > I believe it is blocking. Here's my socket_recvfrom: $Recv = socket_recvfrom($Socket, $Data, 512, MSG_WAITALL, $Name, $Port); So I think the the MSG_WAITALL is causing it to block until incoming data connection is closed (it never reaches the 512 byte mark before it echos the data). Here's the full script, minus the debugging/error catching stuff: $Socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); $Bind = socket_bind($Socket, '127.0.0.1', 1223); while(TRUE){ $Recv = socket_recvfrom($Socket, $Data, 512, MSG_WAITALL, $Name, $Port); print_r($Data); } As soon as the message is sent on the socket, it displays it. There's no delay until it builds up 512 bytes or anything. Also, I was playing around with ps and it looks like it's using 0% CPU, so I suppose it must be blocking. In the case that it is blocking, would it still be wise to throw a usleep in there just to be sure? Thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance of while(true) loop
On Wed, Sep 9, 2009 at 10:32 PM, APseudoUtopia wrote: > Hey list, > > I have a php cli script that listens on a UDP socket and, when data is > sent to the socket, the script inserts it into a database. I'm using > the real BSD socket functions, not fsock. > > The script runs socket_create(), then socket_bind(). Then it starts a > while(TRUE) loop. Within the loop, it runs socket_recvfrom(). I have > it running 24/7 inside a screen window. > > I'm curious as to the cpu/memory/etc usage of a while(true) loop. The > `top` command shows that the process is in the sbwait state (the OS is > FreeBSD). I'm contemplating adding a usleep or even a sleep inside to > loop. Would this be beneficial? I'm not too sure of how the internals > of PHP work in terms of loops and such. > > Thanks. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > Is your socket blocking? If so, what's the timeout? while(true) { //wait for socket timeout } is the same as: while(true) { //read nothing from socket and sleep } Without the usleep(), the loop is going to loop as fast as your CPU will let it - meaning 100% CPU usage, all the time, at least in linux, although I'm pretty sure BSD would behave the same. As far as I'm aware, sockets in PHP behave almost identically to the way that they behave in C. I had an asynchronous TCP server written with the socket_* functions and noticed that the while(true) loop used 100% of the CPU because of the nonblocking sockets in use, but a usleep() solved that quite easily. Using blocking sockets with socket_select and a sane timeout relieved the high CPU usage as well. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP performance profiling
Gryffyn wrote: I did a search and didn't find anything really astounding sounding, so I wanted to ask for some "live" recommendations from the crowd here. I was wondering if anyone had used FirePHP with Firebug or could recommend a good profiling method for figuring out where the slow parts of your PHP code are. I'm curious about solutions that don't require installing something on the server side, since that's not usually an option with shared web hosting and all. I used to love Zend Studio's server component along with the IDE, but it doesn't help so much with shared web hosts where you can't install the server component. Ideally, I'd love to see what segments of the code are running slow, but at the very minimum, I want to see if it's the PHP code or the MySQL calls that are slow. I know I can just add my own statements in the code, but I was hoping there was a more comprehensive solution available. Thanks in advance. -TG manually with a home grown script or pear benchmark apd on windows or zend platform don't really know of anything else tbh but would like a nice profiler for php myself (easier if php was precompiled I guess) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] & performance issues
On 17 April 2008 11:57, Bojan Tesanovic advised: > in PHP5 by default Objects are passed by reference Please stop repeating this -- erm -- inexactitude. In PHP5, objects are passed around by their handle, *not* as a reference. Most of the time, this has the same effect, as you are addressing the same object either way. However, the behaviour of a copied object handle is not the same as a reference. In fact, when you create a reference to an object, what you're actually getting is a reference to the object's handle! To prove this, try running the test code below -- the object handling will not, I assure you, behave as though you were passing a reference around by default, but is directly comparable to the following string example: me = 'Original'; $copy_t = $t; $ref_t = &$t; $copy_t = new test; $copy_t->me = 'Altered Copy'; echo <me Reference: $ref_t->me RESULT1; $ref_t = new test; $ref_t->me = 'Altered Reference'; echo << Original: $t->me Copy: $copy_t->me Reference: $ref_t->me RESULT2; $s = 'String'; $copy_s = $s; $ref_s = &$s; $copy_s = 'String Copy'; echo << Original: $s Copy: $copy_s Reference: $ref_s RESULT3; $ref_s = 'String Reference'; echo << Original: $s Copy: $copy_s Reference: $ref_s RESULT4; ?> Cheers! -- Mike Ford, Electronic Information Services Adviser, JG125, The Headingley Library, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 812 4730 Fax: +44 113 812 3211 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] & performance issues
On Thu, Apr 17, 2008 at 7:10 PM, Nathan Nobbe <[EMAIL PROTECTED]> wrote: > On Thu, Apr 17, 2008 at 11:51 AM, Eric Butera <[EMAIL PROTECTED]> wrote: > > > > > > > > > On Thu, Apr 17, 2008 at 12:00 PM, Nathan Nobbe <[EMAIL PROTECTED]> > wrote: > > > On Thu, Apr 17, 2008 at 4:57 AM, Bojan Tesanovic <[EMAIL PROTECTED]> > > > wrote: > > > > > > > > > > in PHP5 by default Objects are passed by reference and as you can see > at > > > > this graph passing array by reference in PHP5 is slower > > > > http://nathan.moxune.com/arrayVsArrayIteratorReport.php > > > > > > > > > wow, thats hilarious, thats my own chart :O ROTFL > > > > > > im glad somebody else thought something of it ;) > > > > > > -nathan > > > > > > > I almost spit my water out when I saw that link directed at you. > > good times! > > > Your > > work is famous! ;) > > well i do what i can :D > > > > I don't have an actual answer as far as benchmarks go. I've been > > converting all of my sites from php4 to 5 over the past 3 months > > stripping out &'s as I go. I haven't noticed any differences myself > > though. But then again I've been adding in type hints and visibility > > too so I'm sure that isn't helping. > > yea; i hadnt thought of the overhead of adding visibility / type hinting in. > but if im adding those, either way; the extra cost from the & can be gained > back if theyre yanked. > > > > I'm always pimping Xdebug, so just remember it will show you where > > your real bottlenecks are instead of guessing. *shrug* > > xdebug is da bomb; thats what i used to build the charts from the > performance report ;) > > ok, so heres what im thinking. any functions that return by reference can > safely be changed, right? so i could do a mass replace like this > > find: 'function &' > replace: 'function ' > > note, there is a space after function in the replace. i think the only > reason to use return by reference is when returning an object to avoid > getting a copy back in the php4 days. the rest im thinking can be done by > hand as time goes on. waddya all think? > > thx, > > -nathan > Should be ok, but that is what unit tests are for, right? ;) I only used return by reference when returning objects. I think referencing array inputs would be more of a challenge if there was any trickery going on there. The return value should just be a final here you go since the function is done at that point. Guess you'll find out when you try it. Just make a backup first! :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] & performance issues
On Thu, Apr 17, 2008 at 11:51 AM, Eric Butera <[EMAIL PROTECTED]> wrote: > On Thu, Apr 17, 2008 at 12:00 PM, Nathan Nobbe <[EMAIL PROTECTED]> > wrote: > > On Thu, Apr 17, 2008 at 4:57 AM, Bojan Tesanovic <[EMAIL PROTECTED]> > > wrote: > > > > > > > in PHP5 by default Objects are passed by reference and as you can see > at > > > this graph passing array by reference in PHP5 is slower > > > http://nathan.moxune.com/arrayVsArrayIteratorReport.php > > > > > > wow, thats hilarious, thats my own chart :O ROTFL > > > > im glad somebody else thought something of it ;) > > > > -nathan > > > > I almost spit my water out when I saw that link directed at you. good times! > Your > work is famous! ;) well i do what i can :D I don't have an actual answer as far as benchmarks go. I've been > converting all of my sites from php4 to 5 over the past 3 months > stripping out &'s as I go. I haven't noticed any differences myself > though. But then again I've been adding in type hints and visibility > too so I'm sure that isn't helping. yea; i hadnt thought of the overhead of adding visibility / type hinting in. but if im adding those, either way; the extra cost from the & can be gained back if theyre yanked. I'm always pimping Xdebug, so just remember it will show you where > your real bottlenecks are instead of guessing. *shrug* xdebug is da bomb; thats what i used to build the charts from the performance report ;) ok, so heres what im thinking. any functions that return by reference can safely be changed, right? so i could do a mass replace like this find: 'function &' replace: 'function ' note, there is a space after function in the replace. i think the only reason to use return by reference is when returning an object to avoid getting a copy back in the php4 days. the rest im thinking can be done by hand as time goes on. waddya all think? thx, -nathan
Re: [PHP] & performance issues
On Thu, Apr 17, 2008 at 12:00 PM, Nathan Nobbe <[EMAIL PROTECTED]> wrote: > On Thu, Apr 17, 2008 at 4:57 AM, Bojan Tesanovic <[EMAIL PROTECTED]> > wrote: > > > > in PHP5 by default Objects are passed by reference and as you can see at > > this graph passing array by reference in PHP5 is slower > > http://nathan.moxune.com/arrayVsArrayIteratorReport.php > > > wow, thats hilarious, thats my own chart :O ROTFL > > im glad somebody else thought something of it ;) > > -nathan > I almost spit my water out when I saw that link directed at you. Your work is famous! ;) I don't have an actual answer as far as benchmarks go. I've been converting all of my sites from php4 to 5 over the past 3 months stripping out &'s as I go. I haven't noticed any differences myself though. But then again I've been adding in type hints and visibility too so I'm sure that isn't helping. I'm always pimping Xdebug, so just remember it will show you where your real bottlenecks are instead of guessing. *shrug* -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] & performance issues
On Thu, Apr 17, 2008 at 4:57 AM, Bojan Tesanovic <[EMAIL PROTECTED]> wrote: > in PHP5 by default Objects are passed by reference and as you can see at > this graph passing array by reference in PHP5 is slower > http://nathan.moxune.com/arrayVsArrayIteratorReport.php wow, thats hilarious, thats my own chart :O ROTFL im glad somebody else thought something of it ;) -nathan
Re: [PHP] & performance issues
On Thu, Apr 17, 2008 at 12:14 AM, Robert Cummings <[EMAIL PROTECTED]> wrote: > If it's faster, it's faster so that would suggest a performance gain... > but as many will tell you, and you most likely already know... is the > gain worth the effort? BTW, rote replacement of references like that, > may not be a good idea. There are times when you really do want a > reference to an object... or maybe not... but you or someone else might > have done it anyways ;) > im not sure if its worth the effort yet; thats sortof why im asking about it on the list. obviously ill risk introduction bugs, which obviously, i dont want to do... ill have to analyze the regression system as it stands. if its decent, i might be able to use it as a benchmark utility and to test for bugs after the mass conversion. Contrast: > >$b = new Foo(); >$a = &$b; >$a = new Fee(); > > ?> > > Versus: > >$b = new Foo(); >$a = $b; >$a new Fee(); > > ?> > > In the first $b references the instance of Fee since $a is a reference. > In the second, $b remains an instance of Foo when $a becomes and > instance of Fee. wow, thats a clever example. honestly, i dont think ive ever done that before myself... but clearly that doesnt mean others havent in this codebase. thanks for the insight. -nathan
Re: [PHP] & performance issues
On Apr 17, 2008, at 5:37 AM, Nathan Nobbe wrote: all, i have heard from various sources that using the & in php can at times be costly, and therefore, it should not be used when it is not needed. for example, passing an array by reference because you think youre passing the actual array is not a good idea. only pass it by reference if a modified version needs to be handed to the calling code via an actual parameter. im also wondering about php4 code thats now running under 5; such as function &returnObject() ... $a =& new SomeClass() ... lets suppose, for the sake of arguments, i have my hands on a codebase where everything actually does count. the code was php4 and is now transitioning to 5. does anybody know if there would be a performance gain in running the whole thing through sed to try and strip out the unnecessary & characters ? any empirical data? thx, -nathan in PHP5 by default Objects are passed by reference and as you can see at this graph passing array by reference in PHP5 is slower http://nathan.moxune.com/arrayVsArrayIteratorReport.php Bojan Tesanovic http://www.carster.us/
Re: [PHP] & performance issues
On Wed, 2008-04-16 at 23:37 -0400, Nathan Nobbe wrote: > all, > > i have heard from various sources that using the & in php can at times be > costly, and therefore, it should not be used when it is not needed. for > example, passing an array by reference because you think youre passing the > actual array is not a good idea. only pass it by reference if a modified > version needs to be handed to the calling code via an actual parameter. > im also wondering about php4 code thats now running under 5; such as > function &returnObject() ... > $a =& new SomeClass() ... > lets suppose, for the sake of arguments, i have my hands on a codebase where > everything actually does count. the code was php4 and is now transitioning > to 5. does anybody know if there would be a performance gain in running the > whole thing through sed to try and strip out the unnecessary & characters ? > any empirical data? If it's faster, it's faster so that would suggest a performance gain... but as many will tell you, and you most likely already know... is the gain worth the effort? BTW, rote replacement of references like that, may not be a good idea. There are times when you really do want a reference to an object... or maybe not... but you or someone else might have done it anyways ;) Contrast: Versus: In the first $b references the instance of Fee since $a is a reference. In the second, $b remains an instance of Foo when $a becomes and instance of Fee. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance Problem
On Wed, Feb 27, 2008 at 4:29 PM, Adriano Manocchia <[EMAIL PROTECTED]> wrote: > Whoa. No need to get snippy. I was being sincere in my gratitude for > the suggestions. If nothing else, I'm sure I'll be making more use of > Xdebug in the future. I'm not being snippy at all. I was admitting my own mistake in not even noticing that you mentioned it. Somehow I completely skimmed over it. -- Daniel P. Brown Senior Unix Geek -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance Problem
Adriano Manocchia wrote: Whoa. No need to get snippy. I was being sincere in my gratitude for the suggestions. If nothing else, I'm sure I'll be making more use of Xdebug in the future. On Feb 27, 2008, at 3:55 PM, Shawn McKenzie wrote: Adriano Manocchia wrote: Well, I just spent more time messing with httpd's conf and it the problem seems to have resolved itself by turning off hostname lookups. I know there's overhead associated with it, but I don't really understand why it only affected PHP, and so drastically. At any rate, I guess this issue is solved. Thanks for the help. Adriano Yes, we all knew exactly what your problem was. Sorry we didn't post quicker ;-) -Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php He was messing with you if you couldn't tell. I'm not sure if you're just messing back, but it was at least interesting for me to read the progression of events and learn a little bit myself :) -- Ray Hauge www.primateapplications.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance Problem
Doh, sorry... I was jokingly replying to: "I was going to suggest that it was most likely an Apache or DNS issue as opposed to PHP, but after I realized I missed that your "php tests were run on a single-line PHP script that simply echoed 'hi' so it couldn't get much simpler than that," I figured I should re-read before replying again." Adriano Manocchia wrote: > Whoa. No need to get snippy. I was being sincere in my gratitude for the > suggestions. If nothing else, I'm sure I'll be making more use of Xdebug > in the future. > > On Feb 27, 2008, at 3:55 PM, Shawn McKenzie wrote: > >> Adriano Manocchia wrote: >>> Well, I just spent more time messing with httpd's conf and it the >>> problem seems to have resolved itself by turning off hostname lookups. I >>> know there's overhead associated with it, but I don't really understand >>> why it only affected PHP, and so drastically. At any rate, I guess this >>> issue is solved. Thanks for the help. >>> >>> Adriano >> >> Yes, we all knew exactly what your problem was. Sorry we didn't post >> quicker ;-) >> >> -Shawn >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance Problem
Whoa. No need to get snippy. I was being sincere in my gratitude for the suggestions. If nothing else, I'm sure I'll be making more use of Xdebug in the future. On Feb 27, 2008, at 3:55 PM, Shawn McKenzie wrote: Adriano Manocchia wrote: Well, I just spent more time messing with httpd's conf and it the problem seems to have resolved itself by turning off hostname lookups. I know there's overhead associated with it, but I don't really understand why it only affected PHP, and so drastically. At any rate, I guess this issue is solved. Thanks for the help. Adriano Yes, we all knew exactly what your problem was. Sorry we didn't post quicker ;-) -Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance Problem
Adriano Manocchia wrote: > Well, I just spent more time messing with httpd's conf and it the > problem seems to have resolved itself by turning off hostname lookups. I > know there's overhead associated with it, but I don't really understand > why it only affected PHP, and so drastically. At any rate, I guess this > issue is solved. Thanks for the help. > > Adriano Yes, we all knew exactly what your problem was. Sorry we didn't post quicker ;-) -Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance Problem
On Wed, Feb 27, 2008 at 2:50 PM, Adriano Manocchia <[EMAIL PROTECTED]> wrote: > Well, I just spent more time messing with httpd's conf and it the > problem seems to have resolved itself by turning off hostname lookups. > I know there's overhead associated with it, but I don't really > understand why it only affected PHP, and so drastically. At any rate, > I guess this issue is solved. Thanks for the help. I was going to suggest that it was most likely an Apache or DNS issue as opposed to PHP, but after I realized I missed that your "php tests were run on a single-line PHP script that simply echoed 'hi' so it couldn't get much simpler than that," I figured I should re-read before replying again. Good detective work hunting down the problem. -- Daniel P. Brown Senior Unix Geek -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance Problem
On Wed, Feb 27, 2008 at 2:34 PM, Adriano Manocchia <[EMAIL PROTECTED]> wrote: > OK. I just went through about 10 minutes' worth of cachegrinds, > including several httperf tests on that empty php file (which had the > usual poor results). According to the cachegrind files, nothing > (including the other active web pages) took more than 15ms and the > empty php file never exceeded 1ms. Clearly it's not having problems > once it gets to processing the files. The issue seems to lie elsewhere > with PHP. > > > On Feb 27, 2008, at 1:32 PM, Eric Butera wrote: > > > > > Try using Xdebug[1] with the xdebug.profiler_aggregate = 1 switch. > > > > This will allow you to see a generalized overview of all the different > > requests of your site. This way you can spot a weakness in your > > bootstrapping problem vs a single page being slow. > > > > [1] http://www.xdebug.com/ > > Ah right I should have read your situation more closely. Good work on figuring it out though. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance Problem
Well, I just spent more time messing with httpd's conf and it the problem seems to have resolved itself by turning off hostname lookups. I know there's overhead associated with it, but I don't really understand why it only affected PHP, and so drastically. At any rate, I guess this issue is solved. Thanks for the help. Adriano -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance Problem
OK. I just went through about 10 minutes' worth of cachegrinds, including several httperf tests on that empty php file (which had the usual poor results). According to the cachegrind files, nothing (including the other active web pages) took more than 15ms and the empty php file never exceeded 1ms. Clearly it's not having problems once it gets to processing the files. The issue seems to lie elsewhere with PHP. On Feb 27, 2008, at 1:32 PM, Eric Butera wrote: Try using Xdebug[1] with the xdebug.profiler_aggregate = 1 switch. This will allow you to see a generalized overview of all the different requests of your site. This way you can spot a weakness in your bootstrapping problem vs a single page being slow. [1] http://www.xdebug.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance Problem
I'm trying to get it working but it doesn't seem to want to write the profile info at the moment. Correct me if I'm wrong, but wouldn't this just show problems within actual code? If the problem is occurring on a PHP file with no PHP in it whatsoever, it seems to fall outside the scope of what xdebug would show. On Feb 27, 2008, at 1:32 PM, Eric Butera wrote: Try using Xdebug[1] with the xdebug.profiler_aggregate = 1 switch. This will allow you to see a generalized overview of all the different requests of your site. This way you can spot a weakness in your bootstrapping problem vs a single page being slow. [1] http://www.xdebug.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance Problem
On Wed, Feb 27, 2008 at 12:39 PM, Adriano Manocchia <[EMAIL PROTECTED]> wrote: > Hi all, > > I've been chasing what I think is the same performance issue for about > a year and it's driving me batty. First off, the server is a dual core > 2.8 P4 with 2G RAM running RHEL5 hosted at The Planet and is under > very light load. This problem started last year while the server was > RHEL4 and I completely rebuilt it with RHEL5. > > The PHP-based sites hosted on the server have shown intermittent > performance issues when loading. A page might load fine 2 or 3 times, > then take 5-10 seconds to complete the next page load. > > I've gone through everything top-to-bottom to try to eliminate > possibilities: > > First thought was MySQL, so I took that out of the equation and tested > pages that didn't use the database and that had no effect. > > Second though was httpd, so I compared straight HTML with PHP, and > found the problem only occurred with the PHP pages. Straight html had > no issues, so it's definitely a PHP problem. > > I've been compiling my own PHP with MySQL binary releases, so to make > sure I wasn't causing the problem, I rolled back to RHEL5 httpd, php, > and mysql. I even used the RPM's php.ini to try to rule everything > out. To try and quantify the issue, I made a PHP page that just had a > one-line echo and compared it with a regular html page and ran httperf > tests with the following values (run from the server to take network > issues out of the equation): > > httperf --hog --num-conn 100 --ra 10 --timeout 5 > > The html page always ran with no errors: > Connection time [ms]: min 0.2 avg 0.4 max 13.7 median 0.5 stddev 1.4 > Errors: total 0 client-timo 0 socket-timo 0 connrefused 0 connreset 0 > > > On the other hand, the PHP on successive attempts: > Connection rate: 6.9 conn/s (145.0 ms/conn, <=31 concurrent connections) > Connection time [ms]: min 83.3 avg 585.4 max 2215.0 median 406.5 > stddev 510.6 > Reply status: 1xx=0 2xx=70 3xx=0 4xx=0 5xx=0 > Errors: total 30 client-timo 30 socket-timo 0 connrefused 0 connreset 0 > > Connection rate: 10.0 conn/s (99.7 ms/conn, <=6 concurrent connections) > Connection time [ms]: min 25.7 avg 232.1 max 1443.4 median 141.5 > stddev 244.0 > Reply status: 1xx=0 2xx=100 3xx=0 4xx=0 5xx=0 > Errors: total 0 client-timo 0 socket-timo 0 connrefused 0 connreset 0 > > Connection rate: 6.8 conn/s (148.0 ms/conn, <=47 concurrent connections) > Connection time [ms]: min 107.4 avg 1066.1 max 1989.7 median 1201.5 > stddev 519.5 > Reply status: 1xx=0 2xx=22 3xx=0 4xx=0 5xx=0 > Errors: total 78 client-timo 78 socket-timo 0 connrefused 0 connreset 0 > > As you can see, it's all over the place and it shouldn't really be > taxing it enough to cause problems on that server. At this point, I > don't know what else to do. If anyone can shed any light on this, I'd > be forever grateful. I'll try anything and do whatever I can on my end > to fix this. Thanks in advance. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > Try using Xdebug[1] with the xdebug.profiler_aggregate = 1 switch. This will allow you to see a generalized overview of all the different requests of your site. This way you can spot a weakness in your bootstrapping problem vs a single page being slow. [1] http://www.xdebug.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance Problem
I know my original post was long-winded, but I did mention that my php tests were run on a single-line PHP script that simply echoed "hi" so it couldn't get much simpler than that. But for thoroughness' sake, I've run the tests against a test file with a php extension with no PHP code at all, and it suffers the same performance problems/ The only modules loaded for the tests were gd, mysql, pdo. For what it's worth, I help manage several RHEL servers at my day job that run similar hardware and far more bloated PHP builds that have no performance issues whatsoever. And also, for what it's worth, none of the other services on the server have problems. On Feb 27, 2008, at 1:00 PM, Daniel Brown wrote: On Wed, Feb 27, 2008 at 12:39 PM, Adriano Manocchia <[EMAIL PROTECTED] > wrote: Hi all, I've been chasing what I think is the same performance issue for about a year and it's driving me batty. First off, the server is a dual core 2.8 P4 with 2G RAM running RHEL5 hosted at The Planet and is under very light load. This problem started last year while the server was RHEL4 and I completely rebuilt it with RHEL5. [snip all of the good stuff --- thanks for a well-written question!] Adriano, It really depends on what PHP is expected to do prior to serving the content. Some things to consider: Are you loading a bunch of modules in your php.ini? What is the script doing? Is it reading/writing files? Including files? If so, are they local or remote? What happens if you take a static HTML page and rename it with a .php extension and compare load times? The last of the questions will be of the most help in determining which of the first two would be more applicable, because when you rename the extension, PHP will be loaded by Apache. This means: a.) If the performance is degraded by comparison, it's a slow-loading PHP engine. b.) If the benchmarks are comparable, then it's likely something in your PHP script(s). -- Daniel P. Brown Senior Unix Geek -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance Problem
On Wed, Feb 27, 2008 at 12:39 PM, Adriano Manocchia <[EMAIL PROTECTED]> wrote: > Hi all, > > I've been chasing what I think is the same performance issue for about > a year and it's driving me batty. First off, the server is a dual core > 2.8 P4 with 2G RAM running RHEL5 hosted at The Planet and is under > very light load. This problem started last year while the server was > RHEL4 and I completely rebuilt it with RHEL5. [snip all of the good stuff --- thanks for a well-written question!] Adriano, It really depends on what PHP is expected to do prior to serving the content. Some things to consider: Are you loading a bunch of modules in your php.ini? What is the script doing? Is it reading/writing files? Including files? If so, are they local or remote? What happens if you take a static HTML page and rename it with a .php extension and compare load times? The last of the questions will be of the most help in determining which of the first two would be more applicable, because when you rename the extension, PHP will be loaded by Apache. This means: a.) If the performance is degraded by comparison, it's a slow-loading PHP engine. b.) If the benchmarks are comparable, then it's likely something in your PHP script(s). -- Daniel P. Brown Senior Unix Geek -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] performance/load testing ...
apache benchmark, aka "ab" comes with apache and lets you hit your server as many times as you want. Also see wget and valgrind/callgrind For Windows users, there's something called SuperSmack or some equally silly name... :-) On Mon, January 21, 2008 3:50 am, Jochem Maas wrote: > hi guys, > > I need to do some performance testing for a site of mine. > I want to compare performance of various combinations > of using APC, Squid, Apache/LightHTTPD mod_php/fastcgi. > > all very well I can build the various setups but I'm stuck as > to how to go about recreating realistic load on the machine in > question. > > I don't want to have to go out and buy some commercial software. > > STFW is making my head spin. > > Does anyone have any tips, urls, advice as to how to start > going about creating something like a 'test suite' for testing > high load performance of a website? > > TIA > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] performance/load testing ...
On Jan 21, 2008 5:50 AM, Jochem Maas <[EMAIL PROTECTED]> wrote: > Ron Rademaker schreef: > > Jochem Maas wrote: > >> Ron Rademaker schreef: > >>> Hi Jochem, > >>> > >>> Apache comes with an nice ab tool which stands for apache > >>> benchmarking. You can use this to benchmark stuff like concurrent > >>> requests. > >> > >> indeed, I know ab, but it doesn't allow for a very realistic request > >> 'spread' > >> - at least as far as I know. > > Indeed it doesn't, but you appear to want to figure out what > > optimization works best. You don't need realistic spread for that, even > > more I think you shouldn't want realistic spread for that but something > > comparable instead. If anything, the result of ab are very useful for > > comparing results. > > hmm, you have a point - I guess I'll get stuck in. > > > >> > >> I was hoping for a bit more detailed info on mimicking real-world site > >> usage, > >> e.g. maybe using access logs as a source of url data? > >> > >>> > >>> Ron > >>> > >>> Jochem Maas wrote: > hi guys, > > I need to do some performance testing for a site of mine. > I want to compare performance of various combinations > of using APC, Squid, Apache/LightHTTPD mod_php/fastcgi. > > all very well I can build the various setups but I'm stuck as > to how to go about recreating realistic load on the machine in > question. > > I don't want to have to go out and buy some commercial software. > > STFW is making my head spin. > > Does anyone have any tips, urls, advice as to how to start > going about creating something like a 'test suite' for testing > high load performance of a website? > > TIA > > >>> > >> > >> > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > Maybe look at http://www.acme.com/software/http_load/ You can configure a big text file of urls for it to hit randomly and such. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] performance/load testing ...
Ron Rademaker schreef: Jochem Maas wrote: Ron Rademaker schreef: Hi Jochem, Apache comes with an nice ab tool which stands for apache benchmarking. You can use this to benchmark stuff like concurrent requests. indeed, I know ab, but it doesn't allow for a very realistic request 'spread' - at least as far as I know. Indeed it doesn't, but you appear to want to figure out what optimization works best. You don't need realistic spread for that, even more I think you shouldn't want realistic spread for that but something comparable instead. If anything, the result of ab are very useful for comparing results. hmm, you have a point - I guess I'll get stuck in. I was hoping for a bit more detailed info on mimicking real-world site usage, e.g. maybe using access logs as a source of url data? Ron Jochem Maas wrote: hi guys, I need to do some performance testing for a site of mine. I want to compare performance of various combinations of using APC, Squid, Apache/LightHTTPD mod_php/fastcgi. all very well I can build the various setups but I'm stuck as to how to go about recreating realistic load on the machine in question. I don't want to have to go out and buy some commercial software. STFW is making my head spin. Does anyone have any tips, urls, advice as to how to start going about creating something like a 'test suite' for testing high load performance of a website? TIA -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] performance/load testing ...
Jochem Maas wrote: Ron Rademaker schreef: Hi Jochem, Apache comes with an nice ab tool which stands for apache benchmarking. You can use this to benchmark stuff like concurrent requests. indeed, I know ab, but it doesn't allow for a very realistic request 'spread' - at least as far as I know. Indeed it doesn't, but you appear to want to figure out what optimization works best. You don't need realistic spread for that, even more I think you shouldn't want realistic spread for that but something comparable instead. If anything, the result of ab are very useful for comparing results. I was hoping for a bit more detailed info on mimicking real-world site usage, e.g. maybe using access logs as a source of url data? Ron Jochem Maas wrote: hi guys, I need to do some performance testing for a site of mine. I want to compare performance of various combinations of using APC, Squid, Apache/LightHTTPD mod_php/fastcgi. all very well I can build the various setups but I'm stuck as to how to go about recreating realistic load on the machine in question. I don't want to have to go out and buy some commercial software. STFW is making my head spin. Does anyone have any tips, urls, advice as to how to start going about creating something like a 'test suite' for testing high load performance of a website? TIA -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] performance/load testing ...
Ron Rademaker schreef: Hi Jochem, Apache comes with an nice ab tool which stands for apache benchmarking. You can use this to benchmark stuff like concurrent requests. indeed, I know ab, but it doesn't allow for a very realistic request 'spread' - at least as far as I know. I was hoping for a bit more detailed info on mimicking real-world site usage, e.g. maybe using access logs as a source of url data? Ron Jochem Maas wrote: hi guys, I need to do some performance testing for a site of mine. I want to compare performance of various combinations of using APC, Squid, Apache/LightHTTPD mod_php/fastcgi. all very well I can build the various setups but I'm stuck as to how to go about recreating realistic load on the machine in question. I don't want to have to go out and buy some commercial software. STFW is making my head spin. Does anyone have any tips, urls, advice as to how to start going about creating something like a 'test suite' for testing high load performance of a website? TIA -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] performance/load testing ...
On Mon, 2008-01-21 at 10:50 +0100, Jochem Maas wrote: > Does anyone have any tips, urls, advice as to how to start > going about creating something like a 'test suite' for testing > high load performance of a website? > I went through a similar headache recently, and looked at a whole whack of testing suites that are available. You can take a look at http://www.opensourcetesting.org/performance.php first, but I ended up using Apache JMeter most. It really is quite configurable and usable and gives you a lot of information. --Paul -- . | Chisimba PHP5 Framework - http://avoir.uwc.ac.za | :: All Email originating from UWC is covered by disclaimer http://www.uwc.ac.za/portal/public/portal_services/disclaimer.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance question for table updating
On Nov 24, 2007 2:32 AM, Jon Westcot <[EMAIL PROTECTED]> wrote: > Hi all: > > For those who've been following the saga, I'm working on an application > that needs to load > a data file consisting of approximately 29,000 to 35,000 records in it (and > not short ones, > either) into several tables. I'm using MySQL as the database. > > I've noticed a really horrible performance difference between INSERTing > rows into the > table and UPDATEing rows with new data when they already exist in the table. > For > example, when I first start with an empty table, the application inserts > around 29,600 > records in something less than 6 minutes. But, when I use the second file, > updating that > same table takes over 90 minutes. > > Here's my question: I had assumed -- probably wrongly -- that it would be > far more > expedient to only update rows where data had actually changed; moreover, that > I should > only update the changed fields in the particular rows. This involves a large > number of if > statements, i.e., > > if($old_row["field_a"] !== $new_row["field_66"] { > $update_query .= "field_a = '" . > mysql_real_escape_string($new_row["field_66"]) . "',"; > } > > Eventually, I wind up with a query similar to: > > UPDATE table_01 SET field_a = 'New value here', updated=CURDATE() > WHERE > primary_key=12345 > > I thought that, to keep the table updating to a minimum, this approach > made the most > sense. However, seeing the two hugely different performance times has made > me question > whether or not it would be faster to simply update every field in the table > and eliminate all of > these test conditions. > I don't think indexes are really your trouble. Based on what you've posted, it looks like you are selecting the entire data set from MySQL back to PHP and then looping through each record to compare the new and old values to build your queries. If that's the case, it will almost assuredly be faster to just loop through the new data and update everything (even if nothing has changed). Otherwise, you have the added network traffic to send the entire result set back from MySQL to PHP plus the per-row, per-column comparisons, string concatenation operations, and finally another round trip across the network to MySQL again to execute the query for each row in the data. If you want to keep some of your optimizations, you can still loop through the data in your file and build statements like this: UPDATE table_01 SET field_a = 'New value for a', field_b = 'New value for b', updated=CURDATE() WHERE primary_key=12345 AND NOT ( field_a = 'New value for a' AND field_b = 'New value for b' ) This way, if nothing in the record has changed, you still have a trip to MySQL but MySQL has very little work to do since it will find the record by the primary key, then see that no values have changed, and update nothing. No indexes need updated and even your `updated` field is not changed. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance question for table updating
Eventually, I wind up with a query similar to: UPDATE table_01 SET field_a = 'New value here', updated=CURDATE() WHERE primary_key=12345 Even though you've solved it one way to work out the problem here would be to change it to a select query (unfortunately mysql can't explain insert/update/delete statements - which would make it a lot easier). ie change it to select 1 from table where primary_key=12345; If that's slow, then you're missing an index on primary_key. If that's fast.. err, you're back to square one :/ or maybe you have too many indexes (which means the update process is spending all of it's time updating the fields & indexes). -- Postgresql & php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance question for table updating (SOLVED)
On Sat, 2007-11-24 at 04:03 -0700, Jon Westcot wrote: > > Moral of the story? Two, really. First, ensure you always reference > values in the way most appropriate for their type. Second, don't make your > idiocy public by asking stupid questions on a public forum. What's the > quote (probably attributed to Churchill)? "It is better to be ignorant and > silent than to voice one's opinions and remove all doubt." ;) I don't think that phrase applies to your situation... I'd say you did the right thing. Far too often people are afraid of reprisal or seeming stupid and so a problem doesn't get solved until it's far too late and its effects become magnified. Here's a more apt quote for your situation: "It's better to be an idiot for 10 minutes than a failure for the rest of your life." -- Me :) Cheers, Rob. -- ... SwarmBuy.com - http://www.swarmbuy.com Leveraging the buying power of the masses! ... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Performance question for table updating (SOLVED)
Could there be some performance gain by uploading the data to another table and then update / insert via sql? bastien > From: [EMAIL PROTECTED] > To: php-general@lists.php.net > Date: Sat, 24 Nov 2007 04:03:53 -0700 > Subject: Re: [PHP] Performance question for table updating (SOLVED) > > Hi Rob, et al.: > > - Original Message - > From: "Andrés Robinet" >>> -Original Message- >>> From: Jon Westcot [mailto:[EMAIL PROTECTED] >>> >>> :: gigantic snip here:: >>> >>> So, long story short (oops -- too late!), what's the concensus >>> among the learned assembly here? Is it faster to just UPDATE the >>> record if it already exists regardless of the fact that maybe only one >>> or two out of 75 or more fields changed versus testing each one of >>> those 75 fields to try and figure out which ones actually changed and >>> then only update those? >>> >>> I look forward to reading all of your thoughts. >>> >>> Sincerely, >>> >>> Jon >> >> I don't know about consensus over here because I'm kind of newgie (stands >> for new geek, as opposed to newbie which stands for new ball breaker :D :D >> ). I don't know of your previous messages but I can tell you one story... >> Some time ago I got involved in a project that required geo-distance >> calculation (you know distance between two points with latitude and >> longitude). Basically I had to take a set of points and calculate the >> distance of each of those points to a given (reference) one. The math was >> something like the "square root of the sum of a constant times the square >> sin of..." well, I can't remember it, but the point is, it was a > complicated >> formula, which I thought it would allow for some optimizations in PHP. >> Accustomed to regular (compiled) programming languages I developed a set > of >> routines to optimize the task and went ahead and queried the database for >> the (say, 1000 records) dataset of points. Then applied the math to the >> points and the reference point and got the result... in about 5 minutes to >> my (disgusting) surprise. >> Then I grabbed the MySQL manual, built a "non-optimized" version of the >> formula to put directly in the SQL query and get the "shortest distance" >> (which was my goal in the end) calculated by MySQL right away. I thought >> "ok, I'll prepare a cup of coffee to wait for MySQL to finish the >> calculation". To my surprise the query returned the expected result in > less >> than 2 seconds. >> My logic was (wrongly) the following: PHP is a programming language, SQL > is >> a data access language; I'll get the data using MySQL and do the math > using >> PHP. But I forgot PHP is an interpreted language, that a number is more > than >> a number to PHP, but a ZVAL_ object behind the scenes. I forgot >> about the memory and the time required to build those objects when one >> retrieves data out of a database server. I forgot about parsing time, and >> "support logic and safety checks" in the language that overkill any > attempt >> to build TDCPL (Too Damn Complex Programming Logic) in PHP. >> So, now, when I have to do some logic stuff to the retrieved data, I first >> check "how much" I can push into the query itself, to get little or > nothing >> of programming logic in PHP after retrieving (before storing) the data. >> All that said, I'd give a shot to the MySQL REPLACE function (I wouldn't >> even branch the code to use INSERT or UPDATE depending on the record > already >> existing or not, If you have a primary key, all you need is REPLACE). But, >> PLEASE LOOK AT THE GOTCHAS (like set col_name=col_name+1). Furthermore, If >> those data files were to be uploaded by me (I mean, me, the coder, not the >> end user), I'd build (use) a program to convert them to SQL sentences in > my >> desktop PC where I can use faster programming languages and I can wait for >> five minutes of heavy processing (instead of overkilling the server for > five >> minutes which will slow down every other service in there). >> In the end it depends on your requirements and where you get the data from >> and if and how you want to automate the task (I didn't get your previous >> messages, I got subscribed recently, if you can send me a link to those >> ones... great!) >> >> Rob > > Thanks for the comments and suggestions. Pri
Re: [PHP] Performance question for table updating (SOLVED)
Hi Rob, et al.: - Original Message - From: "Andrés Robinet" <[EMAIL PROTECTED]> > > -Original Message- > > From: Jon Westcot [mailto:[EMAIL PROTECTED] > > > > :: gigantic snip here:: > > > > So, long story short (oops -- too late!), what's the concensus > > among the learned assembly here? Is it faster to just UPDATE the > > record if it already exists regardless of the fact that maybe only one > > or two out of 75 or more fields changed versus testing each one of > > those 75 fields to try and figure out which ones actually changed and > > then only update those? > > > > I look forward to reading all of your thoughts. > > > > Sincerely, > > > > Jon > > I don't know about consensus over here because I'm kind of newgie (stands > for new geek, as opposed to newbie which stands for new ball breaker :D :D > ). I don't know of your previous messages but I can tell you one story... > Some time ago I got involved in a project that required geo-distance > calculation (you know distance between two points with latitude and > longitude). Basically I had to take a set of points and calculate the > distance of each of those points to a given (reference) one. The math was > something like the "square root of the sum of a constant times the square > sin of..." well, I can't remember it, but the point is, it was a complicated > formula, which I thought it would allow for some optimizations in PHP. > Accustomed to regular (compiled) programming languages I developed a set of > routines to optimize the task and went ahead and queried the database for > the (say, 1000 records) dataset of points. Then applied the math to the > points and the reference point and got the result... in about 5 minutes to > my (disgusting) surprise. > Then I grabbed the MySQL manual, built a "non-optimized" version of the > formula to put directly in the SQL query and get the "shortest distance" > (which was my goal in the end) calculated by MySQL right away. I thought > "ok, I'll prepare a cup of coffee to wait for MySQL to finish the > calculation". To my surprise the query returned the expected result in less > than 2 seconds. > My logic was (wrongly) the following: PHP is a programming language, SQL is > a data access language; I'll get the data using MySQL and do the math using > PHP. But I forgot PHP is an interpreted language, that a number is more than > a number to PHP, but a ZVAL_ object behind the scenes. I forgot > about the memory and the time required to build those objects when one > retrieves data out of a database server. I forgot about parsing time, and > "support logic and safety checks" in the language that overkill any attempt > to build TDCPL (Too Damn Complex Programming Logic) in PHP. > So, now, when I have to do some logic stuff to the retrieved data, I first > check "how much" I can push into the query itself, to get little or nothing > of programming logic in PHP after retrieving (before storing) the data. > All that said, I'd give a shot to the MySQL REPLACE function (I wouldn't > even branch the code to use INSERT or UPDATE depending on the record already > existing or not, If you have a primary key, all you need is REPLACE). But, > PLEASE LOOK AT THE GOTCHAS (like set col_name=col_name+1). Furthermore, If > those data files were to be uploaded by me (I mean, me, the coder, not the > end user), I'd build (use) a program to convert them to SQL sentences in my > desktop PC where I can use faster programming languages and I can wait for > five minutes of heavy processing (instead of overkilling the server for five > minutes which will slow down every other service in there). > In the end it depends on your requirements and where you get the data from > and if and how you want to automate the task (I didn't get your previous > messages, I got subscribed recently, if you can send me a link to those > ones... great!) > > Rob Thanks for the comments and suggestions. Prior to receiving your note, I went back and did a bit of checking on my code. Turns out that the problem was "hardware" related -- the infamous "Loose Screw Behind the Keyboard." The problem actually boiled down to two quotation marks -- they were present in the search code to see if a record with the specified key existed, but were omitted in the WHERE clause of the UPDATE statement. Said update therefore refused to use the nice little index I'd provided for its use and instead scanned through the entire table to find the record in question. Moral of the story? Two, really. First, ensure you always reference values in the way most appropriate for their type. Second, don't make your idiocy public by asking stupid questions on a public forum. What's the quote (probably attributed to Churchill)? "It is better to be ignorant and silent than to voice one's opinions and remove all doubt." ;) Jon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Performance question for table updating
> -Original Message- > From: Jon Westcot [mailto:[EMAIL PROTECTED] > Sent: Saturday, November 24, 2007 4:32 AM > To: PHP General > Subject: [PHP] Performance question for table updating > > Hi all: > > For those who've been following the saga, I'm working on an > application that needs to load a data file consisting of approximately > 29,000 to 35,000 records in it (and not short ones, either) into > several tables. I'm using MySQL as the database. > > I've noticed a really horrible performance difference between > INSERTing rows into the table and UPDATEing rows with new data when > they already exist in the table. For example, when I first start with > an empty table, the application inserts around 29,600 records in > something less than 6 minutes. But, when I use the second file, > updating that same table takes over 90 minutes. > > Here's my question: I had assumed -- probably wrongly -- that it > would be far more expedient to only update rows where data had actually > changed; moreover, that I should only update the changed fields in the > particular rows. This involves a large number of if statements, i.e., > > if($old_row["field_a"] !== $new_row["field_66"] { > $update_query .= "field_a = '" . > mysql_real_escape_string($new_row["field_66"]) . "',"; > } > > Eventually, I wind up with a query similar to: > > UPDATE table_01 SET field_a = 'New value here', > updated=CURDATE() WHERE primary_key=12345 > > I thought that, to keep the table updating to a minimum, this > approach made the most sense. However, seeing the two hugely different > performance times has made me question whether or not it would be > faster to simply update every field in the table and eliminate all of > these test conditions. > > And, before someone comments that indexes on the table can cause > performance hits, I DROP nearly all of the indexes at the start of the > processing, only keeping those indexes necessary to do the original > INSERT or the subsequent UPDATE, and then add all of the extra > "steroid" indexes (you know -- the performance-enhancing ones ) > after all of the INSERTs and UPDATEs have been finished. > > So, long story short (oops -- too late!), what's the concensus > among the learned assembly here? Is it faster to just UPDATE the > record if it already exists regardless of the fact that maybe only one > or two out of 75 or more fields changed versus testing each one of > those 75 fields to try and figure out which ones actually changed and > then only update those? > > I look forward to reading all of your thoughts. > > Sincerely, > > Jon I don't know about consensus over here because I'm kind of newgie (stands for new geek, as opposed to newbie which stands for new ball breaker :D :D ). I don't know of your previous messages but I can tell you one story... Some time ago I got involved in a project that required geo-distance calculation (you know distance between two points with latitude and longitude). Basically I had to take a set of points and calculate the distance of each of those points to a given (reference) one. The math was something like the "square root of the sum of a constant times the square sin of..." well, I can't remember it, but the point is, it was a complicated formula, which I thought it would allow for some optimizations in PHP. Accustomed to regular (compiled) programming languages I developed a set of routines to optimize the task and went ahead and queried the database for the (say, 1000 records) dataset of points. Then applied the math to the points and the reference point and got the result... in about 5 minutes to my (disgusting) surprise. Then I grabbed the MySQL manual, built a "non-optimized" version of the formula to put directly in the SQL query and get the "shortest distance" (which was my goal in the end) calculated by MySQL right away. I thought "ok, I'll prepare a cup of coffee to wait for MySQL to finish the calculation". To my surprise the query returned the expected result in less than 2 seconds. My logic was (wrongly) the following: PHP is a programming language, SQL is a data access language; I'll get the data using MySQL and do the math using PHP. But I forgot PHP is an interpreted language, that a number is more than a number to PHP, but a ZVAL_ object behind the scenes. I forgot about the memory and the time required to build those objects when one retrieves data out of a database server. I forgot about parsing time, and "support logic and safety checks" in the language that overkill any attempt to build TDCPL (Too Damn Complex Programming Logic) in PHP. So, now, when I have to do some logic stuff to the retrieved data, I first check "how much" I can push into the query itself, to get little or nothing of programming logic in PHP after retrieving (before storing) the data. All that said, I'd give a shot to the MySQL REPLACE function (I wouldn't even branch the code to
Re: [PHP] Performance of PHP
Merlin wrote: > Hi there, > > I am doing some image cropping of about 40.000 files with php. If you're worried about performance, maybe why not use mogrify from ImageMagick? /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance of PHP
Merlin wrote: Hi there, I am doing some image cropping of about 40.000 files with php. To do this I wrote a PHP file that does what I want and I did disable the timeout so I can call it via webbrowser and fire the script. There are two down sides I see: 1. One image takes about 0.25 s, so the whole process would take about 3 hours. 2. During that time a spider could come along and find that file and fire it again. Is it faster if I would issue this by command line on the linux server? php filename.php If your site is running on Apache, you can restrict access to spiders. It is quite easy to set up with a .htaccess file in your script directory. Thank you for any help, Merlin -- With Warm Regards, Sudheer. S http://www.binaryvibes.co.in -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: PHP Performance and System Load
Hi, I had lots of loop in my code. My gain was %4 to %6 and I say "may gain another %10". Of course your millage was different than me Regards Sancar On Saturday 21 July 2007 01:03:45 Richard Lynch wrote: > On Fri, July 20, 2007 4:16 am, Colin Guthrie wrote: > > Sancar Saran wrote: > >> Another simple performance tip. > >> > >> Most of for examples of php look like this > >> for($x=0;$x >> > >> This is bad. In every cycle you call sizeof > >> > >> this was good > >> $intSize = sizeof($arrSometing); > >> for($x=0;$x<$intSize;$x++) > >> > >> if u use. > >> for($x=0;$x<$intSiz;++$x). You may gain another %10 > >> > >> to determine costs of your functions use xdebug and kcachegrind. > > > > I've always used pre-increment in loops like you suggest as it was an > > ingrained part of my C/C++ learning from a performance perspective. I > > wasn't sure if the same was true in PHP but you seem to suggest it is, > > so I feel justified now :) > > I don't really care if one uses pre or post, but I just benchmarked > this, and I don't really think it makes a 10% win. > > And I had to crank it up to 10 MILLION to get any kind of realistic > measurable time in the first place. > > How often do you have a PHP loop that runs to 10 MILLION iterations?! > > Note that I did three with pre before post tests and three post before > pre tests to even out any caching effects. > > Test environment details at the bottom. > > [EMAIL PROTECTED] ~/junk $ cat pre.php post.php > for ($i = 0; $i < 1000; ++$i); > ?> > for ($i = 0; $i < 1000; $i++); > ?> > [EMAIL PROTECTED] ~/junk $ time php -q pre.php ; time php -q > post.php > > real0m5.422s > user0m5.350s > sys 0m0.070s > > real0m5.397s > user0m5.330s > sys 0m0.070s > [EMAIL PROTECTED] ~/junk $ time php -q pre.php ; time php -q > post.php > > real0m5.164s > user0m5.090s > sys 0m0.070s > > real0m5.310s > user0m5.230s > sys 0m0.080s > [EMAIL PROTECTED] ~/junk $ time php -q pre.php ; time php -q > post.php > > real0m5.093s > user0m5.030s > sys 0m0.070s > > real0m5.387s > user0m5.300s > sys 0m0.080s > [EMAIL PROTECTED] ~/junk $ time php -q post.php ; time php -q > pre.php > > real0m5.429s > user0m5.340s > sys 0m0.070s > > real0m5.140s > user0m5.060s > sys 0m0.080s > [EMAIL PROTECTED] ~/junk $ time php -q post.php ; time php -q > pre.php > > real0m5.348s > user0m5.270s > sys 0m0.070s > > real0m5.101s > user0m5.030s > sys 0m0.070s > [EMAIL PROTECTED] ~/junk $ time php -q post.php ; time php -q > pre.php > > real0m5.376s > user0m5.300s > sys 0m0.080s > > real0m5.009s > user0m4.910s > sys 0m0.100s > > [EMAIL PROTECTED] ~/junk $ php -v > PHP 4.4.7 (cli) (built: May 8 2007 09:49:19) > Copyright (c) 1997-2007 The PHP Group > Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies > > [EMAIL PROTECTED] ~/junk $ uname -a > Linux ch10106cus002 2.6.18-hardened-r6 #2 SMP Tue Apr 17 09:15:05 CDT > 2007 i686 Dual Core AMD Opteron(tm) Processor 270 AuthenticAMD > GNU/Linux > [EMAIL PROTECTED] ~/junk $ > > Perhaps the OP meant that not doing the count() / sizeof() on every > iteration was a 10% win? Now *THAT* I can believe! > > -- > Some people have a "gift" link here. > Know what I want? > I want you to buy a CD from some indie artist. > http://cdbaby.com/browse/from/lynch > Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: PHP Performance and System Load
On Fri, July 20, 2007 4:16 am, Colin Guthrie wrote: > Sancar Saran wrote: >> Another simple performance tip. >> >> Most of for examples of php look like this >> for($x=0;$x> >> This is bad. In every cycle you call sizeof >> >> this was good >> $intSize = sizeof($arrSometing); >> for($x=0;$x<$intSize;$x++) >> >> if u use. >> for($x=0;$x<$intSiz;++$x). You may gain another %10 >> >> to determine costs of your functions use xdebug and kcachegrind. > > I've always used pre-increment in loops like you suggest as it was an > ingrained part of my C/C++ learning from a performance perspective. I > wasn't sure if the same was true in PHP but you seem to suggest it is, > so I feel justified now :) I don't really care if one uses pre or post, but I just benchmarked this, and I don't really think it makes a 10% win. And I had to crank it up to 10 MILLION to get any kind of realistic measurable time in the first place. How often do you have a PHP loop that runs to 10 MILLION iterations?! Note that I did three with pre before post tests and three post before pre tests to even out any caching effects. Test environment details at the bottom. [EMAIL PROTECTED] ~/junk $ cat pre.php post.php [EMAIL PROTECTED] ~/junk $ time php -q pre.php ; time php -q post.php real0m5.422s user0m5.350s sys 0m0.070s real0m5.397s user0m5.330s sys 0m0.070s [EMAIL PROTECTED] ~/junk $ time php -q pre.php ; time php -q post.php real0m5.164s user0m5.090s sys 0m0.070s real0m5.310s user0m5.230s sys 0m0.080s [EMAIL PROTECTED] ~/junk $ time php -q pre.php ; time php -q post.php real0m5.093s user0m5.030s sys 0m0.070s real0m5.387s user0m5.300s sys 0m0.080s [EMAIL PROTECTED] ~/junk $ time php -q post.php ; time php -q pre.php real0m5.429s user0m5.340s sys 0m0.070s real0m5.140s user0m5.060s sys 0m0.080s [EMAIL PROTECTED] ~/junk $ time php -q post.php ; time php -q pre.php real0m5.348s user0m5.270s sys 0m0.070s real0m5.101s user0m5.030s sys 0m0.070s [EMAIL PROTECTED] ~/junk $ time php -q post.php ; time php -q pre.php real0m5.376s user0m5.300s sys 0m0.080s real0m5.009s user0m4.910s sys 0m0.100s [EMAIL PROTECTED] ~/junk $ php -v PHP 4.4.7 (cli) (built: May 8 2007 09:49:19) Copyright (c) 1997-2007 The PHP Group Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies [EMAIL PROTECTED] ~/junk $ uname -a Linux ch10106cus002 2.6.18-hardened-r6 #2 SMP Tue Apr 17 09:15:05 CDT 2007 i686 Dual Core AMD Opteron(tm) Processor 270 AuthenticAMD GNU/Linux [EMAIL PROTECTED] ~/junk $ Perhaps the OP meant that not doing the count() / sizeof() on every iteration was a 10% win? Now *THAT* I can believe! -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP Performance and System Load
Sancar Saran wrote: > Another simple performance tip. > > Most of for examples of php look like this > for($x=0;$x > This is bad. In every cycle you call sizeof > > this was good > $intSize = sizeof($arrSometing); > for($x=0;$x<$intSize;$x++) > > if u use. > for($x=0;$x<$intSiz;++$x). You may gain another %10 > > to determine costs of your functions use xdebug and kcachegrind. I've always used pre-increment in loops like you suggest as it was an ingrained part of my C/C++ learning from a performance perspective. I wasn't sure if the same was true in PHP but you seem to suggest it is, so I feel justified now :) Col -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] performance down
Tijnema ! wrote: > On 4/24/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >> Hello everyone, >> >> recently we tested upgrading our systems from: >>apache 2.0.55 >>php 5.1.6 >>eacclerator 0.9.5 >> to: >>apache 2.2.3 >>php 5.2.0 >>eaccelerator 0.9.5 >> >> but we always get worse performance than before. So maybe it is the newer >> apache version which slows us down or changes in php 5.2.0. >> Has anyone come across a similar phenomenon? >> >> >> Dominic Letz > > > What platform are you using? Windows or Linux? > > Never had any slow PHP versions on my Linux server. **SLOWER** it's a comparative not an absolute. know the difference. either go back to comparing print & echo or realise that (for example) a spaceshuttle is fast and an F1 racecar is fast but one if *faster* than the other. the OP asked about comparative performance degradation. sorry OP I can't comment on the degradation your seeing, but I'm interested if anyone can - in the mean time you might consider downgrading apache and measuring the difference and subsequently upgrading apache whilst downgrading php and measuring the difference also - it might give you a clue as to which beast is causing the problem. you might also consider that it's not the upgrade as such but the server configuration (for apache mostly) that is sub optimal. > > Tijnema > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] performance down
On 4/24/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: Hello everyone, recently we tested upgrading our systems from: apache 2.0.55 php 5.1.6 eacclerator 0.9.5 to: apache 2.2.3 php 5.2.0 eaccelerator 0.9.5 but we always get worse performance than before. So maybe it is the newer apache version which slows us down or changes in php 5.2.0. Has anyone come across a similar phenomenon? Dominic Letz What platform are you using? Windows or Linux? Never had any slow PHP versions on my Linux server. Tijnema -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance: While or For loop
On 3/27/07, Travis Doherty <[EMAIL PROTECTED]> wrote: Jake Gardner wrote: > He said if you run the /script/ itself 1000 times, not a loop with 1000 > iterations. This is quite possible; I am fairly certain there are > websites > out there that get accessed well over 1000 times a minute, yes? > > So every minute, that website is saving a total of 2.6 seconds to do... > whatever it is websites do in their free time. > > In reality, scripts rarely get executed once and then are deleted; > they are > used repetitively, and the more a script is used, the more significant > the > gain. Claiming to look practically on a small gain /within one > execution of > a script/ is impractical in itself. I still wouldn't go around telling people to re-write all of their code to use for loops instead of while loops (or whatever was faster for whatever architecture.) While loops came out faster :) Keep in mind that .000xx seconds in performance improvement certainly does make a difference on a site that is accessed millions of times a day, however, one bug caused by writing code that reads poorly instead of writing clean code can cost a *lot* more in the end. - Use what reads easier when deciding if a for/while loop is best. - Profile your code and find the right places to optimize. Optimizing code that takes .0001 seconds to run down to .1 seconds is great, 10x improvement! Who cares. Find the chunk that takes 0.5 seconds to run and optimize that to 0.05 seconds. 10x improvement still, except that this time it actually makes a practical difference. Travis Doherty I'm not telling people to rewrite the code, but if you need to choose, and both are good for the job, choose while :) Tijnema -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance: While or For loop
Jake Gardner wrote: > He said if you run the /script/ itself 1000 times, not a loop with 1000 > iterations. This is quite possible; I am fairly certain there are > websites > out there that get accessed well over 1000 times a minute, yes? > > So every minute, that website is saving a total of 2.6 seconds to do... > whatever it is websites do in their free time. > > In reality, scripts rarely get executed once and then are deleted; > they are > used repetitively, and the more a script is used, the more significant > the > gain. Claiming to look practically on a small gain /within one > execution of > a script/ is impractical in itself. I still wouldn't go around telling people to re-write all of their code to use for loops instead of while loops (or whatever was faster for whatever architecture.) Keep in mind that .000xx seconds in performance improvement certainly does make a difference on a site that is accessed millions of times a day, however, one bug caused by writing code that reads poorly instead of writing clean code can cost a *lot* more in the end. - Use what reads easier when deciding if a for/while loop is best. - Profile your code and find the right places to optimize. Optimizing code that takes .0001 seconds to run down to .1 seconds is great, 10x improvement! Who cares. Find the chunk that takes 0.5 seconds to run and optimize that to 0.05 seconds. 10x improvement still, except that this time it actually makes a practical difference. Travis Doherty -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance: While or For loop
He said if you run the /script/ itself 1000 times, not a loop with 1000 iterations. This is quite possible; I am fairly certain there are websites out there that get accessed well over 1000 times a minute, yes? So every minute, that website is saving a total of 2.6 seconds to do... whatever it is websites do in their free time. In reality, scripts rarely get executed once and then are deleted; they are used repetitively, and the more a script is used, the more significant the gain. Claiming to look practically on a small gain /within one execution of a script/ is impractical in itself. On 3/26/07, Richard Lynch <[EMAIL PROTECTED]> wrote: On Sat, March 24, 2007 4:52 am, Tijnema ! wrote: >> That means that at 1000 iterations, you are "saving" how much time? >> >> .00026 seconds? >> .4 seconds? >> >> Puhleaze. > > Well, if you execute this script 1000 times, you would get a > difference of 2.6 seconds? > But if every microseconds counts for your script, then you should now > about this. No. Re-read the benchmards. At 1000 iterations you're looking at .000xx seconds. At a MILLION iterations, you're looking at 0.xx seconds At a TEN MILLION iterations, you've broken the 1-second barrier. How many PHP scripts do a for or while loop 10 million iterations? xx is either 26 or 4, depending on whose benchmarks you believe. Running tests with 10 million iterations to benchmark is great for removing overhead margin of error. It's also great to look at exactly how many times you'd have to do something to make a significant savings. -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance: While or For loop
On Sat, March 24, 2007 4:52 am, Tijnema ! wrote: >> That means that at 1000 iterations, you are "saving" how much time? >> >> .00026 seconds? >> .4 seconds? >> >> Puhleaze. > > Well, if you execute this script 1000 times, you would get a > difference of 2.6 seconds? > But if every microseconds counts for your script, then you should now > about this. No. Re-read the benchmards. At 1000 iterations you're looking at .000xx seconds. At a MILLION iterations, you're looking at 0.xx seconds At a TEN MILLION iterations, you've broken the 1-second barrier. How many PHP scripts do a for or while loop 10 million iterations? xx is either 26 or 4, depending on whose benchmarks you believe. Running tests with 10 million iterations to benchmark is great for removing overhead margin of error. It's also great to look at exactly how many times you'd have to do something to make a significant savings. -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance: While or For loop
On Sat, 2007-03-24 at 14:38 -0400, tedd wrote: > At 2:24 PM -0400 3/24/07, Robert Cummings wrote: > >On Sat, 2007-03-24 at 10:21 -0400, tedd wrote: > >> At 7:47 PM -0500 3/23/07, Richard Lynch wrote: > >> >Folks: > >> > > >> >How often do you use a loop of any kind in PHP with enough iterations > >> >that this is even significant? > >> > > >> >Write the code that makes sense. > >> > > >> >Optimize the biggest bottleneck until performance is acceptable. > >> > >> Absolutely -- the time we take discussing these types of concerns > >> probably cost more cycles than the sum total of all the "optimized" > >> savings in the lifetime of all the computers on earth. > > > >I highly doubt it. Computers run a lot these days. There are times when > >squeezing that last nanosecond makes a difference and the devotion to > >finding how to squeeze it out is well worth it. Admittedly they may be > >few and far between, but they do exist. > > And, I highly doubt that the difference is worth considering -- and > it's becoming less of a consideration each day. > > Remember, we were talking about the differences between a "for" vs > "while" loop. Ahh, but it was the pre-increment versus post-increment that made the difference. every bit counts, it's the same problem as energy savings. If you only do it in one place you don't really see a savings, if you do it everywhere, it begins to have an impact. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance: While or For loop
At 2:24 PM -0400 3/24/07, Robert Cummings wrote: On Sat, 2007-03-24 at 10:21 -0400, tedd wrote: At 7:47 PM -0500 3/23/07, Richard Lynch wrote: >Folks: > >How often do you use a loop of any kind in PHP with enough iterations >that this is even significant? > >Write the code that makes sense. > >Optimize the biggest bottleneck until performance is acceptable. Absolutely -- the time we take discussing these types of concerns probably cost more cycles than the sum total of all the "optimized" savings in the lifetime of all the computers on earth. I highly doubt it. Computers run a lot these days. There are times when squeezing that last nanosecond makes a difference and the devotion to finding how to squeeze it out is well worth it. Admittedly they may be few and far between, but they do exist. And, I highly doubt that the difference is worth considering -- and it's becoming less of a consideration each day. Remember, we were talking about the differences between a "for" vs "while" loop. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance: While or For loop
On Sat, 2007-03-24 at 10:21 -0400, tedd wrote: > At 7:47 PM -0500 3/23/07, Richard Lynch wrote: > >Folks: > > > >How often do you use a loop of any kind in PHP with enough iterations > >that this is even significant? > > > >Write the code that makes sense. > > > >Optimize the biggest bottleneck until performance is acceptable. > > Absolutely -- the time we take discussing these types of concerns > probably cost more cycles than the sum total of all the "optimized" > savings in the lifetime of all the computers on earth. I highly doubt it. Computers run a lot these days. There are times when squeezing that last nanosecond makes a difference and the devotion to finding how to squeeze it out is well worth it. Admittedly they may be few and far between, but they do exist. > The time you spend trying to make something faster in those terms > clearly cost more time in development and maintenance. It's a > trade-off that's not worth it. The time you spend can be large, but here we all know now how to speed things up, if we just apply the principles that are easy to apply in all the code we write, then such things will already be optimal and so in hindsight we will already be reaping the rewards without any extra effort. > Q: Do they teach this stuff in college now or are the teachers still > only measuring performance in myopic terms of saving memory and time? > Not a criticism, just a question. They generally teach algorithmic analysis that improves the algorithm's order of magnitude in contrast to teaching constant multiplicative gains. However, that's not to say writing efficient code isn't a good thing. If I have an algorithm that runs in X time, I'm sure if X is 2 years and I can shrink it to x/2 then nobody will quibble about the constant gain since it happens to be 1 year of savings. Now depending on the calculations you're doing, shaving off a nanosecond can indeed have a large enough impact to make it worth your time. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance: While or For loop
At 7:47 PM -0500 3/23/07, Richard Lynch wrote: Folks: How often do you use a loop of any kind in PHP with enough iterations that this is even significant? Write the code that makes sense. Optimize the biggest bottleneck until performance is acceptable. Absolutely -- the time we take discussing these types of concerns probably cost more cycles than the sum total of all the "optimized" savings in the lifetime of all the computers on earth. The time you spend trying to make something faster in those terms clearly cost more time in development and maintenance. It's a trade-off that's not worth it. Q: Do they teach this stuff in college now or are the teachers still only measuring performance in myopic terms of saving memory and time? Not a criticism, just a question. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance: While or For loop
Hi, I'm using so much FOR loops in my code, after seeing discussion I try to test. My findigs it was giving %2 to %10 percent performance boost. So ? My recent template addon to this code cost me around %5 to %10 percent of total page process.. I think It was nice trade off. Thank you guys. Just changing two chars. Regards Sancar -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance: While or For loop
On 3/24/07, Richard Lynch <[EMAIL PROTECTED]> wrote: On Fri, March 23, 2007 7:54 pm, Tijnema ! wrote: > On 3/24/07, Richard Lynch <[EMAIL PROTECTED]> wrote: >> Folks: >> >> How often do you use a loop of any kind in PHP with enough >> iterations >> that this is even significant? >> >> Write the code that makes sense. >> >> Optimize the biggest bottleneck until performance is acceptable. > > It was more likely to get an idea if there was a real difference or > not, and apparently there is not really a big difference. > > But well if you are going to create a script where 1000+ loops are, > you might get a few seconds faster script :) I believe we are seeing times for 1000 iterations around 4 seconds? Or was it 26 seconds? Whatever. That means that at 1000 iterations, you are "saving" how much time? .00026 seconds? .4 seconds? Puhleaze. Well, if you execute this script 1000 times, you would get a difference of 2.6 seconds? But if every microseconds counts for your script, then you should now about this. Tijnema -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance: While or For loop
On Fri, March 23, 2007 7:54 pm, Tijnema ! wrote: > On 3/24/07, Richard Lynch <[EMAIL PROTECTED]> wrote: >> Folks: >> >> How often do you use a loop of any kind in PHP with enough >> iterations >> that this is even significant? >> >> Write the code that makes sense. >> >> Optimize the biggest bottleneck until performance is acceptable. > > It was more likely to get an idea if there was a real difference or > not, and apparently there is not really a big difference. > > But well if you are going to create a script where 1000+ loops are, > you might get a few seconds faster script :) I believe we are seeing times for 1000 iterations around 4 seconds? Or was it 26 seconds? Whatever. That means that at 1000 iterations, you are "saving" how much time? .00026 seconds? .4 seconds? Puhleaze. -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance: While or For loop
On Sat, 2007-03-24 at 01:54 +0100, Tijnema ! wrote: > On 3/24/07, Richard Lynch <[EMAIL PROTECTED]> wrote: > > On Thu, March 22, 2007 5:14 pm, Tijnema ! wrote: > > > On 3/22/07, Jon Anderson <[EMAIL PROTECTED]> wrote: > > >> Your test isn't exactly fair. The for loop has no statements in it, > > >> and > > >> the while loop has one. Your tests show while as approx 7% faster, > > >> while > > >> a modified test shows an approximate 30% speed improvement: > > >> > > >> Do this: > > >> > > >> for ($i=0;$i<1000;$i++) {} > > >> > > >> v.s.: > > >> > > >> $i = 0; > > >> while ($i++ < 1000) {} > > >> > > >> The above while loop is 30% faster than the for. A little teaking on > > >> the > > >> for loop, it's faster still: > > > > Folks: > > > > How often do you use a loop of any kind in PHP with enough iterations > > that this is even significant? > > > > Write the code that makes sense. > > > > Optimize the biggest bottleneck until performance is acceptable. It's not optimization if you just happen to write optimal code out of habit. It's already done. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance: While or For loop
On 3/24/07, Richard Lynch <[EMAIL PROTECTED]> wrote: On Thu, March 22, 2007 5:14 pm, Tijnema ! wrote: > On 3/22/07, Jon Anderson <[EMAIL PROTECTED]> wrote: >> Your test isn't exactly fair. The for loop has no statements in it, >> and >> the while loop has one. Your tests show while as approx 7% faster, >> while >> a modified test shows an approximate 30% speed improvement: >> >> Do this: >> >> for ($i=0;$i<1000;$i++) {} >> >> v.s.: >> >> $i = 0; >> while ($i++ < 1000) {} >> >> The above while loop is 30% faster than the for. A little teaking on >> the >> for loop, it's faster still: Folks: How often do you use a loop of any kind in PHP with enough iterations that this is even significant? Write the code that makes sense. Optimize the biggest bottleneck until performance is acceptable. It was more likely to get an idea if there was a real difference or not, and apparently there is not really a big difference. But well if you are going to create a script where 1000+ loops are, you might get a few seconds faster script :) Tijnema -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance: While or For loop
On Thu, March 22, 2007 5:14 pm, Tijnema ! wrote: > On 3/22/07, Jon Anderson <[EMAIL PROTECTED]> wrote: >> Your test isn't exactly fair. The for loop has no statements in it, >> and >> the while loop has one. Your tests show while as approx 7% faster, >> while >> a modified test shows an approximate 30% speed improvement: >> >> Do this: >> >> for ($i=0;$i<1000;$i++) {} >> >> v.s.: >> >> $i = 0; >> while ($i++ < 1000) {} >> >> The above while loop is 30% faster than the for. A little teaking on >> the >> for loop, it's faster still: Folks: How often do you use a loop of any kind in PHP with enough iterations that this is even significant? Write the code that makes sense. Optimize the biggest bottleneck until performance is acceptable. -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance: While or For loop
On 3/23/07, Mario Guenterberg <[EMAIL PROTECTED]> wrote: On Fri, Mar 23, 2007 at 12:24:45AM -0500, Travis Doherty wrote: > After multiple runs I see that the for pre-increment loop is fastest. > Note that the while loop with a post-increment runs once more than with > a pre-increment. > > Everytime I run, the results are *very* different, though still fall > within similar comparitive domains. Hi... I used your script and my results are different from yours. The post-while increment is generally the fastest result on my machine (Core 2 Duo, php 5.2.1 and apache 2.2.4). I ran the script multiple times: [schnipp ] For pre-increment (10): 0.066 For post-increment (10): 0.066 While pre-increment (10): 0.028 While post-increment (11): 0.025 [schnipp ] Greetings Mario Well, myh results are a little bit confusing again, if using pre-increment, for shows up faster now. But while post-increment is the fastest :) Is there any logic why we all have different results? does it has to do something with the type of CPU, i'm using AMD Athlon. 1800+ (clocked down from 133 to 100 * 11.5) For pre-increment (10): 0.026 For post-increment (10): 0.030 While pre-increment (10): 0.029 While post-increment (11): 0.023 Tijnema ps. @ Mario: Youre C2D got owned by a AMD 1.15Ghz :) -- - | havelsoft.com - Ihr Service Partner für Open Source | | Tel: 033876-21 966 | | Notruf: 0173-277 33 60 | | http://www.havelsoft.com| | | | Inhaber: Mario Günterberg | | Mützlitzer Strasse 19 | | 14715 Märkisch Luch | - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance: While or For loop
On Fri, Mar 23, 2007 at 12:24:45AM -0500, Travis Doherty wrote: > After multiple runs I see that the for pre-increment loop is fastest. > Note that the while loop with a post-increment runs once more than with > a pre-increment. > > Everytime I run, the results are *very* different, though still fall > within similar comparitive domains. Hi... I used your script and my results are different from yours. The post-while increment is generally the fastest result on my machine (Core 2 Duo, php 5.2.1 and apache 2.2.4). I ran the script multiple times: [schnipp ] For pre-increment (10): 0.066 For post-increment (10): 0.066 While pre-increment (10): 0.028 While post-increment (11): 0.025 [schnipp ] Greetings Mario -- - | havelsoft.com - Ihr Service Partner für Open Source | | Tel: 033876-21 966 | | Notruf: 0173-277 33 60 | | http://www.havelsoft.com| | | | Inhaber: Mario Günterberg | | Mützlitzer Strasse 19 | | 14715 Märkisch Luch | - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance: While or For loop
Tijnema ! wrote: > On 3/22/07, Jon Anderson <[EMAIL PROTECTED]> wrote: > >> Your test isn't exactly fair. The for loop has no statements in it, and >> the while loop has one. Your tests show while as approx 7% faster, while >> a modified test shows an approximate 30% speed improvement: >> >> Do this: >> >> for ($i=0;$i<1000;$i++) {} >> >> v.s.: >> >> $i = 0; >> while ($i++ < 1000) {} > This has been asked many times, probably likewise for every language. Search for the same question on the C programming language for a more in depth discussion of this and to find out why one way is faster than the other... Major factor: Don't forget the difference between pre and post increment operators. $i++ and ++$i. For reference this is my PHP test script and results: {{{ [EMAIL PROTECTED] tdoherty $ cat ./forwhile.php [EMAIL PROTECTED] tdoherty $ php ./forwhile.php For pre-increment (10): 0.035 For post-increment (10): 0.060 While pre-increment (10): 0.029 While post-increment (11): 0.056 }}} After multiple runs I see that the for pre-increment loop is fastest. Note that the while loop with a post-increment runs once more than with a pre-increment. Everytime I run, the results are *very* different, though still fall within similar comparitive domains. Travis Doherty -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance: While or For loop
On 3/22/07, Jon Anderson <[EMAIL PROTECTED]> wrote: Your test isn't exactly fair. The for loop has no statements in it, and the while loop has one. Your tests show while as approx 7% faster, while a modified test shows an approximate 30% speed improvement: Do this: for ($i=0;$i<1000;$i++) {} v.s.: $i = 0; while ($i++ < 1000) {} The above while loop is 30% faster than the for. A little teaking on the for loop, it's faster still: I was comparing the way people normal use while and for. But this does confirms what i said, while is faster. for ($i=1000;$i--;) {} A little tweaking on the while, and it's faster yet: $i = 1000; while ($i--) {} The last while loop is around 60% faster on my hardware than the first for loop. jon Tijnema ! wrote: > On 3/22/07, Jake McHenry <[EMAIL PROTECTED]> wrote: >> does this help? >> >> http://www.php.lt/benchmark/phpbench.php >> >> Jake > > Well, there wasn't a test between For and While, so i did it myself, > and i'm quite confused about the result. > I let PHP count from 0 to 1 on my 1ghz AMD Athlon. > While did it in a average time of 55 seconds. > For did it in a average time of 59 seconds. > It's not a big difference, if you see what number it needs to go to, > but there is a difference. > > code used: > set_time_limit(10); > echo date("H:i:s"); > for($i = 0; $i < 1;$i++) > { > } > echo date("H:i:s"); > $x = 0; > while($x < 1) > { > $x++; > } > echo date("H:i:s"); > ?> > > So, use while loops instead of for loops ;) > > Tijnema > > ps. I also did the while loop before the for loop, doesn't matter. > >> >> >> >> > -Original Message- >> > From: Tijnema ! [mailto:[EMAIL PROTECTED] >> > Sent: Thursday, March 22, 2007 4:38 PM >> > To: PHP >> > Subject: [PHP] Performance: While or For loop >> > >> > Hi, >> > >> > Does somebody has benchmarks of what is faster, while or for loop? >> > >> > Thanks, >> > >> > Tijnema >> > >> > -- >> > PHP General Mailing List (http://www.php.net/) >> > To unsubscribe, visit: http://www.php.net/unsub.php >> > >> > -- >> > No virus found in this incoming message. >> > Checked by AVG Free Edition. >> > Version: 7.5.446 / Virus Database: 268.18.17/730 - Release >> > Date: 3/22/2007 7:44 AM >> > >> > >> >> -- >> No virus found in this outgoing message. >> Checked by AVG Free Edition. >> Version: 7.5.446 / Virus Database: 268.18.17/730 - Release Date: >> 3/22/2007 >> 7:44 AM >> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance: While or For loop
On 3/22/07, Jake McHenry <[EMAIL PROTECTED]> wrote: does this help? http://www.php.lt/benchmark/phpbench.php Jake Well, there wasn't a test between For and While, so i did it myself, and i'm quite confused about the result. I let PHP count from 0 to 1 on my 1ghz AMD Athlon. While did it in a average time of 55 seconds. For did it in a average time of 59 seconds. It's not a big difference, if you see what number it needs to go to, but there is a difference. code used: So, use while loops instead of for loops ;) Tijnema ps. I also did the while loop before the for loop, doesn't matter. > -Original Message- > From: Tijnema ! [mailto:[EMAIL PROTECTED] > Sent: Thursday, March 22, 2007 4:38 PM > To: PHP > Subject: [PHP] Performance: While or For loop > > Hi, > > Does somebody has benchmarks of what is faster, while or for loop? > > Thanks, > > Tijnema > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- > No virus found in this incoming message. > Checked by AVG Free Edition. > Version: 7.5.446 / Virus Database: 268.18.17/730 - Release > Date: 3/22/2007 7:44 AM > > -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.17/730 - Release Date: 3/22/2007 7:44 AM -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Performance: While or For loop
does this help? http://www.php.lt/benchmark/phpbench.php Jake > -Original Message- > From: Tijnema ! [mailto:[EMAIL PROTECTED] > Sent: Thursday, March 22, 2007 4:38 PM > To: PHP > Subject: [PHP] Performance: While or For loop > > Hi, > > Does somebody has benchmarks of what is faster, while or for loop? > > Thanks, > > Tijnema > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- > No virus found in this incoming message. > Checked by AVG Free Edition. > Version: 7.5.446 / Virus Database: 268.18.17/730 - Release > Date: 3/22/2007 7:44 AM > > -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.446 / Virus Database: 268.18.17/730 - Release Date: 3/22/2007 7:44 AM -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] performance criteria on DEFINE()
At 3:47 PM -0500 4/21/06, Richard Lynch wrote: On Fri, April 21, 2006 7:52 am, Jochem Maas wrote: Andy wrote: Now, one of this file can contain more than 2000 defines and we make a calculation that we will reach 8000 in 2 years. Seems to me you could extend your testing to generate 8000 constants in a file pretty easily, and just benchmark it and find out if it's acceptable. Hell, go for 16000 and 32000 tests as well, and benchmark those. The pattern should be obvious pretty quickly, and you'll know, beyond a shadow of a doubt, if you will be happy in 2 years. (On this issue.) Yes, but in two years speeds will increase and prices will decrease drastically. What is today's "Too Big" will become tomorrow's "minimum requirement". For example, the $15,000 you would have spent in 1984 for hard drive storage can be bought today for less than one cent. tedd -- http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] performance criteria on DEFINE()
On Fri, April 21, 2006 7:52 am, Jochem Maas wrote: > Andy wrote: >> Now, one of this file can contain more than 2000 defines and we make >> a calculation that we will reach 8000 in 2 years. Seems to me you could extend your testing to generate 8000 constants in a file pretty easily, and just benchmark it and find out if it's acceptable. Hell, go for 16000 and 32000 tests as well, and benchmark those. The pattern should be obvious pretty quickly, and you'll know, beyond a shadow of a doubt, if you will be happy in 2 years. (On this issue.) -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] performance criteria on DEFINE()
Thanks for the suggests. I will have to make some tests to see what will happen, especially how fast. I will post after that my opinion. Regards, Andy. - Original Message - From: "Jochem Maas" <[EMAIL PROTECTED]> To: "Andy" <[EMAIL PROTECTED]> Cc: Sent: Friday, April 21, 2006 3:52 PM Subject: Re: [PHP] performance criteria on DEFINE() Andy wrote: Hi, We have a big multilanguage project. For a while we used gettext to translate the pages, but we gave up on this because of many problems. Out solution is to create a file for each language which includes the "label" definitions. for ex: define("LABEL1", "label 1"); define("LABEL2", "label 2"); etc... Now, one of this file can contain more than 2000 defines and we make a calculation that we will reach 8000 in 2 years. I made some testing(generated many label) in including these files into the project it seemed to work fine. I don't know how php handles these defines(memory usage, CPU etc) so the question is: how much affects the performace the inclusion of a lot of defines??? creating constants is _very_ slow... if gettext is too much hassle (I can understand that ;-) it's a pity, but you have the alternative of using an array: $Lang = array( 'LABEL1' => 'hallo!', // etc ); OR install APC and write a routine that uses apc_define_constants() (not on every request obviously - well it will becomne obvious when you read up on apc and that function in particular) and apc_load_constants(). which means you can still use define() and not suffer the speed hit - although be prepared to use up a little RAM :-). note that although this means you will use the constants in your app the definition of the LABEL=>text pairs will be an array if you go the APC route. http://php.net/apc ps - the info on constants and apc is regurgitation of advice/info coming direct from Rasmus. I have never tested it, I assume he knows what he's talking about (otherwise why would he bother to write apc_load_constants()/apc_define_constants()?) pps - use single quotes for the __minimal__ decrease in processing that the skipping of string interpolation causes. Andy. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] performance criteria on DEFINE()
Andy wrote: Hi, We have a big multilanguage project. For a while we used gettext to translate the pages, but we gave up on this because of many problems. Out solution is to create a file for each language which includes the "label" definitions. for ex: define("LABEL1", "label 1"); define("LABEL2", "label 2"); etc... Now, one of this file can contain more than 2000 defines and we make a calculation that we will reach 8000 in 2 years. I made some testing(generated many label) in including these files into the project it seemed to work fine. I don't know how php handles these defines(memory usage, CPU etc) so the question is: how much affects the performace the inclusion of a lot of defines??? creating constants is _very_ slow... if gettext is too much hassle (I can understand that ;-) it's a pity, but you have the alternative of using an array: $Lang = array( 'LABEL1' => 'hallo!', // etc ); OR install APC and write a routine that uses apc_define_constants() (not on every request obviously - well it will becomne obvious when you read up on apc and that function in particular) and apc_load_constants(). which means you can still use define() and not suffer the speed hit - although be prepared to use up a little RAM :-). note that although this means you will use the constants in your app the definition of the LABEL=>text pairs will be an array if you go the APC route. http://php.net/apc ps - the info on constants and apc is regurgitation of advice/info coming direct from Rasmus. I have never tested it, I assume he knows what he's talking about (otherwise why would he bother to write apc_load_constants()/apc_define_constants()?) pps - use single quotes for the __minimal__ decrease in processing that the skipping of string interpolation causes. Andy. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance question
Hi, Any time you fetch results from a database it take up memory, you can't do much about that (you can limit the effect by using 'limit' in conjunction with paging and only getting the columns you need etc but that's about it). If you're using a standard id/parentid type approach you're stuck with recursive sql calls. If you want to take a different approach you could use a tree/node system. You end up with stuff like this: categoryid | node | categoryname | +--+--+ 1 | 0001 | xxx | 2 | 00010002 | 111 | (categoryid '2' is a subcategory of categoryid '1'). Then you can quickly find the path of a category using just sql. The downside is moving categories/parents around is a pain. I haven't tried this myself but having multiple parents you could have a separate table for just the joins with the 'node' (read: path) in it and it basically includes the path to the end category (which you join with your 'category' table to get the name etc). If you need more info let me know. Mathieu Dumoulin wrote: Miles Thompson wrote: At 12:02 PM 2/1/2006, Mathieu Dumoulin wrote: This is more a "How would you do it" than a "How can i do it" question. Didn't have time to try it, but i want to know how mysql_seek_row acts with large result sets. For example im thinking of building a node tree application that can have dual direction links to nodes attached to different places. I was wondering if i could actually have two result sets that query everything sorted by ID (Links and Nodes) then just seek the rows i need instead of dumping everything in php memory. When i mean large i mean really large, more than the standard possible 2 mbs of data allowed by most php servers. That's where the "how you'd do it" comes into play. I think i'd just query my tables, loop them but keep only the line (to do a data_seek later on) and ID in some kind of an hash table or simply an array. This would make it relatively fast without taking too much memory. This is my solution, how do you people see it without dumping everything to memory or by making recursive SQL calls (which will obviously slow everything down i'm pretty sure) Mathieu Dumoulin Programmer analyst in web solutions [EMAIL PROTECTED] I don't get it - what are you trying to do? Why? What is being visualized in the tree structure? Building trees is expensive, you're essentially duplicating the index of the database, and if you fetch the data it's in memory regardless of how you present it. The mysql_data_seek needs the row number - but by then you're on the client side, if this is to respond to a link. Maybe I just don't see it - or maybe you're confusing server side and client side. Regards - Miles Thompson I'll try to explain my post better since people dont seem to understand it. I'm trying to illustrate a node tree client side, everything is considered a node in a tree. Now these nodes can appear more than once since i allow a node to be linked to different elements (Not just one parent, i may need to refer to a node several times. Considering that a node may be there twice or more, that the number of nodes to work with may be quite high, i dont want to start copying into a php memory structure everything from the database that i might need... Nor do i want to recursively call SQL queries getting childrens of every parent. (That would cost a lot to the database server) So i was wondering what would be the best idea to actually implement this... "dilema" of keeping it fast and not using too much memory. As i understand your reply Miles, the query im doing resides in the php memory even if i don't fetch the data? If you do confirm that i WILL have to resort to recursive SQL calls. :( To finish my post i'd re-explain rapidly my vision of doing this, but obviously i may be mistaken, maybe i can't do this. Taking two sql queries, one for the nodes, one for the links between nodes, i'd first read the results sorted by id, and do a mapping table for each result. When i need to use some info, i'd map the id of this info to the mapping table and retrieve the row from the result residing in mysql memory. (Up to now, this seemed logical until Miles told me that results are kept in PHP memory.) If this is still a valid way of doing it great. What would be the impact on the sQL server. Would this be a good way? I'd like to know from other pros how they'd implement it. Mathieu Dumoulin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance question
Miles Thompson wrote: At 12:02 PM 2/1/2006, Mathieu Dumoulin wrote: This is more a "How would you do it" than a "How can i do it" question. Didn't have time to try it, but i want to know how mysql_seek_row acts with large result sets. For example im thinking of building a node tree application that can have dual direction links to nodes attached to different places. I was wondering if i could actually have two result sets that query everything sorted by ID (Links and Nodes) then just seek the rows i need instead of dumping everything in php memory. When i mean large i mean really large, more than the standard possible 2 mbs of data allowed by most php servers. That's where the "how you'd do it" comes into play. I think i'd just query my tables, loop them but keep only the line (to do a data_seek later on) and ID in some kind of an hash table or simply an array. This would make it relatively fast without taking too much memory. This is my solution, how do you people see it without dumping everything to memory or by making recursive SQL calls (which will obviously slow everything down i'm pretty sure) Mathieu Dumoulin Programmer analyst in web solutions [EMAIL PROTECTED] I don't get it - what are you trying to do? Why? What is being visualized in the tree structure? Building trees is expensive, you're essentially duplicating the index of the database, and if you fetch the data it's in memory regardless of how you present it. The mysql_data_seek needs the row number - but by then you're on the client side, if this is to respond to a link. Maybe I just don't see it - or maybe you're confusing server side and client side. Regards - Miles Thompson I'll try to explain my post better since people dont seem to understand it. I'm trying to illustrate a node tree client side, everything is considered a node in a tree. Now these nodes can appear more than once since i allow a node to be linked to different elements (Not just one parent, i may need to refer to a node several times. Considering that a node may be there twice or more, that the number of nodes to work with may be quite high, i dont want to start copying into a php memory structure everything from the database that i might need... Nor do i want to recursively call SQL queries getting childrens of every parent. (That would cost a lot to the database server) So i was wondering what would be the best idea to actually implement this... "dilema" of keeping it fast and not using too much memory. As i understand your reply Miles, the query im doing resides in the php memory even if i don't fetch the data? If you do confirm that i WILL have to resort to recursive SQL calls. :( To finish my post i'd re-explain rapidly my vision of doing this, but obviously i may be mistaken, maybe i can't do this. Taking two sql queries, one for the nodes, one for the links between nodes, i'd first read the results sorted by id, and do a mapping table for each result. When i need to use some info, i'd map the id of this info to the mapping table and retrieve the row from the result residing in mysql memory. (Up to now, this seemed logical until Miles told me that results are kept in PHP memory.) If this is still a valid way of doing it great. What would be the impact on the sQL server. Would this be a good way? I'd like to know from other pros how they'd implement it. Mathieu Dumoulin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance question
At 12:02 PM 2/1/2006, Mathieu Dumoulin wrote: This is more a "How would you do it" than a "How can i do it" question. Didn't have time to try it, but i want to know how mysql_seek_row acts with large result sets. For example im thinking of building a node tree application that can have dual direction links to nodes attached to different places. I was wondering if i could actually have two result sets that query everything sorted by ID (Links and Nodes) then just seek the rows i need instead of dumping everything in php memory. When i mean large i mean really large, more than the standard possible 2 mbs of data allowed by most php servers. That's where the "how you'd do it" comes into play. I think i'd just query my tables, loop them but keep only the line (to do a data_seek later on) and ID in some kind of an hash table or simply an array. This would make it relatively fast without taking too much memory. This is my solution, how do you people see it without dumping everything to memory or by making recursive SQL calls (which will obviously slow everything down i'm pretty sure) Mathieu Dumoulin Programmer analyst in web solutions [EMAIL PROTECTED] I don't get it - what are you trying to do? Why? What is being visualized in the tree structure? Building trees is expensive, you're essentially duplicating the index of the database, and if you fetch the data it's in memory regardless of how you present it. The mysql_data_seek needs the row number - but by then you're on the client side, if this is to respond to a link. Maybe I just don't see it - or maybe you're confusing server side and client side. Regards - Miles Thompson -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.1.375 / Virus Database: 267.14.25/247 - Release Date: 1/31/2006 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance question
This is more a "How would you do it" than a "How can i do it" question. Didn't have time to try it, but i want to know how mysql_seek_row acts with large result sets. For example im thinking of building a node tree application that can have dual direction links to nodes attached to different places. I was wondering if i could actually have two result sets that query everything sorted by ID (Links and Nodes) then just seek the rows i need instead of dumping everything in php memory. When i mean large i mean really large, more than the standard possible 2 mbs of data allowed by most php servers. That's where the "how you'd do it" comes into play. I think i'd just query my tables, loop them but keep only the line (to do a data_seek later on) and ID in some kind of an hash table or simply an array. This would make it relatively fast without taking too much memory. This is my solution, how do you people see it without dumping everything to memory or by making recursive SQL calls (which will obviously slow everything down i'm pretty sure) Mathieu Dumoulin Mathieu: I'm not sure what you're asking, but if it is to limit the amount of data presented to a user from a search, you could use LIMIT. The below uses LIMIT: http://xn--ovg.com/mysql If you want the code, just ask. tedd -- http://sperling.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance question
B trees or binary trees or hash tables or wathever sort algo or memory organisation could be just great if i'd put all my data in the page and tried or needed to sort it, but i can't do that and don't really need to. I'm actually searching for a way to load a ton of data from mysql but avoiding to transfer everything in php memory to work it out. I think the b tree would be nice if i had a ton of data to sort but i technically don't have lots of element in my node tree on the same levels, i could just sort that data in a simple php sort before showing it :) Jochem Maas wrote: I think this might interest you: http://www.bluerwhite.org/btree/ then again it may make your ears bleed (because of the Maths :-). Mathieu Dumoulin wrote: This is more a "How would you do it" than a "How can i do it" question. Didn't have time to try it, but i want to know how mysql_seek_row acts with large result sets. For example im thinking of building a node tree application that can have dual direction links to nodes attached to different places. I was wondering if i could actually have two result sets that query everything sorted by ID (Links and Nodes) then just seek the rows i need instead of dumping everything in php memory. When i mean large i mean really large, more than the standard possible 2 mbs of data allowed by most php servers. That's where the "how you'd do it" comes into play. I think i'd just query my tables, loop them but keep only the line (to do a data_seek later on) and ID in some kind of an hash table or simply an array. This would make it relatively fast without taking too much memory. This is my solution, how do you people see it without dumping everything to memory or by making recursive SQL calls (which will obviously slow everything down i'm pretty sure) Mathieu Dumoulin Programmer analyst in web solutions [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance question
I think this might interest you: http://www.bluerwhite.org/btree/ then again it may make your ears bleed (because of the Maths :-). Mathieu Dumoulin wrote: This is more a "How would you do it" than a "How can i do it" question. Didn't have time to try it, but i want to know how mysql_seek_row acts with large result sets. For example im thinking of building a node tree application that can have dual direction links to nodes attached to different places. I was wondering if i could actually have two result sets that query everything sorted by ID (Links and Nodes) then just seek the rows i need instead of dumping everything in php memory. When i mean large i mean really large, more than the standard possible 2 mbs of data allowed by most php servers. That's where the "how you'd do it" comes into play. I think i'd just query my tables, loop them but keep only the line (to do a data_seek later on) and ID in some kind of an hash table or simply an array. This would make it relatively fast without taking too much memory. This is my solution, how do you people see it without dumping everything to memory or by making recursive SQL calls (which will obviously slow everything down i'm pretty sure) Mathieu Dumoulin Programmer analyst in web solutions [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance & Comments Question
Rodolfo Andrade wrote: Hi all! I would like to know if comments in the code affects the performance. I know that comments are ignored by the interpreter, but it does increase the file size, so I was thinking about a possible performance hit for highly commented files. given the fact that you are too lazy to start a new thread when asking a question on this mailing list I have my doubts as to whether any of your files are tyhat heavily commented that you'd notice any performance hit. ;-) (for a proper answer to your question see my other reply :-) rgds, Jochem PS - please start a new thread when you post a fresh/new/unrelated question. Can anyone confirm this? Thanks! Rodolfo Andrade -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] performance suggestions
$sql = "SELECT u.*, s.*, p.* FROM URL u, session s, page p WHERE u.url_id = s.url_id AND s.section_id = p.section"; if (!$result = mysql_query($sql)) { die('Could not obtain results'); } while ($row = mysql_fetch_array($result)) { $url = $row['url_name']; .. .. and what ever else you want to do here; } "James Benson" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Thanks > > > > > Richard Lynch wrote: > > On Thu, November 3, 2005 8:29 am, James Benson wrote: > > > >>Dear group, can someone suggest the best way to do the following > >>without > >>writing some lengthy script that (possibly) could lead to performance > >>issues, > >> > >> > >>I have three DB fields in MySQL, each has a unique ID, I cannot think > >>of > >>any ways other than pulling each tables record then looping through to > >>determine which one each belongs to which group then maybe placing > >>into > >>an array, > >>the association between them all goes like this, > >> > >> > >>URL:- > >>url_id > >>url_name > >> > >>section:- > >>section_id > >>url_id > >>section_name > >> > >>page:- > >>page_id > >>section_id > >>page_name > > > > > > http://info.com/mysql+join > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] performance suggestions
Thanks Richard Lynch wrote: On Thu, November 3, 2005 8:29 am, James Benson wrote: Dear group, can someone suggest the best way to do the following without writing some lengthy script that (possibly) could lead to performance issues, I have three DB fields in MySQL, each has a unique ID, I cannot think of any ways other than pulling each tables record then looping through to determine which one each belongs to which group then maybe placing into an array, the association between them all goes like this, URL:- url_id url_name section:- section_id url_id section_name page:- page_id section_id page_name http://info.com/mysql+join -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] performance suggestions
On Thu, November 3, 2005 8:29 am, James Benson wrote: > Dear group, can someone suggest the best way to do the following > without > writing some lengthy script that (possibly) could lead to performance > issues, > > > I have three DB fields in MySQL, each has a unique ID, I cannot think > of > any ways other than pulling each tables record then looping through to > determine which one each belongs to which group then maybe placing > into > an array, > the association between them all goes like this, > > > URL:- > url_id > url_name > > section:- > section_id > url_id > section_name > > page:- > page_id > section_id > page_name http://info.com/mysql+join -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance of magic_quotes_gpc ??
Michael Gale wrote: > I am working on a ticket tracking system and using htmlentities and > htmlspecialchars on text that gets inserted into the database. > > code I have: > > --snip-- > if ((isset($_POST['tentry_body'])) AND strlen($_POST['tentry_body']) > 5) > { > $query .= " tentry_body = '" . > htmlentities(htmlspecialchars($_POST['tentry_body'])) . "'"; You've already been told all about this one :-) > } else { > $status="ERROR with entry -- appears to be empty > !\n"; > $check=1; > } > --snip-- > > In the archives people suggest that using mysql_escape_string should be > used, I then found that you could globally enable magic_quotes_gpc. > > What is the best method ? Does magic_quotes have a large performance > issue ?? > > Would it not just be safer to turn it on ?? Safer as in "more secure from hackers"? No. It's not safer either way, really, imho. The security doesn't come from adding slashes -- It comes from knowing what the data *should* look like, and validating that it *does* look like that, as strictly as possible. Safer as in "less likely I'll screw up"? This could go either way. If you understand what MagicQuotes does, how it works, and when it's appropriate to rely on it (or not) it's a convenient feature. If you don't understand how Magic Quotes works, then it's not a good thing to use. :-) -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance of magic_quotes_gpc ??
Hello, Thanks for all of the responses ... I am going to use mysql_real_escape_string. Michael. Jordi Canals wrote: Hi, a couple of comments: --snip-- htmlentities(htmlspecialchars($_POST['tentry_body'])) . "'"; --snip-- Why are you using both htmlentities and htmlspecialchars? Think that html only converts some entities while htmlentities converts all ... so, for your purposes, apliying only one could do the job. In the archives people suggest that using mysql_escape_string should be used, I then found that you could globally enable magic_quotes_gpc. magic_quotes_gpc is a generic way to getting the user data escaped, but is not the recommended way. It's better to have magic_quotes_gpc disabled and use a database specific method for scaping. If you use mysql, I would recommend mysql_real_escape_string. (mysql_escape_string is deprecated since 4.3.0) Best regards, Jordi. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance of magic_quotes_gpc ??
Hi, a couple of comments: > --snip-- > htmlentities(htmlspecialchars($_POST['tentry_body'])) . "'"; > --snip-- Why are you using both htmlentities and htmlspecialchars? Think that html only converts some entities while htmlentities converts all ... so, for your purposes, apliying only one could do the job. > > In the archives people suggest that using mysql_escape_string should be > used, I then found that you could globally enable magic_quotes_gpc. > magic_quotes_gpc is a generic way to getting the user data escaped, but is not the recommended way. It's better to have magic_quotes_gpc disabled and use a database specific method for scaping. If you use mysql, I would recommend mysql_real_escape_string. (mysql_escape_string is deprecated since 4.3.0) Best regards, Jordi. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Performance of magic_quotes_gpc ??
On Sun, 2004-12-19 at 18:31, Michael Gale wrote: > Hello, > > I am working on a ticket tracking system and using htmlentities and > htmlspecialchars on text that gets inserted into the database. > > code I have: > > --snip-- > if ((isset($_POST['tentry_body'])) AND strlen($_POST['tentry_body']) > 5) { > $query .= " tentry_body = '" . > htmlentities(htmlspecialchars($_POST['tentry_body'])) . "'"; > } else { > $status="ERROR with entry -- appears to be empty > !\n"; > $check=1; > } > --snip-- > > In the archives people suggest that using mysql_escape_string should be > used, I then found that you could globally enable magic_quotes_gpc. > > What is the best method ? Does magic_quotes have a large performance > issue ?? > > Would it not just be safer to turn it on ?? Learn to write secure code for yourself. Magic quotes are an illusion. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] performance: large includes vs small includes with lots of reads
* Thus wrote Hans H. Anderson: > I'm trying to tweak my server a bit and wonder if it is better to have a large > include file, say 20-40 kb with 15 user-defined functions, of which maybe 3 or 4 This is all a 'depends' situation. Of those 15 functions how many of them are actually executed accross all your scripts that depend on them. I tend to group function's into file where their related, and thus we get into a disussion of OOP. Functions that are used a majority of the time are included always, like authentication functions. Then their is the 'middleware' functons, that depend on what type of results you expect to have. And last are the very specific functions depending on the 'type'. > are used on any given page, or to have each function in it's own file and > include (disk access/read) them only as needed. This bottleneck is usually taken care of at the OS level, and how it caches frequently accesses files. > > Is it faster/more efficient to read one large file or several smaller ones? > It's a RS Linux server with a gig of memory. > > I'm also looking at PHP Accelerator and such. Do those store only in memory > what the script needs, or does it include all that you require or include in, as > well? A PHP Accelerator will basically cache the actual OP code that php uses to execute a script, including the files that are included within the script An acclerator is always a good option to optimize performnce. Generally they will eliminate the overhead of php having to parse each file within each request, and will probably eliminate most of the overhead if you include one big file. Of course, even with the accelerator, I would suggest designing your code to be as optimal with out it. Curt -- The above comments may offend you. flame at will. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] performance: large includes vs small includes with lots of reads
On Thu, 7 Oct 2004 11:41:10 -0500 (CDT), Hans H. Anderson <[EMAIL PROTECTED]> wrote: > I'm trying to tweak my server a bit and wonder if it is better to have a large > include file, say 20-40 kb with 15 user-defined functions, of which maybe 3 or 4 > are used on any given page, or to have each function in it's own file and > include (disk access/read) them only as needed. > > Is it faster/more efficient to read one large file or several smaller ones? > It's a RS Linux server with a gig of memory. > > I'm also looking at PHP Accelerator and such. Do those store only in memory > what the script needs, or does it include all that you require or include in, as > well? With sufficient ram, the OS will likely cache a lot of the file reads anyway, so with files that small it shouldn't make a whole lot of difference. But like I always say, the best way to know is to try it both ways and benchmark it. -- Greg Donald Zend Certified Engineer http://gdconsultants.com/ http://destiney.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php