View previous topic :: View next topic |
Author |
Message |
nikotto Smarty Rookie
Joined: 12 Jan 2004 Posts: 26
|
Posted: Tue Jan 27, 2004 7:07 pm Post subject: cache on pages with much traffic |
|
|
hey
i have a question.
i always thought like that:
i use smarty caching, so i can use a complex database-structure that requires several queries and a relative long script-run. with the wonderfull cache all no problem.
but:
from time to time content changes - so i have to delete the cache (users would be confused if they add something and it isnt immideately there)
and now the question:
what happens if for one CacheID the cache doesnt exist and two or more request exactly this CacheID at the same time (or at least withing the time it takes to create the page)
is smarty that intelligent that it won't create the page several times?
...and another question:
i set the lifetime to infinite and i delete the cache whenever the content changes. is this a good solution?
many thx for any answer
mfg |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Tue Jan 27, 2004 9:42 pm Post subject: Re: cache on pages with much traffic |
|
|
nikotto wrote: | what happens if for one CacheID the cache doesnt exist and two or more request exactly this CacheID at the same time (or at least withing the time it takes to create the page)
is smarty that intelligent that it won't create the page several times?
|
No, it isn't.
Quote: | i set the lifetime to infinite and i delete the cache whenever the content changes. is this a good solution? |
I think it is a good solution. Of course it's best if you delete only the cache-groups that are affected by the change and not the whole cache. |
|
Back to top |
|
nikotto Smarty Rookie
Joined: 12 Jan 2004 Posts: 26
|
Posted: Wed Jan 28, 2004 6:15 pm Post subject: |
|
|
thx for your fast reply.
what should i do about that now?
when there are about 150+ visitors on the page we have speed problems!
of course i have to optimize my code too, but i would like to think about everything that could speed up things...
mfg |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed Jan 28, 2004 6:31 pm Post subject: |
|
|
how long does it take to generate a page (in approx. average)? are you sure you have so many concurrent writes of the same cache-file that preventing this would extinct your performance-problems?
if so: maybe you can write your own cache_handler_func to handle reads and writes (and deletes) of cached files. you could implement a locking that fits you needs better or you could use a transactional database (maybe with some row-locking) to eleminate unnecessary writes.
this *could* help, but it's a little effort and you have to implement it and only know afterwards if that is faster than you current solution (the built-in cache-file-handling). so if i was you: before i put any effort in it i'd make sure that this is really the bottle-neck and the point that needs optimization. |
|
Back to top |
|
nikotto Smarty Rookie
Joined: 12 Jan 2004 Posts: 26
|
Posted: Thu Jan 29, 2004 7:19 pm Post subject: |
|
|
i measure 13sec execution-time from the start of the script to the end.
It has to serve 94.56 KB and get the all from the database
within this time there are sure several requests...
i suppose this is ways to high - but i always thought about it like "i use smarty cache, no problem"
does using a database for a cache speed up things? aren't files much faster just for writing or reading one file? of course the row-locking (however this would be done) would be helpful...
mfg |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu Jan 29, 2004 7:44 pm Post subject: |
|
|
one advantage of file-based caching is, if is_cached() returns true you don't even have to load your db-abstraction-class and you don't have to connect the database at all.
of course it depends on the filesystem and on the database which one is faster.
13 seconds is a lot. do you have a finite number of cache_ids? if so you could try to write a cache_handler_func that doesn't delete expired templates but marks them as expired. if the cache-handler hits an expired page it looks if somebody is already creating a new version. if so it returns the expired page, if not it creates the page. so only one visitor has to wait for the page and the other get older content for a limited time (better than nothing). |
|
Back to top |
|
nikotto Smarty Rookie
Joined: 12 Jan 2004 Posts: 26
|
Posted: Sat Jan 31, 2004 7:16 am Post subject: |
|
|
thats a great idea!
but, as i mentioned allready - i do have a infinite lifetime and delete the cache whenever content gets changed. so i would have to mark them as deleted when i call the clear_cache-function.
do you have an idea how to mark them? in a database? (db-connection is set anyway) or in an additional file?
like create for cachefile.tpl a cachefile.createmenew-file?
and then when someone hits that page and the createmenew-file exists he first deletes this file and then creates the new cachefile.tpl and all other requests don't see the createmenew anymore so they just use the cachefile.tpl...
or yould it be more efficient to save this somewhere else?
and about cache_ids, i do have infinite-cache_ids - why is this a problem?
big thx for your help...
mfg |
|
Back to top |
|
|