开发者

WindowsAzure: Blob cache experiments with phpazure

I'm doing some experiments with caching sites into the blob storage. Now I recognize that this is not as fast as I expected. For instance, the following code checks if a cached version of the requested site exists and returns the content:

$blobStorageClient = new Microsoft_WindowsAzure_Stora开发者_开发百科ge_Blob();
if (!$blobStorageClient->blobExists(self::CONTAINER, $path))
return false;

$blobData = $blobStorageClient->getBlobData(self::CONTAINER, $path);
$metaData = $blobStorageClient->getBlobMetadata(self::CONTAINER, $path);
...

This part takes always between 500ms and 1000ms (somtime 2000ms). I tested it with PHP Azure SDK, Azure Compute Emulator and live storage. Does somebody know why it is so slow, or is it normal, what can I do better, is it at all a good idea to do blob caching?


I don't think blob storage is suitable for caching. It can still be used in certain situations, but generally you wan't your cache to be as fast as possible. You should use appfabric cache or memory cache. Memory cache might sound bad in multi instance environment, but there are certainly cases where you can use it, depends on what exactly you need.

About that code.. you are making 3 transactions here (in case that blob exists). You could try to call getBlobData immediately and in case of NotFound error return false. I don't know how good is php with exception handling, but I doubt it is slower than whole request to blob storage.


agreed blob storage may not be the app cache solution. Have you thought about using this? http://www.davidaiken.com/2011/01/11/windows-azure-memcached-plugin

Thanks for using the PHP SDK, any other feedback you'd like to share with our engineering team?

TGIF :)

jas


I'm not sure why it's so slow at your end, but I actually manage to get a 'false' for non-existing blobs in 5ms and the actual data in 44ms (where the actual data is only a few bytes).

What size of data is in every cached blob? If it's only a few kilobytes it should be no problem, but anything bigger will probably make your cache slow as data has to be retrieved over the network each time.

For distributed caching, check http://www.davidaiken.com/2011/01/11/windows-azure-memcached-plugin. For caching on the local VM, use the filesystem (http://phpazurecontrib.codeplex.com, check local resource) or make use of the WinCache extensions available.

And for reference: checking if the blob exists is not necessary in your code sample, just try the following structure:

    $blobData = null;
$metaData = null;

try {
    $blobData = $blobStorageClient->getBlobData($container, $path);
    $blobStorageClient->getBlobMetadata($container, $path); 
} catch (Microsoft_WindowsAzure_Exception $ex) {
    return false;
}

return $blobData;

This will have one less roundtrip to storage.


It looks to me like that code is doing three round-trips to blob storage (when the blob exists). I'm not that familiar with the PHP library, but hopefully there's a single method you can call that will pull down the blob data and metadata at once. You can just try to do that, and if it fails, it means the blob didn't exist. If it succeeds, use that data.

As for timing, my rule of thumb is that a roundtrip to storage will probably take around 10-30 milliseconds, and then of course there's time to transfer the blob data, which depends on the size of the blob. That time is of course for code running in Windows Azure talking to a storage account in the same location.


Update for May 2012

In case someone else comes across this topic (as I did), there have been movements with memory caching in Azure since this was written. (And memory caching appears the way for the user to go for this question)

Azure does now has it's own caching, but it's not natively supported in PHP. So that's still not really an option (as of May 2012).

So, at the time of writing, the best option (and the one I'm using) is to use memcached. Then all the PHP documented solutions still work, and there are examples of deploying memcached at https://github.com/interop-Bridges/Windows-Azure-PHP-Scaffolders/tree/master/Memcached - this uses a scaffold to install memcached on the server, then you can use PHP's memcache or memcached to access.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜