View previous topic :: View next topic |
Author |
Message |
rippergun Smarty n00b
Joined: 06 May 2011 Posts: 2
|
Posted: Thu Jun 23, 2011 7:53 am Post subject: |
|
|
exactly what we looking for.
We were trying to have opcode compilation with APC and store it to a distributed fast cache repository (memcached).
In fact you can avoid the eval for the template. The Include function is an eval (sort of).
So we try to add a native function to PHP (ie include_cache) which get the item from memcache and eval it like an include().
FYI for the moment we step back to APC.
The compiled templates are on SSD drive. The items assigned to smarty are stored in memcached.
The best of both world for the moment.
Quote: | The assumption that reading caches from APC is faster than eval() is not necessarily true. If you have many cache hits (say per generated cache file at least 20 hits [guessed, needs measuring!]), you may outweigh the overhead of pulling stuff from memcache to disk and shoving it into apc before including the file. |
We have 20k read per second on our memcached cluster. Eval was just pulling down performances (+0.2 second per page).
APC, even on multiple servers is faster for us (on SSD drive) |
|
Back to top |
|
therealnine Smarty n00b
Joined: 11 Aug 2011 Posts: 3
|
Posted: Thu Aug 11, 2011 11:43 pm Post subject: Memcached conclusions |
|
|
I have been using memcached with smarty 2 and just found today that its not working with Smarty 3.0.8. Looking through how to make this work the recommendation seems to be 3.1, but 3.1 is 'unstable' right?
This question surely goes beyond the scope of this thread, but in consideration of memcached, is 3.1 'safe' to deploy? In terms of your versioning RC is supposed to be pretty safe right? But in the changelog you have it going back to DEV? Either way it seems like 3.1 might be safer than hacking 3.0.8 plugins together anyway. Is there an outstanding issue list that would be more concise than the forum?
Also, I noticed in the old plugin for 3.0.8 that the memcache library is used (rather than memcached). Is that still the case in 3.1?
Thanks. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Fri Aug 12, 2011 12:29 am Post subject: |
|
|
The SVN branch Smarty_3_1_DEV contains some bugfixes and improvements made after 3.1 RC1. There are currently no open issues and plans are that this will become the offical release in about 3 weeks.
Jn the demo folder is an example of the memcache cache resource. |
|
Back to top |
|
therealnine Smarty n00b
Joined: 11 Aug 2011 Posts: 3
|
Posted: Mon Aug 15, 2011 7:05 pm Post subject: memcache extension |
|
|
It seems there is no local storage of the response from the memcached server. Therefore, if isCached is true, the cache file will be requested from the server again when fetch is called. Smarty 2 handled this issue.
More important than the performance, if the file expires or is evicted between the 2 calls- that would be a problem.
Additionally, the #IVK#CID files are also requested twice. So where there used to be one call there are now 4. Can someone give me a case when this IVK file is used? I would think that I could turn this off. |
|
Back to top |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
Posted: Mon Aug 15, 2011 7:38 pm Post subject: Re: memcache extension |
|
|
therealnine wrote: | It seems there is no local storage of the response from the memcached server. Therefore, if isCached is true, the cache file will be requested from the server again when fetch is called. Smarty 2 handled this issue. |
For some reason the last rewrite of the CacheResource API the couple of lines for the instance caching got lost. I'll look into this tomorrow.
therealnine wrote: | Can someone give me a case when this IVK file is used? I would think that I could turn this off. |
IVK stands for InValidationKey. I tried to explain the basc idea in the comments of http://code.google.com/p/smarty-php/source/browse/branches/Smarty_3_1_DEV/distribution/libs/sysplugins/smarty_cacheresource_keyvaluestore.php - does that help you? _________________ Twitter |
|
Back to top |
|
therealnine Smarty n00b
Joined: 11 Aug 2011 Posts: 3
|
Posted: Mon Aug 15, 2011 7:55 pm Post subject: |
|
|
I get the basic idea, but if I never use invalidate() can I turn it off? or is invalidate() called internally?
I was working under the idea that if I needed to toss the cache I would just restart memcached. Having 2x the calls seems like unnecessary overhead (at least for me).
I have 2 other question around this:
1. Is there a good reason for using memcache rather than memcached? I was using memcached with Smarty 2 and don't love this feeling of downgrading.
2. Why does Smarty_CacheResource_Memcache->read() take an array? It doesn't seem to ever pass more than a single string. Is this used, or for some future idea?
Thanks for helping me out. |
|
Back to top |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
Posted: Mon Aug 15, 2011 8:09 pm Post subject: |
|
|
therealnine wrote: | I get the basic idea, but if I never use invalidate() can I turn it off? or is invalidate() called internally? |
invalidate() is called internally. And no, you can't turn it off. you need this for being able to clear caches by template, cache groups, …
therealnine wrote: | I was working under the idea that if I needed to toss the cache I would just restart memcached. Having 2x the calls seems like unnecessary overhead (at least for me). |
If you never call clearCache() then by god, disable the IVK stuff.
Lines 127, 151, 203 - 207
therealnine wrote: | I have 2 other question around this:
1. Is there a good reason for using memcache rather than memcached? I was using memcached with Smarty 2 and don't love this feeling of downgrading. |
memcache and mysql are just examples. Use whatever PECL, whatever storage facility you like.
(Last time I used the memcached PECL, It froze the shit out of my app. dead-node failover did not work properly. but that was 2 years ago. haven't switched back since.)
therealnine wrote: | 2. Why does Smarty_CacheResource_Memcache->read() take an array? It doesn't seem to ever pass more than a single string. Is this used, or for some future idea? |
it'll be called once for the actual content (single key) and once for the IVKs (multiple keys). The array makes sense, especially if the storage adapter (like memcache in this example) accepts arrays… _________________ Twitter |
|
Back to top |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
|
Back to top |
|
aladin Smarty n00b
Joined: 11 Feb 2013 Posts: 4
|
Posted: Mon Feb 11, 2013 8:20 am Post subject: not working |
|
|
Hello, I can't get memcache caching to work.
What I did:
I use extended smarty class, my constructor looks like this:
Code: | parent::__construct();
$this -> setCompileDir(SMARTY_CACHE_DIR);
Smarty_CacheResource_Memcache::$memcache = $memcache;
$this->registerCacheResource('memcache', new Smarty_CacheResource_Memcache());
$this->caching_type = 'memcache'; |
Have I missed something? |
|
Back to top |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
Posted: Mon Feb 11, 2013 9:09 am Post subject: Re: not working |
|
|
what is this supposed to do?
Code: | Smarty_CacheResource_Memcache::$memcache = $memcache; |
If you want to pass in an existing memcache instance, extend the memcache class:
Code: | class MyMemcacheThingie extends Smarty_CacheResource_Memcache {
public __construct($instance) {
$this->memcache = $instance;
}
}
$smarty->registerCacheResource('memcache', new MyMemcacheThingie($myMemcacheInstance)); |
_________________ Twitter |
|
Back to top |
|
aladin Smarty n00b
Joined: 11 Feb 2013 Posts: 4
|
Posted: Mon Feb 11, 2013 9:25 am Post subject: Re: not working |
|
|
rodneyrehm wrote: |
Code: | class MyMemcacheThingie extends Smarty_CacheResource_Memcache {
public __construct($instance) {
$this->memcache = $instance;
}
}
$smarty->registerCacheResource('memcache', new MyMemcacheThingie($myMemcacheInstance)); |
|
I just did it like that:
Code: |
$smarty->registerCacheResource('memcache', new Smarty_CacheResource_Memcache ($myMemcacheInstance));
|
But that doesn't address my problem |
|
Back to top |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
Posted: Mon Feb 11, 2013 9:27 am Post subject: Re: not working |
|
|
aladin wrote: | I just did it like that:
Code: |
$smarty->registerCacheResource('memcache', new Smarty_CacheResource_Memcache ($myMemcacheInstance));
|
But that doesn't address my problem |
well, the constructor of Smarty_CacheResource_Memcache looks as follows:
Code: | public function __construct()
{
$this->memcache = new Memcache();
$this->memcache->addServer( '127.0.0.1', 11211 );
} |
so passing anything to it won't do squat… that's why I said you need to subclass it and do it yourself. _________________ Twitter |
|
Back to top |
|
aladin Smarty n00b
Joined: 11 Feb 2013 Posts: 4
|
Posted: Mon Feb 11, 2013 10:55 am Post subject: |
|
|
I made my Smarty_CacheResource_Memcache class a little different from one in the exmaple, also I changed constructor, to support memcache object as parameter, If I supply the object to registerCacheResource initiated, so there is no problem with that? |
|
Back to top |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
Posted: Mon Feb 11, 2013 10:59 am Post subject: |
|
|
aladin wrote: | I made my Smarty_CacheResource_Memcache class a little different from one in the exmaple, also I changed constructor, to support memcache object as parameter, If I supply the object to registerCacheResource initiated, so there is no problem with that? |
so… you made changes to internal code. You did not mention that before. You expected us to magically know about that. *never* do that again.
Now that we've sorted out that Smarty_CacheResource_Memcache is indeed using your memcache instance, you might want to clarify what the "it doesn't work" really looks like. _________________ Twitter |
|
Back to top |
|
aladin Smarty n00b
Joined: 11 Feb 2013 Posts: 4
|
Posted: Mon Feb 11, 2013 11:14 am Post subject: |
|
|
Sorry for misunderstanding, I did not think that Smarty_CacheResource_Memcache is part of internal code, since I had to copy paste it from the page .
Anyway, I forgot to enable caching, so that is why it was not working, now memcache works. |
|
Back to top |
|
|