Register Members List Search Today's Posts Mark Forums Read

Reply
 
Article Options
  #16  
Old 10 Jul 2011, 23:28
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
Originally Posted by Disasterpiece View Post
... there is an extra setting area for this in the config.php where you can switch the default datastore handler to memcached...
Well, if a mod isn't written to use the datastore then enabling memcached for the datastore won't change anything. And if it is written to use the datastore then it probably doesn't need to be changed. But I suppose you could argue that if you are going to change a mod then it makes more sense to change it to use the datastore.

Last edited by kh99; 10 Jul 2011 at 23:42.
Reply With Quote
  #17  
Old 24 Jul 2011, 19:49
MoMan MoMan is offline
 
Join Date: Oct 2005
One problem with the memcached is that it can't store anything over 1Mb, and it's slow at reading out large chunks of data. Not surprisingly, I've thus found the database datastore to be better (faster) than the memcached datastore as it contains quite a bit of data, especially if you're running vbseo. Therefore, caching the smaller stuff in memcache pays off, as does the extra effort taken to modify inefficient mods.

What I've done is I added a global $vbulletin->memcache state via global.php. As such, storing data is very easy as I don't need to create an instance of the memcache object every time I want to use it.

On my board, using memcached to cache the forumhome "who's online" block cuts index.php's generation time from 0.15s to about 0.07s. This is because fully caching the listings saves hundreds of evaluations forumhome_loggedinuser. I think that in total, I cache 15 or so mods, and it really pays off. This includes my very own vb3 sidebar mod, which would otherwise take over a second to fetch the most recent data from the databse.

One piece of advice I can give everyone is that you need to understand what memcache is good at prior to using it for caching. You don't want to write mods that rely on memcache to work, or cache things for more than an hour- as then, you're probably better off just using the database to begin with.

---------------------

Regarding showgroups.php, let me start by saying that nobody ever visits that page. But if you still want to cache it, there are two approaches: you can save the result of the query and fetch it from the cache, or you can cache the entire page. Note that unless you have hundreds of users on your showgroups page, you probably won't gain much from caching.

My forum has some 1,100 users listed, and takes between 1.5 and 2 seconds to generate if you don't cache. With the cache, it's spat out in under 0.1s, of which 0.07s can be attributed to memcache (again, on my server- this varies from site to site).

Here's the rough idea, with the actual vb code cut out as required by the license:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

I'm pretty sure I modified my SHOWGROUPS template in order to be able to do full HTML caching, but I forget.

---------------------

Another idea for those who want to be even more efficient is to get both the time and data in a single $memcache->get call, which will save you 1 get per pageload at the expense of fetching unecessary data if it turns out the cache need to be updated. You can also try playing around with $memcache->add, although I've found the behavior of this to be somewhat unpredictable.
__________________
Adam

Admin of PentaxForums.com - Big-Board
Reply With Quote
  #18  
Old 03 Aug 2011, 00:38
MoMan MoMan is offline
 
Join Date: Oct 2005
FWIW I have come up with a new way to cache that doesn't have to check for a timestamp every time. This works especially nicely if you write your own memcached wrapper class.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

__________________
Adam

Admin of PentaxForums.com - Big-Board
Reply With Quote
  #19  
Old 09 Aug 2011, 10:54
MoMan MoMan is offline
 
Join Date: Oct 2005
I have now updated the article in the first post with my new approach, which only makes 1 memcache call per regular pageload, and 2 when the cache needs updating. The old approach used 2 calls per pageload and 3 when the cache needed updating
__________________
Adam

Admin of PentaxForums.com - Big-Board
Reply With Quote
  #20  
Old 31 Oct 2011, 07:13
MoMan MoMan is offline
 
Join Date: Oct 2005
Here's my latest update to the caching function to make things even easier. Simply specify a cache key and a callback function - if the data exists in the cache, it will be fetched. Otherwise, the callback will be called and the returned data will be stored in cache and returned to the user.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Usage:

$cacheobj->fetch('data_key', 'some_function');

See php's documentation on call_user_func for more info on what $callback can contain.
__________________
Adam

Admin of PentaxForums.com - Big-Board
Reply With Quote
  #21  
Old 31 Jan 2015, 20:52
punchbowl punchbowl is offline
 
Join Date: Nov 2006
Found this through googling. Fantastic insight and great to see a top quality, modern looking forum, still on vb3.8. Great work op and thanks for sharing.

Last edited by punchbowl; 01 Feb 2015 at 12:19.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Article Options

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


New To Site? Need Help?

All times are GMT. The time now is 01:07.

Layout Options | Width: Wide Color: