php/mysql 分类按日期查看计数器
我正在构建一个广告分类网站,我想在其中存储每个广告的观看次数计数,我希望能够在以后的日期、按天和按月等以图表形式显示每个广告的观看次数。对于每个用户和每个他们的广告。我只是在努力决定如何最好地实现 mysql 数据库来存储每个广告的潜在大量数据。
我将为页面视图创建一个表,如下所示,它将为每个广告的每个视图存储一条记录,例如,如果广告(id 1)有 200 个视图,则该表将存储 200 个记录:
Advert_id(广告的唯一 id)
date_time(查看的日期和时间)
ip_address(查看广告的人的唯一 IP 地址)
page_referrer(推荐人页面的 URL)
如前所述,我将为每个成员创建功能网站查看每个广告的观看统计数据图表,以便他们可以查看每个广告的总观看次数,以及他们的广告每天的观看次数(在 2 个给定日期之间)以及有多少观看次数每个广告的每月浏览量。我将通过按 date_time 字段分组来完成此操作。
如果我的网站变得相当大,例如有 40,000 个广告,每个广告平均有 3,000 次页面浏览,则意味着该表有 1.2 亿条记录。这太大了吗?生成图表的 mysql 查询会非常慢吗?
您认为上面的表格和方法是存储这些广告浏览统计数据的最佳方式还是有更好的方式来做到这一点?
Im building a classifieds website of adverts where I want to store a count of the number of views of each advert which I want to be able to display in a graph at a later date by day and month etc.. for each user and each of their adverts. Im just struggling with deciding how best to implement the mysql database to store potentially a large amount of data for each advert.
I am going to create a table for the page views as follows which would store a record for each view for each advert, for example if advert (id 1) has 200 views the table will store 200 records:
Advert_id (unique id of advert)
date_time (date and time of view)
ip_address ( unique ip address of person viewing advert)
page_referrer (url of referrer page)
As mentioned I am going to create the functionality for each member of the site to view a graph for the view statistics for each of their adverts so they can see how many total views each of their adverts have had, and also how many views their advert has had each day (between 2 given dates) and also how many views per month each advert has had. I'll do this by grouping by the date_time field.
If my site grows quite large and for example has 40,000 adverts and each advert has on average 3,000 page views, that would mean the table has 120 Million records. Is this too large ? and would the mysql queries to produce the graphs be very slow?
Do you think the table and method above is the best way to store these advert view statistics or is there a better way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除非您确实需要存储所有数据,否则最好在查看广告时增加计数。因此,每个广告只需一行(甚至广告行中的一列)。
另一种选择是将其保存到文本文件中,然后离线处理它,但通常最好在获取数据时对其进行处理并将其合并到您的应用程序流程中。
如果您确实需要保存所有这些数据,那么每周轮换日志表(处理后)可能会减少无限期存储所有这些信息的开销。
Unless you really need to store all that data it would probably be better to just increment the count when the advert is viewed. So you just have one row for each advert (or even a column in the row for the advert).
Another option is to save this into a text file and then process it offline but it's generally better to process data as you get it and incorporate that into your applications process.
If you really need to save all of that data then rotating the log table weekly maybe (after processing it) would reduce the overhead of storing all of that information indefinitely.
我正在处理每天有 50.000 个唯一访问者的网站,并且我和你有同一张桌子。
表每天增长约 200-500 MB,但我每天都能清理表。
最好的选择是创建第二个表,每天计算访客数量,将结果添加到第二个表,然后刷新第一个表。
第一个表示例:
第二个表示例(用于图表):
统计唯一访问者的示例 SQL 查询:
问题甚至不是性能(MySQL ISAM 引擎非常智能且快速),问题是存储如此大的数据。
90% 的统计工具(甚至谷歌分析或 webalyzer)每天只制作一次图表,而不是实时的。
很好的主意是使用函数 ip2long() 将 IP 存储为 INT
I was working with website with 50.000 unique visitors per day, and i had same table as you.
Table was growthing ~200-500 MB/day, but i was able to clean table every day.
Best option is make second table, count visitors every day, add result to 2nd table, and flush 1st table.
first table example:
second table example (for graph):
Example SQL query to count unqiue visitors:
Problem is not even perfomance (MySQL ISAM Engine is quite smart and fast), problem is storage such big data.
90% statistics tools (even google analytics or webalyzer) is making graphs only once per day, not in real-time.
And quite good idea is store IP as INT using function ip2long()