当前位置:   article > 正文

Windows Azure的数据存储和性能比较(一)

azure blob 存储 插入数据效率

Windows Azure的数据存储和性能比较

在Windows Azure上存储数据大体上有两种方式:Windows Azure Storage和SQL Azure。其中,Storage上的存储又细分为:Blob,Table和Queue三种。下文就把这几种在Azure上的存储方法及性能作个简单的比较,粗忽之处还请雅正。

1、Blog存储:存储大型的二进制数据,最大的存储为50G。

(1)Blob的操作示例:在Blob中存储一个字符串,再读取出来。

CloudBlobClient blobclient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobclient.GetContainerReference("blobtest"); container.CreateIfNotExist(); CloudBlob blob = container.GetBlobReference("myFile"); blob.UploadText("Hello World!"); string blobcontent = blob.DownloadText();


(2)使用流的方式更新Blob数据。

由于使用OpenWrite得到的BlobStream分别为只写的,所以,不能使用Seek方法来定位写入位置,所以,如果想更改Blob中的内容,可能需要把所有的数据都读取到内存中,修改后,再上传。如果仅仅是在现有的Blob后面追加数据,这样做的方式效率较低。现给出使用两个流的方式来更新Blob,供参考。

CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount; CloudBlobClient blobclient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobclient.GetContainerReference("blobtest"); container.CreateIfNotExist(); CloudBlob blob = container.GetBlobReference("myFile"); BlobStream streamWrite = null; try { streamWrite = blob.OpenWrite(); BlobStream streamRead = null; try { streamRead = blob.OpenRead(); byte[] buffer = new byte[32]; int len = -1; streamRead.Seek(1, System.IO.SeekOrigin.Begin); while ((len = streamRead.Read(buffer, 0, buffer.Length)) > 0) { streamWrite.Write(buffer, 0, len); } string appendContent = "This is example."; byte[] bs = Encoding.ASCII.GetBytes(appendContent); streamWrite.Write(bs, 0, bs.Length); } finally { if (streamRead != null) { streamRead.Close(); streamRead = null; } } } finally { if (streamWrite != null) { streamWrite.Close(); streamWrite = null; } }


(3)Blob操作性能的比较

Blob数据追加,更新和删除的性能曲线。

Blob数据下载的性能曲线。从这图可以得知,如果下载一个5M大小的数据,可能的需要将近5秒钟的时间。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/138238
推荐阅读
相关标签
  

闽ICP备14008679号