我应该使用日志文件还是数据库来跟踪印象?

发布于 2024-10-12 08:25:10 字数 111 浏览 3 评论 0原文

我在 iframe 中有一张图片(类似于广告),该图片将被放置在多个网站中。我应该使用服务器日志文件来找出印象吗?或者我应该使用数据库来跟踪每次印象?

哪种方式速度更快并且可以处理大流量?谢谢

I have a picture (similar to an ad) in an iframe that will be placed in multiple sites. Should I use the server log file to find out the impression? or should I use DB to keep track of each impression?

which way is faster and can handle large volume of traffic? thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

停滞 2024-10-19 08:25:10

这个问题的答案实际上取决于您使用的数据库类型,以及您的部署环境中 Web 服务器磁盘和数据库的实际繁忙程度;

  • 如果每次完成印象时都将日志条目记录到文件中,那么速度会非常快。您可以每天将此文件移动到一个新文件并将其发送到某个后端系统来处理它,并且您很可能永远不会丢失一个条目(除非您遇到磁盘崩溃)
  • 带有表条目的常规 mysql 数据库可能有点过大为此,除非您想使用同一个表来对数据进行查询。它可能也可以很好地扩展,但是如果您的流量很大,您最终可能会在这里得到很多条目。
  • 为此使用 nosql 数据库可能是一个很好的匹配,这可能会像 Twitter 一样扩展它 - 尽管大多数网站不像 Twitter,所以它可能对您的需求来说有点过分了:)

如果您有一个常规网站,您可以可能会采用第一种方法,因为它很简单。如果没有,那么您还没有在上面花费很多时间。

The answer for this question really depends on what kind of database you are using, and how busy the web servers disk and the database really are in your deployment environment;

  • If you cat a log entry to a file each time an impression is done this is pretty fast. You can daily move this file to a new file and send it to some back-end system to process it and you would most likely never loose an entry (unless you encounter a disk crash)
  • A regular mysql database with a table entry might be overkill for this unless you want to use the same table for doing queries on the data. It would probably also scale well, but you could end up with a lot of entries here if you have lots of traffic.
  • Using a nosql database for this could be a good match, and this would probably scale it up to scaling like twitter - though most sites aren't like Twitter so it is probably overkill for your needs :)

If you have a regular website you can probably get away with doing it the first way as it is simple. If it does not, you haven't spent a lot of time on it.

说谎友 2024-10-19 08:25:10

对我来说听起来很合理。使用日志的简单方法可以是使用 grep 从日志中查找正确的调用并对其进行计数。

正如 Knubo 所说,压缩已经处理过的条目是有意义的,因为每小时 1000 万+,您可能会看到相当多的日志文件:) 因此,例如每天执行一个过程:

  1. 启动一个新的日志文件(日志旋转)
  2. 计数昨天日志文件中的正确条目 归档
  3. 已处理的日志文件(gzip、bzip2、7zip 等)

Sounds reasonable to me. The simple way with logs could be e.g. to use grep to find the correct calls from the log and count them.

As Knubo said, compressing entries that have already been processed makes sense, as with 10M+/hour you could be looking at quite a log-file :) So e.g. daily do a process which:

  1. Starts a new log-file (log rotating)
  2. Counts correct entries from yesterdays log-file
  3. Archives the processed log-file (gzip, bzip2, 7zip etc.)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文