# MongoDB Nginx Module

**URL:** <https://www.ruby-forum.com/t/mongodb-nginx-module/191453>\
**Category:** NGINX\
**Created:** [July 12, 2010, 11:22pm UTC](https://www.ruby-forum.com/t/mongodb-nginx-module/191453 "2010-07-12T23:22:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christopher\_Triolo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/91b2a8/32.png) [@Christopher\_Triolo](https://www.ruby-forum.com/u/Christopher_Triolo)\
**Post date:** [July 12, 2010, 11:22pm UTC](https://www.ruby-forum.com/t/mongodb-nginx-module/191453/1 "2010-07-12T23:22:49Z")

</div>

Hi Nginx Mailing List,

I’m in the process of creating a nginx module that serves files from a  
file  
system within mongoDB.

Code is here: [http://github.com/mdirolf/nginx-gridfs](http://github.com/mdirolf/nginx-gridfs)

Basically we embed our C-driver into the module and talk to mongoDB that  
way.  
When the handler is called, it retrieves a file chunk by chunk from  
mongoDB  
and serves it.

I would be very grateful if someone would be able to clear up a few  
things  
for me, as I still haven’t fully wrapped my head around nginx’s  
internals…

Do I save anything by calling ngx\_http\_output\_filter() for each chunk of  
data.  
If the call to mongoDB blocks the worker process, would it be just the  
same  
to call ngx\_http\_output\_filter() once for the whole file?  
Might there be a faster way to accomplish this task?

Thanks in advanced!

Christopher

---

<div class="post-metadata">

**Author:** ![Christopher\_Triolo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/91b2a8/32.png) [@Christopher\_Triolo](https://www.ruby-forum.com/u/Christopher_Triolo)\
**Post date:** [July 13, 2010, 4:44pm UTC](https://www.ruby-forum.com/t/mongodb-nginx-module/191453/2 "2010-07-13T16:44:53Z")

</div>

Hey thanks so much for your response!

I’ll look into that upstream facility. Looks like thats is exactly what  
I  
need.

Thanks again!  
Christopher

---

<div class="post-metadata">

**Author:** ![Christopher\_Triolo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/91b2a8/32.png) [@Christopher\_Triolo](https://www.ruby-forum.com/u/Christopher_Triolo)\
**Post date:** [July 13, 2010, 4:26am UTC](https://www.ruby-forum.com/t/mongodb-nginx-module/191453/3 "2010-07-13T04:26:36Z")

</div>

On Tue, Jul 13, 2010 at 5:22 AM, Christopher Triolo  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m in the process of creating a nginx module that serves files from a file  
> system within mongoDB.  
> Code is here: [GitHub - mdirolf/nginx-gridfs: Nginx module for serving files from MongoDB's GridFS · GitHub](http://github.com/mdirolf/nginx-gridfs)  
> Basically we embed our C-driver into the module and talk to mongoDB that  
> way.

By looking at the source code, it seems to me that it blocks on I/O.  
Sigh.

> When the handler is called, it retrieves a file chunk by chunk from mongoDB  
> and serves it.

Is it possible to make it non-blocking? Like those using the  
ngx\_http\_upstream facility?

> I would be very grateful if someone would be able to clear up a few things  
> for me, as I still haven’t fully wrapped my head around nginx’s internals…  
> Do I save anything by calling ngx\_http\_output\_filter() for each chunk of  
> data.

Actually, it usually makes things slower if the chunk is too small  
(more invocations of the output filter chain and more writev  
syscalls). We observed a significant performance difference in our  
mysql driver module ngx\_drizzle 😉

> If the call to mongoDB blocks the worker process, would it be just the same  
> to call ngx\_http\_output\_filter() once for the whole file?

Not really 🙂

Cheers,  
-agentzh
