如何在大型服务器上存储用户日志最佳实践
根据我的经验,这就是我的想法。
我目前正在将用户和统计类保存到 MongoDb 中,一切正常。
但是我如何保存每个用户生成的日志?
正在考虑使用 LogBack SiftingAppender
并委托日志信息
分离 MongoDb Collections
。就像每个 MongoDb Collection
都有用户的 id。
这样我就不必创建高级 MapReduce 查询,因为日志整齐地堆叠在一起。
或者将 SiftingAppender
与 FileAppender 一起使用,以便每个用户都有一个单独的日志文件。
如果 MongoDB 有 100 万个日志集合,每个日志集合都以用户 ID 命名,那么就会出现问题。 (顺便说一句,是否有可能)
如果所有内容都存储在 MongoDb 中,则 MongoDb 主从复制使得 如果主节点死亡,这很容易。
FileAppender 方法怎么样?感觉日志文件会有很多漏洞 来管理。人们也许可以根据字母表将它们保存在文件夹中。文件夹A 对于名称/id 以 A 开头的用户/id。
还有哪些其他选项可以实现此目的?
From my experience this is what i come up with.
Im currently saving Users and Statistic classes into the MongoDb and everything works grate.
But how do i save the log each user generate?
Was thinking to use the LogBack SiftingAppender
and delegate the log information
to separate MongoDb Collections
. Like every MongoDb Collection
have the id of the user.
That way i don't have to create advanced mapreduce query's since logs are neatly stacked.
Or use SiftingAppender
with a FileAppender so each user have a separate log file.
I there is a problem with this if the MongoDB have one million Log Collections each one named with the User Id. (is it even possible btw)
If everything is stored in the MongoDb the MongoDb master-slave replication makes
it easy if a master node dies.
What about the FileAppender approach. Feels like there will be a hole lot of log files
to administrate. One could maybe save them in folders according to Alphabet. Folder A
for user/id with names/id starting with A.
What are other options to make this work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 1M 集合的 qn 上,数据库的默认命名空间文件为 16MB,它允许大约 24000 个命名空间(12000 个集合 + 它们的 _id 索引)。更多信息在此网站上
您可以使用 --nssize 选项将最大 .ns(命名空间)文件大小设置为 2GB,这将允许大约 3072000 个命名空间。
On your qn of 1M collections, the default namespace file for a db is 16MB which allows about 24000 namespaces (12000 collections + their _id indexes). More info on this website
And you can set maximum .ns (namespace) file size to 2GB with --nssize option, which will allow probably 3072000 namespaces.
利用嵌入式文档,为每个用户提供一个文档,其中包含一系列包含日志文件的嵌入式文档。如果集合变大,您还可以从分片中受益。
Make use of Embedded Documents and have one Document for each user with an array of embedded documents containing log files. You can also benefit from sharding if collections get large.