Saving Images in GridFS MongoDB

I am discussing saving images in Mongo GridFS or in the cloud file system. I tend to cloud due to several reasons. The language used is PHP on the Nginx server.

  • Saving images in GridFS increases the size of the database. Therefore, most of the database needs to be in memory, and I will spend more time and money managing servers when it comes to things like shards.

  • Getting the image from GridFS takes longer than the cloud, because I have to a) Request the image using the identifier b) Read the image in memory c) Use the php header to display the image

A cloud would be better because its image URL was directly a cloud.

Are these reasons justified or should I go in a different direction with my thinking?

+4
source share
1 answer

Not quite right.

Saving images in GridFS increases the size of the database. So most of the database needs to be in memory, and I will spend more time / money managing servers when it comes to things like Sharding.

Mongodb gridfs breaks huge files into pieces, and only they will be loaded and maintained (for each fragment) when they are requested. Yes, definitely it will take more memory than the file system. These are all trade-offs when using in-memory data stores.

Getting the image from GridFS takes longer than the cloud, because I need to: a) request an image using the identifier b) read the image in memory c) use the php header to display the image

As I said in the previous paragraph, it will be loaded into memory for the first time. so you won’t have a performance problem, in fact it will be a win since it is served from RAM instead of a disk. But if you are not satisfied yet, I would recommend caching images in nginx. therefore he will not come to mongo after the first.

+4
source

Source: https://habr.com/ru/post/1390067/


All Articles