WindowsAzure:使用 phpazure 进行 Blob 缓存实验

发布于 2024-10-17 03:47:34 字数 594 浏览 5 评论 0原文

我正在做一些实验,将站点缓存到 blob 存储中。 现在我认识到这并没有我想象的那么快。例如,以下代码检查所请求站点的缓存版本是否存在并返回内容:

$blobStorageClient = new Microsoft_WindowsAzure_Storage_Blob();
if (!$blobStorageClient->blobExists(self::CONTAINER, $path))
return false;

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

此部分始终需要 500 毫秒到 1000 毫秒(有时 2000 毫秒)。我使用 PHP Azure SDK、Azure 计算模拟器和实时存储对其进行了测试。有人知道为什么它这么慢,或者这是正常的,我能做些什么更好,进行 blob 缓存是一个好主意吗?

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_Storage_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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

左秋 2024-10-24 03:47:34

我认为 blob 存储不适合缓存。它仍然可以在某些情况下使用,但通常您不希望缓存尽可能快。您应该使用 appfabric 缓存或内存缓存。在多实例环境中,内存缓存可能听起来很糟糕,但在某些情况下您可以使用它,具体取决于您的具体需求。

关于该代码..您将在这里进行 3 笔交易(如果该 blob 存在)。您可以尝试立即调用 getBlobData,如果出现 NotFound 错误,则返回 false。我不知道 php 的异常处理有多好,但我怀疑它比对 blob 存储的整个请求慢。

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.

冷弦 2024-10-24 03:47:34

商定的 blob 存储可能不是应用程序缓存解决方案。你有没有想过使用这个? http://www.davidaiken.com/2011/01/11 /windows-azure-memcached-plugin

感谢您使用 PHP SDK,您还有其他反馈意见想与我们的工程团队分享吗?

TGIF :)

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

多彩岁月 2024-10-24 03:47:34

我不知道为什么你的最后这么慢,但我实际上设法在 5 毫秒内得到不存在的 blob 的“错误”,并在 44 毫秒内得到实际数据(其中实际数据只有几个字节)。

每个缓存的 blob 中的数据大小是多少?如果只有几千字节,应该没问题,但更大的数据可能会使缓存变慢,因为每次都必须通过网络检索数据。

对于分布式缓存,请检查 http://www.davidaiken.com/ 2011/01/11/windows-azure-memcached-插件
要在本地 VM 上进行缓存,请使用文件系统(http://phpazurecontrib.codeplex.com,检查本地资源)或使用可用的 WinCache 扩展。

作为参考:在代码示例中不需要检查 blob 是否存在,只需尝试以下结构:

    $blobData = null;
$metaData = null;

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

return $blobData;

这将减少一次存储往返次数。

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.

牵强ㄟ 2024-10-24 03:47:34

在我看来,该代码正在对 blob 存储进行三次往返(当 blob 存在时)。我对 PHP 库不太熟悉,但希望有一个可以调用的方法可以立即提取 blob 数据和元数据。您可以尝试这样做,如果失败,则意味着该 blob 不存在。如果成功,请使用该数据。

至于时间,我的经验法则是,到存储的往返可能需要大约 10-30 毫秒,当然还有时间传输 Blob 数据,这取决于 Blob 的大小。当然,这个时间是在 Windows Azure 中运行的代码与同一位置的存储帐户进行通信的时间。

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.

凡尘雨 2024-10-24 03:47:34

2012 年 5 月更新

如果其他人遇到这个主题(就像我一样),自本文撰写以来,Azure 中的内存缓存已经发生了变化。 (内存缓存似乎是用户回答这个问题的方式)

Azure 现在有自己的缓存,但 PHP 本身并不支持它。所以这仍然不是一个真正的选择(截至 2012 年 5 月)。

因此,在撰写本文时,最好的选择(也是我正在使用的)是使用 memcached。然后,所有 PHP 记录的解决方案仍然有效,并且有部署 memcached 的示例 https://github.com/interop-Bridges/Windows-Azure-PHP-Scaffolders/tree/master/Memcached - 这个使用脚手架在服务器上安装memcached,然后你就可以使用PHP的memcache 或 memcached 来访问。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文