The best way to use MongoDB as image DB

573 views
Skip to first unread message

Rik

unread,
Apr 5, 2012, 6:33:57 AM4/5/12
to mongodb-user
I'm looking for the best way to manage a huge set of images that will
serve some website pages.

I would like (if possibile) to implement this infrastructure:

My website is placed in one dedicated server and some pages built in
JSP will contain many images,
for this I would like to provide a separate server (or multiple)
running mongos and storing all the images.

For example:
website server is 172.116.0.1 in JSP page I would like to have
something like <img src=" 172.116.0.2/test.jpg">
where 172.116.0.2 could be an apache server able to pull images from
MongoDB (multiple istance).

But really maybe I'm going in the wrong way, therefore can you advice
which is the best way to use Mongo to have a scalable infrastructure
that can achieve this target?

Thanks to all, in advance.
Rk

Nat

unread,
Apr 5, 2012, 7:00:17 AM4/5/12
to mongod...@googlegroups.com
You can try using mongodb gridfs with nginx.
https://github.com/mdirolf/nginx-gridfs
--
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.

EZ

unread,
Apr 5, 2012, 10:22:16 AM4/5/12
to mongodb-user
I read in some forum that nginx-gridfs project is not maintained
anymore...
Is there any plugin like nginx-gridfs for Apache server?

thanks emi

Gary Murakami

unread,
Apr 9, 2012, 4:29:01 PM4/9/12
to mongodb-user
GridFS is recommended for any bulk data that would normally be stored
in a file, including your use case for images. Note that the metadata
for the image can be stored in the files collection within GridFS if
you want it to be searchable via db queries. It is recommended that
you program directly to the GridFS API, as opposed to the unofficial
and unsupported nginx implementation.

gregorinator

unread,
Apr 9, 2012, 8:13:17 PM4/9/12
to mongod...@googlegroups.com
On Mon, Apr 9, 2012 at 4:29 PM, Gary Murakami <gary.m...@10gen.com> wrote:
> GridFS is recommended for any bulk data that would normally be stored
> in a file, including your use case for images.

Truly spoken! And possibly best for Rk's application. However, I'd
like to remind everyone who might jump to GridFS for every "big
object" solution that regular MongoDB documents can be up to 16Mb in
size, and if your BLOb size isn't going to exceed that, you're better
off using a document collection than using GridFS. Many, if not most,
amateur digital photographs, for example, are smaller than 16Mb, often
much smaller. GridFS is only a last resort when you have data that
exceeds -- or you suspect it may exceed -- the 16Mb limit. 16Mb is a
lot of data, and will serve a lot of needs. Look at your data
realistically before choosing GridFS over a plain old, ho-hum, boring
(but 16Mb big, and much faster) document. :)

In the interest of full disclosure, I have to admit that I didn't
learn any of this through personal experience. I'm paraphrasing from
Kristina Chodorow's great book, _50 Tips and Tricks for MongoDB
Developers_, which I highly, highly recommend.

gs

Gary Murakami

unread,
Apr 11, 2012, 11:03:14 AM4/11/12
to mongodb-user
gregorinator raise the somewhat deeper issue that you should consider
for your application with respect to scaling and performance. For
small data (and small images), storing directly in the document is
recommended. But as data sizes increase, there are some impacts on
performance, as the document must be served in its entirety, with
associated buffer, bandwidth, and latency issues. By default, GridFS
uses 256KB chunks to bound these issues for bulk data.

It is worth examining your image sizes and expected scaling and
performance concerns. If your image sizes are small or in the
ballpark of 256KB, GridFS is just extra overhead. If your image sizes
are significantly larger than 256KB, GridFS may give you scaling and
performance benefits because of the chunk size (bounded unit of
multiplexing in networking terms).

The API is simple enough that should consider crafting scaling and
performance tests for both implementations. Measure, compare the
results, and make your choice.

-Gary

Rik

unread,
Apr 11, 2012, 11:28:35 AM4/11/12
to mongodb-user
gs,
got your point.

really I'm not expecting to have object (images) that will exceed 16
Mbyte,
but my target is to find the fastet way to load an image into one web
page, therefore
I would like to understand if is a good idea to store them in MongoDB
then extract when necessary
by linking into a webpage or using GridFS is faster cause I can link
a static file directly.

Using MongoDb as storage seems to be easier also cause ngix with
Gridfs is not manteined so much,
but really if somebody have done something simililar and can share the
solution will be great.

Rk



On 10 Apr, 02:13, gregorinator <gregorina...@gmail.com> wrote:
> On Mon, Apr 9, 2012 at 4:29 PM, Gary Murakami <gary.murak...@10gen.com> wrote:
> > GridFS is recommended for any bulk data that would normally be stored
> > in a file, including your use case for images.
>
> Truly spoken!  And possiblybestfor Rk's application.  However, I'd
Reply all
Reply to author
Forward
0 new messages