-2

I want to create function to update count for page views I use ado.net i build update method to update count by 1 every page load and lookup by id

Problem : We have large visitors it can reach to 3k online user per second and execute it by ajax call Its make database high performance and table locked and site run out memory Is there are any solution for it ?

  • Use a queue maybe? That way your controller can just fire the add-to-queue event and move along. Then your queue will just increment the db by one for every message. – maccettura Jul 07 '17 at 22:16

1 Answers1

1

Rather than execute SQL on every page view, you should increment an in-memory int or long using Interlocked.Increment. Then on every (for example) 5,000 increments (checked using Mod) then you should hit the database and increase the pageview count by 5,000.

It does mean the page view count will be updated slower than currently, but it will massively reduce DB load.

Also consider using Redis to store the counts, rather than whatever your existing database is. Redis is awesome for this kind of use-case.

mjwills
  • 23,389
  • 6
  • 40
  • 63
  • How do can I include Redis in my MVC app, and how can I pass the count through a model to my view so I can display my page view count? –  Jul 09 '17 at 04:02
  • @RyanVancityGosling For Redis, see https://stackexchange.github.io/StackExchange.Redis/ . For displaying it, you will need to create a new question for that. – mjwills Jul 10 '17 at 07:09
  • Thanks for quick response I will try it – Ahmed Elgendy Jul 10 '17 at 20:30