BALA G
BALA G

Reputation: 75

How to use Sync Method across multiple instance azure worker role?

I am using azure worker role with auto scale.. When more than one instance running, performance is good. But some function should not run in same time. so i need to make a method or task as sync, or need to lock until another one finished.. Need to implement this across multiple azure instance.. Or specific function should run in only one instance.

How to implement this?

Thank you

Upvotes: 2

Views: 243

Answers (1)

Gaurav Mantri
Gaurav Mantri

Reputation: 136146

Since each instance runs independently, I don't think making a method or task sync is going to help you out as each method or task will run synchronously in each instance.

Do take a look at Leader Election Pattern (and while you're there, do take a look at other cloud patterns as well). Essentially the idea is that each instance will fight (for the lack of better word :)) to execute a method but only once instance will succeed. The instance which will succeed is the Leader and will execute the method. There are two ways by which you can implement this:

  1. Lease Blob - There's a blob in blob storage and before executing the method, each instance will try to acquire a lease on this blob. Only one instance will succeed. The instance which acquires the lease on the blob will execute this method.
  2. Get Message - Information about method to execute is stored in Azure Queues as a message. All instance will try to GET message from this queue but only one instance will GET the message. The instance which gets the message will execute the method.

Upvotes: 1

Related Questions