Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: Guy Verschuere - tammikuu 20, 2014, 01:58:50 IP

Otsikko: Optimal use of cache
Kirjoitti: Guy Verschuere - tammikuu 20, 2014, 01:58:50 IP
Hi all,

I've been busy optimizing my server to deliver the fastest forum possible.
After optimizing Apache and MySQL I did the 2 wordpress sites and now I'm busy optimizing the 2 SMF forum's.

I've been changing the TTL times for several caches and already added several queries to the cache.
With all these optimizations I managed to get a 'all unread' page with 5 queries and the index down to 3.

On every page load there are still 2 queries I want cached:
a) SELECT variable, value FROM smf_settings (in Sources/Load.php)
b) UPDATE smf_log_activity SET hits = hits + 1 WHERE date = '2014-01-20'  (in Sources/Subs.php)

a) Why doesn't this query use the cache? Debug shows "get modSettings: 0,00007s - 0 bytes, put modSettings: 0,00316s - 53065 bytes"
Why is the cache always 'null' then?

b) Why update the table on each pageview? Why not combine that in steps of 10?

Who can help me with these two?

Thanks!
Otsikko: Re: Optimal use of cache
Kirjoitti: emanuele - tammikuu 20, 2014, 04:15:36 IP
Lainaus käyttäjältä: Guy Verschuere - tammikuu 20, 2014, 01:58:50 IP
a) SELECT variable, value FROM smf_settings (in Sources/Load.php)

a) Why doesn't this query use the cache? Debug shows "get modSettings: 0,00007s - 0 bytes, put modSettings: 0,00316s - 53065 bytes"
Why is the cache always 'null' then?
For that you have to grab the "mostly rewritten" cache from 2.1 (well, "mostly rewritten" sounds drastic, there are quite a few changes though).
The main reason is that the first time cache_get_data is called to retrieve $modSettings, $modSettings does not yet exist, so the check to see if the cache is enabled (!empty($modSettings['blabla'])) returns that the value is empty and the system thinks the cache is disabled.

Lainaus käyttäjältä: Guy Verschuere - tammikuu 20, 2014, 01:58:50 IP
b) UPDATE smf_log_activity SET hits = hits + 1 WHERE date = '2014-01-20'  (in Sources/Subs.php)
b) Why update the table on each pageview? Why not combine that in steps of 10?
And where would you save these 10 steps? In session? And what is the user hits only 9 times something?
Otsikko: Re: Optimal use of cache
Kirjoitti: Guy Verschuere - tammikuu 20, 2014, 04:51:57 IP
a) fixed, altered some things in function cache_get_data() so cache is hardcoded now.

b) maybe in cache? Should be a global counter do, for all users the same cache key.

Otsikko: Re: Optimal use of cache
Kirjoitti: Arantor - tammikuu 20, 2014, 05:43:03 IP
Also note that it isn't every page view that it updates the hit count.
Otsikko: Re: Optimal use of cache
Kirjoitti: Guy Verschuere - tammikuu 21, 2014, 12:59:48 AP
I think he does. Even if I refresh 10 times every second, the hits query is always done.
Otsikko: Re: Optimal use of cache
Kirjoitti: Arantor - tammikuu 21, 2014, 01:05:17 AP
As for doing it in batches, that gets complicated because you do have to store it somewhere between page views and session isn't somewhere I'd generally suggest that be stored... cache isn't advisable either because by definition a cache is volatile and you can't rely on it existing.

Oh, and yes, it's the overall hit count not the per topic one (which definitely isn't done every page view). Personally I'm not sure that's actually very useful though and on my own sites I just turn it off (everyone who really cares is going to be using Google Analytics)