'How to use Azure CloudQueueClient within Web API?

I have a ASP.NET Web API 2.0 project running in Azure. The main method is called every minute by 1000s of remote devices. There seems to be a memory issue. When the API is started the memory loading is about 40%. Within 24 hours this creeps up to 80+%, at which time I restart the service and memory drops back to 40% and the cycle begins again. This is a relatively new problem resulting from increasing numbers of devices connecting. I guess some threshold has been reached.

The main method that the remote devices are calling basically takes the device data and pushes it onto a Azure Queue via a CloudQueueClient. Before the memory loading became a problem I was creating a new CloudQueueClient for each call. When I changed this to a global CloudQueueClient the memory issues seemed to be alleviated somewhat - the time it took to go from 40% - 80% increased by a factor of 10+. This is why I'm thinking my use of CloudQueueClient and CloudQueue objects might be the issue.

I push the device data using:

 var queue = queueClient.GetQueueReference(queueName);
 await queue.AddMessageAsync(new CloudQueueMessage(message));

Where queueClient is my global CloudQueueClient instance. As you can see I'm still created an instance of CloudClient on every call. Should I be reusing an instance of CloudClient for every call.

My question is simply, what is the right way to use CloudQueueClient and CloudQueue within the context of a Web API application?

Note that I distribute the incoming device messages across several queues to relief the loading on each queue so as not to be throttled.



Solution 1:[1]

Can't the device send the data directly to the queue instead of using your api as middleman? There is a rest api available.

Also this link may be helpful:

You can reuse the CloudQueue and CloudQueueClient instances.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Peter Bons