Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Cache Speed question

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
niekas
Smarty Rookie


Joined: 30 Jan 2004
Posts: 10

PostPosted: Fri Mar 11, 2005 12:24 am    Post subject: Cache Speed question Reply with quote

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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Fri Mar 11, 2005 4:08 am    Post subject: Reply with quote

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
View user's profile Send private message
niekas
Smarty Rookie


Joined: 30 Jan 2004
Posts: 10

PostPosted: Sat Mar 12, 2005 2:37 am    Post subject: Reply with quote

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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sat Mar 12, 2005 3:09 am    Post subject: Reply with quote

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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sat Mar 12, 2005 3:20 am    Post subject: Reply with quote

oops, just saw your edit Smile

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
View user's profile Send private message
niekas
Smarty Rookie


Joined: 30 Jan 2004
Posts: 10

PostPosted: Sat Mar 12, 2005 3:30 am    Post subject: Reply with quote

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". Laughing
Back to top
View user's profile Send private message
niekas
Smarty Rookie


Joined: 30 Jan 2004
Posts: 10

PostPosted: Sat Mar 12, 2005 4:19 am    Post subject: Reply with quote

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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sat Mar 12, 2005 4:20 am    Post subject: Reply with quote

oops. I think I had that backwards -- it should be:

- output buffering when fetch() is used
- will not use output buffering on display()

There was a long-ish thread concerning output buffering on the smarty-dev mailing list a couple of years ago. http://marc.theaimsgroup.com/?l=smarty-dev&m=105223513623346&w=2

It yielded these links which could be of interest:
http://talks.php.net/show/hpp/11
http://talks.php.net/show/nytips/27
http://httpd.apache.org/docs/mod/core.html#sendbuffersize

edit: ahh, missed your post again Smile glad you solved it! These links were just a stroll down memory lane anyways.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP