Devin Dixon
Devin Dixon

Reputation: 12363

Storing Images in the MongoDB GridFS

I am debating on storing images in the Mongo GridFS or on an cloud file system. I am leaning towards the cloud because of a few reasons.The language being used is PHP on a Nginx server.

  1. 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.

  2. 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

The cloud would be better because its a url of the image directly to the cloud.

Does those reasons sound valid or should I be going in a different direction with my thinking?

Upvotes: 4

Views: 2001

Answers (1)

RameshVel
RameshVel

Reputation: 65867

Its not entirely true.

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 splits the huge files into the chunks and only they will be loaded and served (by each chunk) when it is requested . Yes definitely it ll take more memory than the file system. These are all the trade offs when using the in memory data stores.

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

As i stated in my previous point, it will be getting loaded into the memory at the first time. so you wont be having much of a performance problem, infact it ll be a gain since it served from RAM instead disk. But if you are not satisfied still, i would recommend to cache the images in nginx. so it wont come to mongo after the first one.

Upvotes: 5

Related Questions