php – 在MongoDB GridFS中存储图像

我正在讨论将图像存储在Mongo GridFS或云文件系统中.由于一些原因,我倾向于云.使用的语言是Nginx服务器上的PHP.

>在GridFS中存储图像会增加数据库的大小.因此,更多的数据库必须在内存中,当涉及到分片等事情时,我将花费更多的时间/金钱来管理服务器.
>从GridFS中检索图像需要比云更长的时间,因为我必须这样做
    a)使用id查询图像
    b)将图像读入内存
    c)使用PHP标头显示图像

云会更好,因为它的图像直接映射到云端.

这些理由是否合理,或者我是否应该按照自己的想法朝着不同的方向前进?

解决方法:

它并非完全正确.

Storing images in the GridFS increases the size of the database.
Therefore more of the database has to be in memory and I will spend
more time/money managing the servers when it comes to things like
sharding.

Mongodb gridfs将巨大的文件拆分成块,只有在请求时才会加载和提供它们(由每个块).是的,它肯定会占用比文件系统更多的内存.这些都是使用内存数据存储时的权衡.

Retrieving the image from GridFS takes longer than cloud because I
have to a) Query the image using the id b) read the image into memory
c) use a PHP header to display the image

正如我在之前的观点中所述,它将在第一时间被加载到内存中.所以你不会遇到太多的性能问题,因为它从RAM而不是磁盘服务,它将是一个增益.但如果你还不满意,我会建议在Nginx中缓存图像.所以它不会在第一个之后来到mongo.

相关文章

MongoTemplate 是Spring Data MongoDB 中的一个核心类,为 S...
笔者今天要分享的是一个项目重构过程中如何将数据库选型由原...
mongodb/mongoTemplate.upsert批量插入更新数据的实现
进入官网下载官网安装点击next勾选同意,点击next点击custom...
头歌 MongoDB实验——数据库基本操作
期末考试复习总结