Hi Tomm,
I have installed the jquery cycle plugin on leefish, and it looks pretty slick, but I am a bit concerned about site performance.
The images are called from the database and the slider hides the images on the page (except the active image) and runs a simple slideshow. My current plugin is set to run on portal start, but I was wondering two things:
1) Is this jQuery Cycle plugin likely to be affecting the site performance in anyway? Like making it slower?
2) If the effect is minimal, how would I go about making it so that my plugin calls the data from the database and then caches it so it does not requery the db on every page load?
My host (who is actually a friend of mine) said I should use memcache (he has it installed on his server - thats the server leefish is on) but I am really struggling to get it to work. Do you have any tips?
Link to the page if you are interested:
http://www.leefish.nl/mybb/portal.php
Its the "fresh fish" and "Favourite items" in the left panel.
|
|
|
Ok, my reason for strugglle is that the memcache was installed but not switched on. Two queries nuked from portal page.
|
|
|
You're right - that does pretty slick!
To be honest, it's not going to be doing much damage if it's just using basic SELECT statements to retrieve the images. It would start affecting performance if your site was getting 1,000's of queries every second - to the point where every query needs to be optimized.
Memcache is very useful, but again, it's something you should look at later when performance starts decreasing. At the minute, your site takes a page load time of 0.1 seconds. Considering Invision, phpBB and MyBB 2 all run at around 0.5 seconds, you seem to be OK.
If you're really interested in optimizing it, I would put it into the datacache table first before trying Memcache. This table is automatically retrieved first before anything else on every MyBB page, so if you can store the data in there then there isn't anymore queries to handle as then you can just do $cache->read("title_of_cache) to retrieve the info. I know you're super awesome at making plugins now, so I have faith you'll be able to do it. You know where I am if you want to make it 2-1 in our coding FAQ scores.
In contrast, Xekko runs at 0.04 seconds. It doesn't use Memcache.
|
|
|
0.04 seconds.....
Is that because it is tableless? Or not many plugins?
I will have a look at the datacache table suggestion - it could make this a nice plugin for MYBB users on slower servers, and as I found out, memcache is not always on.
|
|
|
Memcache is quite rare on shared servers, although most companies will switch it on if it's requested. The main role of the datacache table is to retrieve information most commonly used by MyBB otherwise we'd be constantly asking the database for stuff like forums, permissions and even trivial things like smilies. It can be quite useful - the class_datacache.php is where the action's at - just remember to use it wisely. With great coding power comes great responsibility.
Technically the speed is a combination of lots of things - I believe being tableless does help (difference is probably minimal, but takes less time to retrieve smaller templates from the database) but Xekko runs over 15 plugins last time I checked and it queries the database for things like new posts/threads to appear in the header. It's just what you use I guess, but it's on a good server too.
|
|
|
Hi Tomm,
I haven't posted for a while as I saw you were super busy and I have been trying with this but I am a bit lost. I have a query which currently uses memcache to store the data for a set period of time and then to rerun the query. This gives the "freshness" to my front page without hitting the db all the time. The thing is, my host keeps turning memcache off...... so I think I need to swap over to the mybb option you outlined
Here is my current query with the memcache bit >>
PHP Code:
if($mybb->settings['whatshot_ed'] != 0) {
// Check memcache and see if we already have generated the attachment gallery $whatshot_gallery = $memcache->get("mybb_whatshot_whatshot_gallery"); // If not (ie if the return is boolean false), OR we pass in a "regen" parameter, then generate the contents again via SQL if ($whatshot_gallery === false || isset($_GET['regen'])) { $whatshot_num = intval($mybb->settings['whatshot_num']); if(is_array(explode(',', $mybb->settings['whatshot_fid']))) { foreach(explode(',', $mybb->settings['whatshot_fid']) as $whatshot_tid) { $whatshot_tid_array[] = intval($whatshot_tid); } } $query = $db->query(" SELECT a.*, t.* FROM ".TABLE_PREFIX."aggrdownloads a LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=a.itemid) WHERE t.visible=1 AND a.dateline= $mydate AND t.closed NOT LIKE 'moved|%' AND t.fid IN ('".implode("','", $whatshot_tid_array)."') GROUP BY a.itemid DESC ORDER BY a.counter DESC LIMIT $whatshot_num "); while($whatshot = $db->fetch_array($query)) { $whatshot_title = htmlspecialchars_uni($whatshot['subject']); $whatshot_postlink = get_thread_link(intval($whatshot['tid'])); eval("\$whatshot_gallery_gallery .= \"".$templates->get("whatshot_gallery_gallery")."\";"); } eval("\$whatshot_gallery = \"".$templates->get("whatshot_gallery")."\";"); // 3600 seconds = 1 hour // 1800 seconds = 30 minutes // 900 seconds = 15 minutes // 300 seconds = 5 minutes // Save the generated template into memcache for so many seconds. $memcache->set("mybb_whatshot_whatshot_gallery", $whatshot_gallery, 0, 3600);
} }
I am a bit lost on how I can use the mybb datacache class and still get this timed update. if you have time to help it would be appreciated.
|
|
|
PHP Code:
if($mybb->settings['whatshot_ed'] != 0) { // Attempt to read the cache with the 'whatshot_gallery' title $whatshot_gallery = $cache->read('whatshot_gallery');
// No cache found or we need to update it (time expired) if($whatshot_gallery == false || is_array($whatshot_gallery) && $whatshot_gallery['update'] <= (TIME_NOW - 3600)) { $whatshot_num = intval($mybb->settings['whatshot_num']);
if(is_array(explode(',', $mybb->settings['whatshot_fid']))) { $tid_array = array(); $whatshot_gallery_gallery = '';
foreach(explode(',', $mybb->settings['whatshot_fid']) as $tid) { $tid_array[] = intval($tid); }
$query = $db->query(" SELECT a.*, t.* FROM ".TABLE_PREFIX."aggrdownloads a LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid = a.itemid) WHERE t.visible = 1 AND a.dateline = '{$mydate}' AND t.closed NOT LIKE 'moved|%' AND t.fid IN ('".implode("','", $tid_array)."') GROUP BY a.itemid DESC ORDER BY a.counter DESC LIMIT {$whatshot_num} ");
while($whatshot = $db->fetch_array($query)) { $whatshot_postlink = get_thread_link($whatshot['tid']); $whatshot_title = htmlspecialchars_uni($whatshot['subject']);
eval("\$whatshot_gallery_gallery .= \"".$templates->get("whatshot_gallery_gallery")."\";"); }
eval("\$whatshot_gallery = \"".$templates->get("whatshot_gallery")."\";");
// Save data into a cache $cache->update('whatshot_gallery', array('update' => TIME_NOW, 'template' => $whatshot_gallery)); } } }
Fundamental functions are read and update - both are quite simple really. Just make sure you create a row in the datacache table first (title: whatshot_gallery | cache: a:0:{}) before doing anything! Update just serializes the array and inserts it into the cache handler.
|
|
|
Thank you Tomm - I shall try that
|
|
|
Hallo again
I think I am like you Tomm - too many projects/interests not enough time. Anyway, my host turned memcache OFF (again!) and I decided to have a shot at the above code.
It does not work - well, it DOES - but not quite in the way I expected. You see, I am not that good a coder, and I tend to reuse what I know.... so on leefish the galleries are made so that there is an outer template - in this case the whatshot_gallery - and then there is an inner template - whatshot_gallery_gallery - which holds the data.
So I implemented the above code - and made the cache - and it did work - it did a great job of caching the outer template but not the inner. So I had an empty sidebox on my portal saying "whats hot"...
I have tried fiddling about with the code, but so far no luck. The most I have been able to achieve is the total disappearance of the sidebox. I know I have a cache - I can see it in the cache list - but there is no data in it if I refer to the whatshot_gallery_gallery (inner). If I refer to the whatshot_gallery (outer) then the cache shows a nice cache of that template.
Further help/advice appreciated. If it is a matter of changing the way I have built my gallery templates I am open to that suggestion (with a tip on how please.)
Thank you
|
|
|
|