Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Smarty 3 and Memcache
Goto page Previous  1, 2
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
rippergun
Smarty n00b


Joined: 06 May 2011
Posts: 2

PostPosted: Thu Jun 23, 2011 7:53 am    Post subject: Reply with quote

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) Smile
Back to top
View user's profile Send private message
therealnine
Smarty n00b


Joined: 11 Aug 2011
Posts: 3

PostPosted: Thu Aug 11, 2011 11:43 pm    Post subject: Memcached conclusions Reply with quote

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


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Fri Aug 12, 2011 12:29 am    Post subject: Reply with quote

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


Joined: 11 Aug 2011
Posts: 3

PostPosted: Mon Aug 15, 2011 7:05 pm    Post subject: memcache extension Reply with quote

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


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Mon Aug 15, 2011 7:38 pm    Post subject: Re: memcache extension Reply with quote

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
View user's profile Send private message Visit poster's website
therealnine
Smarty n00b


Joined: 11 Aug 2011
Posts: 3

PostPosted: Mon Aug 15, 2011 7:55 pm    Post subject: Reply with quote

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


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Mon Aug 15, 2011 8:09 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Mon Aug 15, 2011 9:04 pm    Post subject: Reply with quote

the problem is now fixed: http://code.google.com/p/smarty-php/source/detail?r=4233
_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
aladin
Smarty n00b


Joined: 11 Feb 2013
Posts: 4

PostPosted: Mon Feb 11, 2013 8:20 am    Post subject: not working Reply with quote

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


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Mon Feb 11, 2013 9:09 am    Post subject: Re: not working Reply with quote

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
View user's profile Send private message Visit poster's website
aladin
Smarty n00b


Joined: 11 Feb 2013
Posts: 4

PostPosted: Mon Feb 11, 2013 9:25 am    Post subject: Re: not working Reply with quote

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 Smile
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Mon Feb 11, 2013 9:27 am    Post subject: Re: not working Reply with quote

aladin wrote:
I just did it like that:
Code:

$smarty->registerCacheResource('memcache', new Smarty_CacheResource_Memcache ($myMemcacheInstance));


But that doesn't address my problem Smile


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
View user's profile Send private message Visit poster's website
aladin
Smarty n00b


Joined: 11 Feb 2013
Posts: 4

PostPosted: Mon Feb 11, 2013 10:55 am    Post subject: Reply with quote

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


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Mon Feb 11, 2013 10:59 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
aladin
Smarty n00b


Joined: 11 Feb 2013
Posts: 4

PostPosted: Mon Feb 11, 2013 11:14 am    Post subject: Reply with quote

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 Smile.

Anyway, I forgot to enable caching, so that is why it was not working, now memcache works.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
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