NoSQL MongoDB与Cassandra [英] NoSQL MongoDB vs Cassandra

查看:86
本文介绍了NoSQL MongoDB与Cassandra的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个云平台,我想存储文档和视频文件.

I am developing a cloud platform and I want to Store documents and video files.

第一个概念是将MongoDB用于简单文档和大型视频文件cassandra.但是我已经读过,如果文件大于64 MB,我会遇到cassandra问题.

First concept was to use MongoDB for the simple documents and for large video files cassandra. But i have read that with cassandra i'll have a problem if the file is larger than 64 MB.

另一方面,mongoDB具有GridFS,该文件允许大于100MB的文件.

On the other hand mongoDB has GridFS that allows files larger than 100MB.

我已将mongoDB与Java连接.开始时,数据库为80MB,当我将GridFS的1.80GB视频文件插入MongoDB时,我期望数据库能够捕获1.9GB磁盘空间,但它捕获了6GB .... 3倍于文件大小.

I have connected mongoDB with Java. At start the database was 80MB, when I inserted a 1.80GB video file with GridFS into MongoDB i was expecting the Database to capture something like 1.9GB disk spase, but it captured 6 GB .... 3 times the size of the file.

这是我使用的代码:

MongoClient mongo = new MongoClient("localhost", 27017);
DB db = mongo.getDB("testdb");
DBCollection table = db.getCollection("user");

String newFileName = "Video";

File videoFile = new File("e:\\Magnificent.mp4");
GridFS gfsText = new GridFS(db, "video");
GridFSInputFile gfsFile = gfsText.createFile(videoFile);
gfsFile.setFilename(newFileName);
gfsFile.save();

此外,在运行应用程序并将文件保存到mongodb之后,以下文件将创建到DB文件夹中.请注意文件大小:

Also, after run the application and save the file into mongodb the following files are created into the DB folder. Pease notice the size of the files:

第一个问题是为什么它会捕获这么多磁盘空间?

1st question is why it captures so much disk space ??

第二个问题:是否有可能使用cassandra存储500MB-1GB的视频文件?

2ond question: Is there any chance to use cassandra for storing video files 500MB-1GB ???

谢谢您的建议

推荐答案

广告1: 这是因为文件被拆分为多个块,并创建了2个集合,一个集合用于二进制部分(一个块),另一个集合用于元数据.您可以在MongoDB文档关于GridFS

Ad 1: It's because the files are splited into chunks with 2 collections created, one for the binary part (a chunk) and one for the metadata. You can read way more on the MongoDB documentation about GridFS and about how the storage is actually maintained.

广告2: 是的,有一种方法可以在Cassandra中存储大于64MB的文件.您可以轻松地建立一种机制,将文件拆分为多个块,并将其保留为单独的条目.它将以与MongoDB GridFS实施完全相同的方式工作.而且您不会是第一个-DataStax,一家声称在Cassandra之后的公司,已经在名为Enterprise的商业堆栈中实现了这一功能.您可以在此处了解有关 Cassandra文件系统设计和一些此处的文档. 总体而言,如果您决定构建自己的解决方案,那么它应该相当简单明了-您所需要做的就是将文件拆分并将内容放入多个记录中.

Ad 2: Yes, there is a way to store a file that is way above 64MB in Cassandra. You can easily build a mechanism to split the files into chunks and keep them as a separated entries. That will work in the exactly same way as MongoDB GridFS implementation. And you will not be the first one - DataStax, a company that claims to be "behind" Cassandra, have this already implemented in their commercial stack, called Enterprise. You can read about Cassandra File System Design here and some documentation here. Overall, if you will decide to build your own solution it should be fairly simple and straight forward - all you need to do is just to split the files and put the content in more than one record.

另一方面,哲学问题是为什么".为什么要使用 Database 系统存储如此大的文件?有许多更好的方法来处理该问题,包括类似于Amazon S3或任何其他实施的分布式和复制文件/存储系统,这将使您在许多层次上的生活变得如此轻松.还要考虑一下,它是BLOB的很好替代品...

On the other note the philosophical question is "why". Why would you like to use a Database system to store such a big file? There are so many better ways to handle that, including distributed and replicated file/storage systems similar to Amazon S3 or any other implementation, that will make your life so much easier on so many levels. Consider that as well, as a good replacement to BLOBs...

这篇关于NoSQL MongoDB与Cassandra的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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