1

I'm building a news website using Django and hope this website can handle millions of traffic.Now I'm coding a function that displays 48 hours most viewed articles to readers,so I need calculate the PV.

I have searched for a while and asked some people.I know I have some options:

1.using simply click_num=click_num+1,but I know this is the worst way.

2.A better way is using Celery to code a distributed task,but I don't know how to exactly do it.

3.I heard Redis also can used to calculate PV and UV but,have no idea how to do it and not sure the it can satisfy my needs.

4.Another good way is to use google analysis,but I also have no idea how to do it and not sure the it can satisfy my needs.

5.The last way ,I think the easiest way is to use JavaScript, but I'm not sure whether it can satisfy my needs.

Any friend can give me some advice? Thank you so much!

William
  • 3,724
  • 9
  • 43
  • 76
  • You don’t get millions of views from one day to the next. There’s no reason to write something to deal with such traffic before you actually see any scaling issues. Google Analytics can do this for you, just add their javascript to your page. Or create your own little analytics api that you call with a little javascript on your page. Even using a normal database works for millions of views per month. – dirkgroten May 13 '18 at 21:20
  • Thank you so much! – William May 14 '18 at 15:17
  • I missed your tag, did you end up using something? – Lemayzeur May 18 '18 at 05:16
  • Yes, currently,I'm using F() expressions like this, News.objects.filter(id=news_pk).update(pv=F('pv') + 1),in the future I may use something like redis.But now I just want to finish this project as soon as possible.: ) – William May 18 '18 at 19:01
  • Hi friend,I asked a new question ,could you help me to check?Thank you so much! https://stackoverflow.com/questions/50418200/how-to-get-data-from-last-48-hours-django – William May 18 '18 at 19:38

0 Answers0