Azure的Blob和队列线程安全 [英] Azure Blob and Queue Thread Safety

查看:210
本文介绍了Azure的Blob和队列线程安全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在理解蔚蓝CloudBlobClient,CloudQueueClient和CloudBlob类线程安全一些帮助。

I need some help in understanding the thread safety in azure CloudBlobClient, CloudQueueClient and CloudBlob classes.

我开发辅助角色,其包括其中每个工作处理器从特定队列中读取和写入/更新到一些斑点容器可以是相同的多个独立工作的处理器。

I am developing a worker role which includes multiple independent job processors where each of these job processors read from a specific queue and write/update to some blob containers which may be the same.

我要确保这些任务​​处理器不踩着对方的脚趾。

I want to make sure that these job processors are not stepping on each other toe.

1>如何确保这是不使用任何类型的锁的情况下?如果我分配一个单独的CloudBlobClient和CloudQueueClient给我的每一个工作处理器(谁都住同一个进程内),是否足够地说,他们是独立的,相互借鉴,因为每一项工作的处理器使用一个单独的客户机实例,它们将无法运行对方呢?

1> How can I make sure that this is the case without using any kind of lock? If I assign a separate CloudBlobClient and CloudQueueClient to each of my job processors (who all live within same process), is it enough to say that they are independent from each other and because every job processors uses a separate client instance, they will not run into each other at all?

2>在相同的工作的处理器,如果我尝试使用Parallel.ForEach说并行调用GetBlobReference或UploadText会对CloudBlobClient并行,做我需要纳入某种同步或者这些方法的线程安全的? Azure的文件说,他们不是,但似乎我已经在网上看到的大多数例子并不适用任何类型的同步机制上的这些方法。什么是实现这一目标的最佳途径?我的意思是使用一个CloudBlobClient并调用GetBlobReference或UploadText并行的最佳方式?

2> Within same job processor, if I try to have parallelism on CloudBlobClient using Parallel.ForEach to say call GetBlobReference or UploadText in parallel, do I need to incorporate some sort of synchronization or are these methods thread safe? Azure documentation says they are not but most examples that I have seen online do not seem to apply any kind of synchronization mechanism on these methods. What is the best way to achieve this? I mean the best way to use one CloudBlobClient and call GetBlobReference or UploadText in Parallel?

推荐答案

我有一个看 CloudBlobClient 在MSDN上和它说什么文档:

I had a look at the CloudBlobClient documentation on MSDN and what it says is:

任何公共static这种类型的成员(在Visual Basic中的Shared)是线程安全的。任何实例成员不能保证是线程安全的。

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

由于这不是一个静态的成员,它不能保证线程安全的。如果你想确保你不会被任何线程问题MS可以在存储客户端库已经错过了被抓住了,然后是你应该确保每个线程都有它自己的客户端(也许创建的 ThreadStatic 变量)。

As this is not a static member, it is not guaranteed to be thread safe. If you want to be sure that you're not going to get caught out by any threading issues the MS may have missed in the storage client library, then yes you should ensure that each thread has it's own client (maybe create a ThreadStatic variable).

说了这么多,我已经使用了 CloudBlobClient 来在 Parallel.ForEach 上传多个项目,而不会使它任何问题。

Having said that, I have used the CloudBlobClient to upload multiple items in a Parallel.ForEach without it causing any problems.

这篇关于Azure的Blob和队列线程安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆