我应该使用 mysql 来保存日志,还是只转储到文本文件

发布于 2024-10-02 16:10:49 字数 336 浏览 4 评论 0原文

我正在创建一个将进行大量搜索的网站,并且我需要记录每次搜索的数据以供以后分析。

我预计最终会在多个服务器之间分配负载,然后每个月我都会下载所有日志并将其导入到一个 mysql 数据库中进行分析。

目前,我一直在考虑将每台服务器设置为 mysql“主服务器”,它将实时更新从属分析服务器,并且本质上也充当备份。

但我的目标是效率。显然,mysql 复制的好处是我始终可以集中使用日志,而不必每月在每个服务器上导入和重置日志文件。

如果登录一个明文文件,然后每个月转储这个日志文件并集中导入到 mysql 中,效率会高多少?明文转储是否比 mysql 更高效/更快?

感谢您的想法!

I am creating a site which will make lots of searches and I need to log data about every search that is made for later analysis.

I anticipate ultimately having load distributed between a number of servers, then each month I will download and import all logs into a single mysql database at my end for analysis.

At the moment I've been looking at setting every server up as a mysql 'master' which will live update the slave analysis server and essentially also act as a backup.

However I'm aiming for efficiency. Obviously the benefits of mysql replication are that I always have logs centrally available and don't have to import and reset log files on each server every month.

How much more efficient would it be to log in a plaintext file and just dump this logfile every month and import into mysql centrally? Is a plaintext dump much, if any, more efficient/faster than mysql?

Thanks for your thoughts!

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

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

发布评论

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

评论(1

温柔嚣张 2024-10-09 16:10:49

数据库的强大功能不仅仅是插入。它们在锁定机制、事务管理、快速搜索、连接池等方面都很强大。

另一方面,如果您通常需要做的就是将一大块数据写入磁盘,那么数据库将是一个巨大的开销。

鉴于上述情况,由于您只想整个月都写东西,我建议您使用日志,并且每月一次 - 获取日志,将它们合并在一起并分析它们。然后,您可以决定是否要将它们全部合并到数据库中(如果它有意义并为您提供一些附加值),或者您只想将文本合并在一起。

顺便说一句,您可能希望将 INSERT 语句保存到此日志中,然后将其用作脚本将所有内容加载到数据库中。考虑一下:-)

Databases are strong for doing more than inserts. They are strong for locking mechanisms, transaction management, fast searches, connections pooling, and the list goes on.

On the other hand, if all you need to do in general is writing a chunk of data to the disk, a database would be a huge overhead.

Given the above, and since you only want to write stuff all month long, I would recommend you use logs, and once a month - take the logs, merge them together and analyze them. You could then decide if you want to merge all of them into a database (if it makes sense and gives you some added value), or you just want to merge the text together.

BTW, you may want to save the INSERT statements into this log, and then use it as a script to load everything into the database. Give it a thought :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文