twhite3000 / vqmod

Automatically exported from code.google.com/p/vqmod
0 stars 0 forks source link

Better caching mechanism #101

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
NOTE THAT THIS IS FOR VQMOD ENGINE ERRORS ONLY. FOR GENERAL ERRORS FROM
MODIFICATIONS CONTACT YOUR DEVELOPER

What steps will reproduce the problem?
1. Install VqMod
2. Test performance drop (eg. on Linux using ab -c5 -n10 mywebsite

What is the expected output? What do you see instead?

vQmod Version: 2.3.2
Server Operating System: Debian Etch

Please provide any additional information below.
The current caching mechanism is better than in 2.1.8 but there is still lots 
of room for improvements.
In vqmod.php on line 124 if the file is not in cache and its SHA hash is not 
modified by any XML modification, such file is not stored in the cache.

This means that source files without modifications are tested on every request 
if there are any modifications or not. This should be done only once.

If we replace "if (sha1($fileData) != $fileHash)" with "if (1)" all files will 
be stored into cache (modified or not) and the whole perfomance increases by 
200%

To do it even better, the mods.cache should be used only to store the last 
modification time of the vqmod/xml directory and for each filename going into 
the modCheck() function there should be stored if:
  there is a cache file and its path(ie. modification exists)
  there is no cache file (ie. no modification exists)
  the filename was not checked for modification yet

So the caching would be:
1. in constructor unserialize from mods.cache
2. call modCheck($filename)
3. check if $filename is in mods.cache. If so:
a)  is it cached ? return contents of the cache file else return contents of 
$filename
b)  If the filename is not in mods.cache, load all the XMLs, check if its 
modified, update mods.cache in destructor

Regards Martin

Original issue reported on code.google.com by mar...@inprodej.cz on 22 May 2013 at 3:15

GoogleCodeExporter commented 9 years ago
What you are suggesting would place a vQmodded cache file of every file, 
regardless of any modifications?

Original comment by DJG6...@gmail.com on 22 May 2013 at 3:22

GoogleCodeExporter commented 9 years ago
Option number 1:
1) The simple solution is: Yes, on every file. This will skip this loop:
foreach($this->_mods as $modObject) {
                        foreach($modObject->mods as $path => $mods) {
                                if($this->_checkMatch($path, $sourcePath)) {
                                        $modObject->applyMod($mods, $fileData);
                                }
                        }
                }
on every request for not modified files. It does nothing as it goes through all 
XMLs and finds no modification in every request.

2) The more complex solution is to:
a) simplify the mods.cache to only contain if each file is modified or not and 
name of the cache file
b) this will reduce the size from average 0,5MByte to several kilobytes 
(unserialize will be much faster)
c) remove the call to _getMods() from constructor, put it into 
modCheck($filename) after the check if there is a cache file
d) "lazy" load the modifications only if the there is no info for the $filename 
in mods.cache

Original comment by mar...@inprodej.cz on 22 May 2013 at 9:22

GoogleCodeExporter commented 9 years ago

Original comment by DJG6...@gmail.com on 26 Jul 2013 at 7:56