Delayed Processing of Initial Queue Messages in WebJob: Seeking Solution for Idle Time in Storage Queue

Ajit Soutadekar 1 Reputation point
2023-10-30T10:13:54.4366667+00:00
    I have an App Service: AppService1
	Service Plan: AppService-Dev-SP (B1: 1)
	Configuration->General Settings -> Always On is selected.

	I have a Webjob in this service: AppSubscribers
	It picks messages from Queue Storage: AppStoragedev

	ISSUE:
	The 1st message which webjob picks from queue storage- takes 10-20  secs to process.
	Subsequent messages are being processed as expected.
	Maybe the Storage queue is going in Idle mode. 
	Need help

	Need Solution:
	Can you please suggest a suitable solution to handle this idle time in the storage queue?
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,761 questions
{count} votes

1 answer

Sort by: Most helpful
  1. SnehaAgrawal-MSFT 21,506 Reputation points
    2023-11-01T09:06:45.4866667+00:00

    Ajit Soutadekar Thanks for reaching here!

    Based on the information provided, it seems like the first message picked up by the WebJob takes longer to process than the subsequent messages.

    This could be due to the Storage Queue going into idle mode.

    One solution to handle this idle time in the Storage Queue is to increase the visibility timeout of the messages.

    To explain-

    Azure Storage Queue does not provide Ordering guarantees. However, Storage bus queue is able to provide First In First Out (FIFO) capabilities by using message sessions.

    Please check this document that compares both the queues: https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-azure-and-service-bus-queues-compared-contrasted

    Messages in Storage Queues are typically first-in-first-out, but sometimes they can be out of order.

    For example, when the visibility-timeout duration of a message expires because a client application crashed while processing a message. When the visibility timeout expires, the message becomes visible again on the queue for another worker to dequeue it. At that point, the newly visible message might be placed in the queue to be dequeued again.

    By default, the visibility timeout is set to 30 seconds, which means that if a message is picked up by a WebJob and not deleted within 30 seconds, it becomes visible to other clients.

    You can increase the visibility timeout to a higher value, such as 2-3 minutes, to give the WebJob enough time to process the message before it becomes visible to other clients. This can be done by setting the visibilityTimeout property when calling the receiveMessage method in your WebJob code.

    Another solution is to use the updateMessage method to periodically update the message's visibility timeout while it is being processed by the WebJob. This will prevent the message from becoming visible to other clients while it is still being processed.

    See- Below links might be helpful

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.