none
Execute Methode in windows azure with multiple instances

    Question

  • I want to execute a job scheduler methods in my windows azure application. So in my application i am using 2 instance of the same application. So If i create a scheduler means both the instance can execute same code. Is it possible to avoid such execution? Or is it possible check other instace before executing the code? For the implementation i am using c#.Net.
    Tuesday, June 26, 2012 6:25 AM

Answers

  • Use a pattern I've taken to calling the "Self elected controller". I've explained it briefly on a related post on Stackoverflow.

    Essentially this pattern lets you have multiple instances of a role running but helps ensure that a specific process is only "active" in one instance at a time.

    Tuesday, June 26, 2012 8:28 PM
  • I've got the exact same problem, so I know what you're saying. I have two identical instances that both dequeue messages and do the requested work - effectively splitting my workload across the two instances. However, the problem is that I still need something put push the messages into the queue on a scheduled basis. I've toyed with the idea that Brent offered up, but anticipate that it's a bunch more work than I was willing too take on.

    My current solution is to have an auxiliarly worker role running in it's own instance that does the scheduling and enqueuing. It's not necessarily cost effective, but it works.


    Chris

    Thursday, June 28, 2012 6:01 PM

All replies

  • What do you mean by instances? If you mean Windows Azure instances, you can use Queues for instance interaction.

    Add a message to Queue before starting to work, then wait a few seconds and test if your message is still the first in the queue, and start working.

    Delete the message from Queue after finished working.


    DNS for Windows Azure dnsazure.com

    Tuesday, June 26, 2012 7:28 AM
  •  Hi,

    Usually Scheduled jobs are executed with worker role/s. The logic can be that the input for the jobs can be queued through Azure queues and the jobs will be picked by one or more Worker roles (In which the schedulers are running).

    Regards,

    Vijay.

    Tuesday, June 26, 2012 7:32 AM
  • Basically your issue is around concurrency, and to ensure a task is executed just once? Steve Marx had some article about a while ago http://blog.smarx.com/posts/building-a-task-scheduler-in-windows-azure, that should give you some background how such situations could be handled.

    Tuesday, June 26, 2012 2:28 PM
  • If its a really simplistic scenario - may be the "lock" keyword in C# would help in enforcing concurrency? http://msdn.microsoft.com/en-us/library/c5kehkcz(v=vs.80).aspx


    PS

    Tuesday, June 26, 2012 4:41 PM
  • If its a really simplistic scenario - may be the "lock" keyword in C# would help in enforcing concurrency? http://msdn.microsoft.com/en-us/library/c5kehkcz(v=vs.80).aspx


    PS

    the lock statement is limited to an application on a single instance! There are some other synchronization mechanism available for system wide use, however non of them enables syncronization across instances!

    For that you'd need some other way to synchronize functionality, where using a lease on CloudBlob such as used in the sample above may be one of them, there could be others too.

    Tuesday, June 26, 2012 6:07 PM
  • Use a pattern I've taken to calling the "Self elected controller". I've explained it briefly on a related post on Stackoverflow.

    Essentially this pattern lets you have multiple instances of a role running but helps ensure that a specific process is only "active" in one instance at a time.

    Tuesday, June 26, 2012 8:28 PM
  • I've got the exact same problem, so I know what you're saying. I have two identical instances that both dequeue messages and do the requested work - effectively splitting my workload across the two instances. However, the problem is that I still need something put push the messages into the queue on a scheduled basis. I've toyed with the idea that Brent offered up, but anticipate that it's a bunch more work than I was willing too take on.

    My current solution is to have an auxiliarly worker role running in it's own instance that does the scheduling and enqueuing. It's not necessarily cost effective, but it works.


    Chris

    Thursday, June 28, 2012 6:01 PM