View previous topic :: View next topic |
Author |
Message |
niekas Smarty Rookie
Joined: 30 Jan 2004 Posts: 10
|
Posted: Fri Mar 11, 2005 12:24 am Post subject: Cache Speed question |
|
|
My smarty page loads rather slow - compiled/cached; 1 dynamic poll
on debug console it indicates that it loads very fast:
Quote: | included templates & config files (load time in seconds):
index_new.tpl (0.00252) (total)
poll.tpl (0.00168) |
But in reality something it takes much longer - 0.600 - 1.000s
What could be a problem? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Fri Mar 11, 2005 4:08 am Post subject: |
|
|
Loading of the templates is but part of the story. Your page request involves more than that, for example, the time it takes to load the Smarty library and the other classes you may be using. If you are not using is_cached() then you are doing (possibly timely) application work that can be avoided when retrieving from cache.
I showed a little technique you can use to set timers throughout your code and templates. You might want to consider something similar to help you pinpoint the exact issue or perhaps use a profiling tool such as the one in XDebug.
greetings |
|
Back to top |
|
niekas Smarty Rookie
Joined: 30 Jan 2004 Posts: 10
|
Posted: Sat Mar 12, 2005 2:37 am Post subject: |
|
|
Thanks boots for your reply. Yes i'm using is_cached. I tried using timer with fetch-> method from that thread you provided. My cached html page is ~10kb so its not conclusive.
Loading this cached html page by itself takes on average 0.0002 s
Loading compiled template with smarty and cache takes on average 0.2 s
Loading compiled template without caching takes on average 0.6 s
Adding gzip compression improves it a lot - on average it loads 0.06 s
How come gzip improves the load time so much? Its a small page and it seems should add extra time to compress the output.
I tried to load page by using fetch to silently capture template into $output, without echoing content - it takes ~0.07s. After adding echo $output; load time jumps to ~0.2+s
Is there something wrong with my hoster that it takes 0.2s to echo 10kb of html?
I tried a little test - plain php file echoing one large string with timer . Up to ~13KB it loads very fast 0.0002 s (just like html file), but once string is larger than 15kb it slows down considerably 0.1-0.2s.
To echo 100kb string it takes ~0.5s. Is this normal? I'm pretty sure its not smarty problem, but some bottleneck, weird configuration on my webhosting, or something else that i'm missing? <scratching head>
[add]
I also found this on php.net/echo
Due to the way TCP/IP packets are buffered, using echo to send large strings to the client may cause a severe performance hit. Sometimes it can add as much as an entire second to the processing time of the script. This even happens when output buffering is used.
If you need to echo a large string, break it into smaller chunks first and then echo each chunk.
Does smarty spit out cached html as one piece or it splits it in smaller chunks? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sat Mar 12, 2005 3:09 am Post subject: |
|
|
hmm. Check out http://php.net/outcontrol and have a look at the first user-note on that page.
There may be more help available on the php-general mailing list as this is a bigger scoped issue than Smarty itself.
Greetings |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sat Mar 12, 2005 3:20 am Post subject: |
|
|
oops, just saw your edit
Quote: | Does smarty spit out cached html as one piece or it splits it in smaller chunks? |
If I'm not mistaken, it depends but I don't think Smarty ever tries to chunk the output. I believe cache portions are essentially echo'd. Compiled templates are PHP included just like any script. I believe Smarty will automatically use output buffering when display() is used, but wil not use output buffering on fetch(). |
|
Back to top |
|
niekas Smarty Rookie
Joined: 30 Jan 2004 Posts: 10
|
Posted: Sat Mar 12, 2005 3:30 am Post subject: |
|
|
Thanks boots for quick answer:
I'm not alone with this:
http://wonko.com/content.php?id=299
Although his solution on splitting string into chunks doesn't seem to help that much (i didn't try readfile() yet). Anyway its not smarty problem. Its amazing that a lot more people do not experience/notice this - everybody uses "echo". |
|
Back to top |
|
niekas Smarty Rookie
Joined: 30 Jan 2004 Posts: 10
|
Posted: Sat Mar 12, 2005 4:19 am Post subject: |
|
|
Thanks boots - adding this line to htaccess:
Code: | PHP_FLAG output_buffering on |
did the trick.
echoing 100Kb string (no splitting) takes 0.0004 s instead of 0.6s
that is more than 1000x faster.
thanks again. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
|
Back to top |
|
|