I am developing a very busy web service which is supposed to get thousands of requests per second. I want that each request will update a counter field. How would i do that? Saving the counter in db is very important so I will not lose the information in case the server dies. I have tried the following code, but this will be a huge bottle neck for thousands requests per second. How would you do that?
public void Upload(int organizationId)
{
try
{
lock (UpadateLock)
{
using (var db = new DbContext())
{
Counter counter = db.Counters.Where(c => c.OrganizationId == organizationId).FirstOrDefault();
counter.count++;
db.SaveChanges();
}
}
}
catch (Exception ex)
{
}
}