存储聊天消息和文件的最佳方式 [英] Best way to store chat messages and files

查看:133
本文介绍了存储聊天消息和文件的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道你在数据库中存储聊天消息的想法是什么?



我需要能够将其他东西绑定到他们(如文件,或联系人)和使用数据库是我现在看到的最好的方式。



同样的问题来自于文件,因为它们可以绑定到聊天消息,我必须将它们存储在数据库中。



有数千条消息和文件,我不知道性能下降和数据库大小。


解决方案

我觉得没关系存储数据库上的任何文本信息(名称,消息历史等),只要您正确地构建数据库。我已经为大型网站(每天多公里访问)和电信公司工作,这些公司在长达数百吉字节的数据库上存储有关用户信息(包括流量统计信息),应用程序正常工作。



但是关于像图像和文件这样的二进制信息,最好将它们存储在文件系统上,并将其路径存储在数据库上,因为阅读时会更便宜他们从将数据库进程绑定到读取一个多兆字节文件的磁盘。



正如我所说,重要的是你可以做几件事:


  1. 正确设置信息 - 正确设计数据库非常重要,将其适当地划分成表和表到您的绩效目标的领域因为这将构成您的应用程序和查询的基础。得到这个错误,你的查询将会很慢。


  2. 对与每​​个表相关的表引擎做出正确的决定。这是一个重要的步骤,因为它会极大地影响查询的性能。例如,MyISAM在更新时阻止读取表的访问。对于像社交网络或新闻网站这样的网络应用程序来说,这是一个问题,因为在许多情况下,您的用户基本上必须等待信息更新完成,才能看到生成的页面。


  3. 创建正确的索引 - 对于性能非常重要,特别是对于具有快速增长的大型数据库的应用程序。


  4. 您的查询随着数据的增长而增长,并寻找改进方法 - 您将始终找到必须被删除的瓶颈,这是持续不间断的过程。每个流行的Web应用都必须这样做。



I would like to know what do you think about storing chat messages in a database?

I need to be able to bind other stuff to them (like files, or contacts) and using a database is the best way I see for now.

The same question comes for files, because they can be bound to chat messages, I have to store them in the database too..

With thousands of messages and files I wonder about performance drops and database size.

What do you think considering I'm using PHP with MySQL/Doctrine?

解决方案

I think that it would be OK to store any textual information on the database (names, messages history, etc) provided that you structure your database properly. I have worked for big Web-sites (multi-kilo visits a day) and telecom companies that store information about their users (including their traffic statistics) on the databases that have grown up to hundreds of gigabytes and the applications were working fine.

But regarding binary information like images and files it would be better to store them on the file systems and store only their paths on the database, because it will be cheaper to read them off the disks that to tie a database process to reading a multi-megabyte file.

As I said, it is important that you do several things:

  1. Structure you information properly - it is very important to properly design your database, properly divide it into tables and tables into fields with your performance goals in mind because this will form the basis for your application and queries. Get that wrong and your queries will be slow.

  2. Make proper decisions on table engines pertinent to every table. This is an important step because it will greatly affect the performance of your queries. For example, MyISAM blocks reading access to the table while it is being updated. That will be a problem for a web application like a social networking or a news site because im many situations your users will basically have to wait for a information update to be completed before the will see a generated page.

  3. Create proper indexes - very important for performance, especially for applications with rapidly growing big databases.

  4. Measure performance of your queries as data grows and look for the ways to improve it - you will always find bottlenecks that have to be removed, this is an ongoing non-stop process. Every popular web application has to do it.

这篇关于存储聊天消息和文件的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆