How to build a large-scale global counter in Azure?

I am trying to set up a global counter in Windows Azure that will track the number of games running during the day. Each time a player starts a game, a web service call is made from the client to the server, and the global counter is incremented. It should be pretty simple to do with the database ... But I wonder how I could do this effectively. A database approach is good for several hundred clients at the same time, but what happens if I have 100,000 clients?

Thanks for your help / ideas!

+1
source share
3 answers

A little over a year ago, it was a topic in the Cloud Cover episode: Cloud Cover Episode 43 - Scalable Counters with Windows Azure . They discussed how to create an Apaythy Button (similar to the Like button on Facebook).

Steve Marx also discusses this in detail on his source code blog: Scalable Counter Architecture with Windows Azure . In this decision, they do the following:
  • In each instance, track the local counter
  • Use Interlock.Increment to change the local counter.
  • If the counter has changed, save the new value in the table storage (each timer does this every few seconds). For each deployment / instance, you will have 1 entry in the counter table.
  • To display the total counter, take the sum of all entries in the counter table.
+6
source

Well, there are plenty of options. And I do not know what is best for you. But I will give them here with some pros and cons, and you can come to your own conclusions, taking into account your requirements.

The simplest answer is to put it in storage. Both Azure SQL and the Azure base table or blog storage options are for you. One issue that needs to be addressed is performance in the face of large-scale concurrency, but I also urge you to think about the correctness. You really want something that supports atomic increment in order to convey this problem to IMO.

Another storage-oriented option would be a highly available virtual machine. You can deploy your own virtual machine to Azure, return the data disk to Azure Drives, and then use something on top of the OS for this (database server, an application that directly uses the file system). It would be more like what you would do at home, but it would have some pretty bad compromises ... your whole cloud now depends on the availability of this virtual machine, the cost is what you need to think about, the scalability of the solution, and so on . Splunk can also be considered if you look at virtual machines.

As mentioned earlier by an earlier commenter, you can compute log data. But it probably won't be super in real time.

A service tire is another consideration. You can pump messages through SB for these events and have a consumer who reads them and emits a "resume". There are several design options to consider if you look at this. The SB stack is well documented. Another interesting element of SB is that you could adjust 100% correctness for performance / scale / cost. This can be a worthy compromise for you depending on your goals.

Azure also provides queues that may be appropriate. I agree, I think SB is probably a better fit, but it's worth a look at both if you go this route.

Sorry, I don't have a silver bullet, but I hope this helps.

0
source

I suggest you follow the pattern described in the .NET Multi-Tier Application . This will help you separate the Web role that your customers are facing and the Worker role, which will store data on a continuity medium (or SQL Server / Azure Storage) using the service bus.

It is also an effective scaling model because you can span new instances of a web role or worker role, or both. For the control panel, depending on the load, you can cache your data periodically and remove the server from the cache. This may compromise the accuracy of the data, but will still be able to scale easily. You can even invalidate the cache every 1 minute and load it from the save environment to get the latest value.

Regarding the use of SQL Server or Azure storage, if you do not need relational capabilities such as JOINS , etc., you can very well go to Azure storage.

0
source

Source: https://habr.com/ru/post/1485307/


All Articles