Advertisement:

Optimal use of cache

Aloittaja Guy Verschuere, tammikuu 20, 2014, 01:58:50 IP

« edellinen - seuraava »

Guy Verschuere

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!

emanuele

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?


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Guy Verschuere

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.


Arantor

Also note that it isn't every page view that it updates the hit count.
Holder of controversial views, all of which my own.


Guy Verschuere

I think he does. Even if I refresh 10 times every second, the hits query is always done.

Arantor

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)
Holder of controversial views, all of which my own.


Advertisement: