聊天服务器:保存对话日志的最佳方式(最佳方式)是什么 [英] chat server: what's the best(optimized) way to save a conversation log

查看:231
本文介绍了聊天服务器:保存对话日志的最佳方式(最佳方式)是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用java构建一个简单的聊天服务器,用户可以在其中彼此进行私人对话.我想将这些对话保存在服务器级别(而不是在客户端),以便可以将它们作为对话日志服务列出给用户. 我还在软件中将MySQL用作数据库.

I'm building a simple chat server in java , where users can have private conversations with each other. I want to save those conversation at a server level(not on client side) so I can list them to the users as a conversation log service. I'm also using MySQL as a database in my software.

我正在寻找的是一种优化的方式来保存这些对话,并且是一种稍后将其列出的快速方式. 到目前为止,我已经考虑了2种实现方式.

What I'm looking is an optimized way to save those conversations and also a fast way to list them later. So far I've thought on 2 implementations.

  1. 使用MySQL数据库和

  1. using the MySQL database and

a)将对话连续保存为文本,但是问题是某些对话非常大(很多字符),我可能在保存整个对话时遇到了问题

a) save the conversation in a row as a text, but the problem is that some conversations are very huge(lots of chars) and I might have problems saving the entire conversation

b)连续保存对话的每一行,但是当我要列出整个对话时,这种方式会出现速度问题

b) save every line of the conversation in a row, but this way speed problems can appear when I want to list the entire conversation

将每个对话保存在一个单独的文本文件中,但恐怕会出现读/写问题,尤其是当用户(客户端)非常快地编写(发送文本)时.

saving every conversation in a separated text file, but I'm afraid read/write problems can appear, especially when the users(clients) are writing(sending text) very fast.

谢谢

推荐答案

这是一个很大的体系结构问题,您知道.像facebook和twitter这样的公司花费了大量时间和金钱来以健壮的方式解决您的问题.如果您的聊天服务器很简单(如您所写),请使用1.b方式,但要创建一个抽象层(例如saveConversationgetConversation之类).如果将来的速度无法满足您的需求,请考虑使用更高效的表示形式,例如NoSQL数据库(LevelDB或类似的东西).现在不要考虑性能,制作具有良好抽象性和可插拔架构的原型.

This is big architectural problem, you know. Companies like facebook and twitter spent lots of time and money to solve your problem in robust way. If your chat server is simple (As you've written), use 1.b way, but make an abstraction layer (something like saveConversation, getConversation). If in future speed wouldn't satisfy you, think about more efficient representation, like NoSQL database (LevelDB or something like this). Don't think about performance now, make a prototype with good abstraction and pluggable architecture.

这篇关于聊天服务器:保存对话日志的最佳方式(最佳方式)是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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