1

I am struggling to answer this question for myself so can anyone answer it for me. How, exactly, do webjobs get run? By this I mean does the Azure framework manage access to the WebJob and are multiple instances run in separate processes?

I am under the impression that I get 12 or 16 parrallel instances by default. Is this correct? So if three messages are placed on a queue, that my webjob is triggered by, they will all run in parrallel.

onesixtyfourth
  • 744
  • 9
  • 30

1 Answers1

1

AFAIK, when you scale out multiple instances, the webjobs will run on the instances in parallel in separate processes. But there are prerequisites of it,

  1. The webjob should be continous and not Manual/Scheduled.
  2. For this to happen correctly, you need to be running in Standard mode, and have the Always On setting enabled.

Note: If you use TimerTrigger in your webjob, it will not scale out. Refer to this article.

Behind the scenes, TimerTrigger uses the Singleton feature of the WebJobs SDK to ensure that only a single instance of your triggered function is running at any given time. When the JobHost starts up, for each of your TimerTrigger functions a blob lease (the Singleton Lock) is taken. This distrubuted lock ensures that only a single instance of your scheduled function is running at any time.

For more details about the issue, here are two similar posts for you to refer, 1 and 2.

Joy Wang
  • 39,905
  • 3
  • 30
  • 54
  • Interesting about the TimerTrigger I didn't realise that but for continuous jobs I am referring to how it runs on an instance. I have noticed that if I have more than one message on a queue they appear to be processed in parrallell. How is this managed/administered. – onesixtyfourth Jun 13 '18 at 06:56
  • @onesixtyfourth As mentioned in the [link](https://stackoverflow.com/questions/24461772/multiple-azure-webjob-instances-on-one-queue) in my reply, each job instance will pick a different message from the queue via [Azure WebJobs SDK](https://github.com/Azure/azure-webjobs-sdk/wiki). – Joy Wang Jun 13 '18 at 07:02
  • BatchSize is what I wanted to know about. config.Queues.BatchSize controls the number of items that will be processed in parrellel. So an instance can process more than one item. https://github.com/Azure/azure-webjobs-sdk/wiki/Queues#-parallel-execution – onesixtyfourth Jun 13 '18 at 07:33
  • @onesixtyfourth Yes, in short the SDK will manage it. Glad your issue has been solved. – Joy Wang Jun 13 '18 at 07:37