Testing File Change Notification support on WinCache 1.1 Beta2

As you all know we did a Beta2 release of WINCACHE 1.1 few days back. This is a very important release with lots of bug fixes and new features. I would encourage all current users of WINCACHE to upgrade to Beta2 latest build.

I have already blogged about my favorite feature which is support for file change notification. Testing this was a bit of challenge. And believe me there were people in the team who were extremely skeptical about this working in a way which doesn’t cause any problem while executing HTTP request. I would agree with the concerns. This made me think about a good strategy to test it.

Simple exploratory testing covered basic scenarios. This means I used to do the following:

  • Send request to a page like http://localhost/mediawiki
  • This means if my site is mapped to directory C:\inetpub\wwwroot\mediawiki, WINCACHE will start listening to folder C:\inetpub\wwwroot\mediawiki
  • Now either open the file index.php and save it (raises FILE_NOTIFY_CHANGE_LAST_WRITE), or change the security settings (raises FILE_NOTIFY_CHANGE_SECURITY), or run TOUCH command or something similar (raises FILE_NOTIFY_CHANGE_ATTRIBUTES).

This was an okay strategy. I did find bugs but not all and was still not satisfied.

Then one fine day my grey cells came out with a new thinking. I thought of running stress where we keep sending request to some popular web sites home pages at regular intervals using WCAT and using 50 concurrent connections. Now the challenge was just to keep changing files in a random way. Well PHP came to the rescue. Here is the script I wrote which did the trick.

<?php
define(MAX_NUM_FILES, 9);
$sleep_time = 30;
if ($argc == 2)
{
    $sleep_time = $argv[1];
}


$sys_drive = getenv("SystemDrive");
$root = $sys_drive . "\\inetpub\\wwwroot";
$file_array = array
        (
            "$root\\drupal\\index.php",
            "$root\\drupal\\modules\\cacherouter\\engines\\wincache.php",
            "$root\\drupal\\cron.php",
            "$root\\wordpress\\index.php",
            "$root\\wordpress\\wp-content\\object-cache.php",
            "$root\\wordpress\\wp-blog-header.php",
            "$root\\sugarcrm\\index.php",
            "$root\\sugarcrm\\include\\utils\\external_cache\\SugarCache_WINCACHE.php",
            "$root\\joomla\\index.php"
        );

$i = 0;
while(true)
{
    if ($i == 1024)
        $i = 0; //don't want overflow
    $i++;
    $random_index = rand(0, MAX_NUM_FILES - 1);
    if ($i % 3 == 0)
    {
        touch($file_array[$random_index]);
    }
    else if ($i % 3 == 1)
    {
        exec("copy /b $file_array[$random_index]" . "+,,.");
    }
    else
    {
        $tmp_dir = getenv("SystemRoot") . "\\Temp\\";
        $tmp_file = $tmp_dir . "ACLFile.txt";
        exec("icacls.exe $file_array[$random_index] /save $tmp_file");
        $dir = dirname($file_array[$random_index]);
        exec("icacls.exe $dir /restore $tmp_file");
    }
    sleep($sleep_time);
}
?>

This script was kept running in the background while stress was running. Well all different notification tested and in a stressful way. We found lot of bugs and good ones and fixed it. I chose those set of files because those were being hit or included as part of hitting home page of applications. I really like PHP for this as it gives you a lot of API which can be used to automate many systems. And now I am confident that this feature is well tested and we have fixed almost everything. So feel free to use the Beta bits and enjoy. And yes if you have any suggestion please feel free to leave a comment here. I am open to good suggestion.

Thanks for patient reading and till we meet again ‘Good Bye’.

Don.

PS: Though not related to WINCACHE, this is an interesting article how dynamic maximum instance can help increasing performance.

No Comments