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

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秒钟的时间。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值