Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incrementing Counters in Azure Table [duplicate]

I plan to use Azure Tables to store various application related counters. My concerns are the counters are incremented from many different client instances of the application.

Seems like a simple task at the surface, but looking at it closer it is quite challenging.

I hoping someone can share some wisdom that will help make the problem more manageable.

Thanks!

like image 376
Chris Craft Avatar asked Dec 27 '22 03:12

Chris Craft


1 Answers

Steve Marx has covered this quite well in his blog and the related Cloud Cover episode. The short version is:

  • The client contacts the web role.
  • The web role updates a static variable using the System.Threading.Interlocked functionality. This avoids multiple threads on the server trying to update the same number.
  • Each webrole has a background thread which on a timed basis writes back to the count table which includes as part of its PartitionKey/RowKey the instance name. This avoids two instances trying to update the same number at the same time.
like image 146
knightpfhor Avatar answered Jan 16 '23 15:01

knightpfhor