Images in documents and memory usage

16 views
Skip to first unread message

Maeldron T.

unread,
Jul 7, 2011, 2:34:52 PM7/7/11
to mongodb-user
Hello,

as a newcomer to MongoDB I would like to migrate my existing apps. I
also want to build new HA websites on this nice database.

After reading the docs I consider storing images in MongoDB. The main
reason would be the easy replicaton and high availability.

After reading a dozen threads about this I am still not sure.

The number of the images are thousands or tens of thousand. They are
uploaded by the users.

Every image file is below 4MB. Should I use GridFS? I suppose I
shouldn't. What is the advantage of GridFS compared to simple MongoDB
documents (one document per image) if all the files are below 4MB?

I see that MongoDB likes to eat all the available RAM. On my servers I
have 4GB RAM. The total amount of the images are above 4GB.

I know that linux uses all the available memory for filesystem cache.

All my databases can fit in the RAM without the images.

1.: Suppose that I store the images in the filesystem.

That means that every read from the database will read the RAM. It
will be fast. In this case some of the images will be cached by the OS
and some will be not.

2.: Suppose that I put all the images into MongoDB. Now the whole
database will be larger than the amount of the RAM. Which means that
some database read *not against the images* will be read from disk.
What happens with the indexes? Do they have higher priority to stay in
RAM than other data?

Which solution is the better? I am not sure but I'd guess the first
one. However having all the images replicated with standard filesystem
is a big pain.

ps: I don't plan using sharding. Only replication.

Tony Hannan

unread,
Jul 7, 2011, 6:41:05 PM7/7/11
to mongod...@googlegroups.com
I would keep your images as single documents in MongoDB (no GridFS and no separate file system). You can keep the images in a separate collection to keep them separate (on different disk pages) than the rest of your data. Pages of data (including indexes) accessed frequently will remain in RAM. This is managed by the OS because Mongo uses memory mapped files.


--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.


Keith Branton

unread,
Jul 7, 2011, 8:14:51 PM7/7/11
to mongod...@googlegroups.com
An advantage of GridFS is that it supports streaming . In my application that means that threads serving images don't need to grab as much heap to do their work. This can be quite significant as you try to maximize web server throughput.
Reply all
Reply to author
Forward
0 new messages