对MySQL中表的最大记录数感到困惑
我正在使用一个网站分析器,它将用于根据 tomcat 的日志分析我们自己的网站。
现在,我们每天将日志从tomcat推送到数据库(MySQL),现在运行良好。然而我发现了一个潜在的致命问题!
到目前为止,我们将日志推送到数据库中的单个表中,但是日志项很快就会增加,尤其是当我们容纳更多用户时,显然单个表无法保存这么多日志项(而且当使用时也会导致性能低下)从large表执行查询操作)。
并且我们使用hibernate作为持久层,日志表中的每一行都映射到应用程序中LogEntry的java对象。
我想过每个月创建一张新表,但是如何让LogEntry映射到多个表并跨表查询?
另外,每个月的日志数可能不一样,一个极端的例子,日志数(表中的记录)大于db中表的最大容量怎么办?
然后我想到设置一个属性来限制hibernate推送日志到数据库时推送日志的最大数量。如果是这样,我不知道告诉休眠创建一个新表并自动跨表查询。
有什么想法吗?
更新Sandy:
我知道你的意思,也就是说表的最大容量是由操作系统决定的,如果我使用分区,最大容量可能会增加,直到达到最大容量我的磁盘。然而,即使我使用分区,似乎我也不需要关心表的最大容量,但如果表保存太多记录,则会导致性能低下。 (顺便说一句,我们还没有决定删除旧日志。)我想到的另一种方法是创建多个具有相同结构的表,但我使用的是hibernate,所有日志插入和查询都将通过hibernate,并且可以实体(POJO)映射到多个表?
I am working with a web site analyser which will be used to analyse our own site according to the log from tomcat.
Now,we push the log from tomcat to the database (MySQL) everyday, it works well now. However I found a potential and fatal problem !
Until now we push the log to a single table in the database,but the log items will increase rapidly soon especially when we hold more users, obviously a single table can not save so many log items (also it will result in a low performance when do the query operation from the large table).
And we use the hibernate as the persistence layer,each row in the log table is mapped to a java object of LogEntry in the application.
I have thought create a new table each month,but how to make the LogEntry map to more than one tables and query across tables?
Also,the log number of each month maybe not the same, an extreme example, how about the log number (records in the table) is greater than the max capacity of the table in db?
Then I thought set a property to limit the max number of log to be pushed when hibernate push log to db. If so I have no idea to tell the hibernate create a new table and query across table automatically.
Any ideas?
Update to Sandy:
I know your meaning, that's to say the max capability of a table is decided by the OS, and if I use the partitioning, the max capability maybe increase until it up to the max capability of my disk. However even if I use the partition, it seems that I do not need to care about the max capability of the table, but if the table hold too many records, it will result in a low performance. (BTW, we have not decide to delete the old logs yet.) Another way I thought is create more than tables with the same structure,but I am using the hibernate,all of the log inserting and querying will through the hibernate, and can the Entity (POJO) mapped to more than one table?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看Hibernate Shards(数据库分片是一种水平分区的方法)。虽然这个su项目不是很活跃并且有一些限制(请参阅文档),但它很稳定且可用(Hibernate Shards已 由 Google 的 Max Ross 贡献,他正在内部使用它)。
监视您的数据库/表并预测所需的维护。
Hibernate 不会自动执行此操作,这将是数据库和分片配置维护的一部分(另请参阅有关 虚拟分片)。
Have a look at Hibernate Shards (database sharding is a method of horizontal partitioning). Although this suproject is not very active and has some limitations (refer to the documentation), it's stable and usable (Hibernate Shards has been contributed by Max Ross from Google who is using it internally).
Monitor your database/tables and anticipate the required maintenance.
Hibernate won't do that automatically, this will be part of the maintenance of the database and of the sharding configuration (see also the section about Virtual Shards).
我认为你应该考虑水平分区。
查看这篇文章通过分区提高数据库性能
更新
I think you should consider horizontal partitioning.
Checkout this article Improving Database Performance with Partitioning
Update