# Ngx\_drizzle: make nginx talk directly to mysql, drizzle, and sqlite3 	by libdrizzle

**URL:** <https://www.ruby-forum.com/t/ngx-drizzle-make-nginx-talk-directly-to-mysql-drizzle-and-sqlite3-by-libdrizzle/180911>\
**Category:** NGINX\
**Created:** [December 31, 2009, 12:10pm UTC](https://www.ruby-forum.com/t/ngx-drizzle-make-nginx-talk-directly-to-mysql-drizzle-and-sqlite3-by-libdrizzle/180911 "2009-12-31T12:10:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![agentzh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@agentzh](https://www.ruby-forum.com/u/agentzh)\
**Post date:** [December 31, 2009, 12:10pm UTC](https://www.ruby-forum.com/t/ngx-drizzle-make-nginx-talk-directly-to-mysql-drizzle-and-sqlite3-by-libdrizzle/180911/1 "2009-12-31T12:10:22Z")

</div>

Hi, guys!

This is the last day in 2009 and I’m too impatient to hold the first  
release (version v0.0.1) of our ngx\_drizzle module, an upstream module  
that talks directly to RDBMS backends like mysql, drizzle, and the  
drizzle server shipped with libdrizzle for sqlite3.

This module is initially started by my friend and colleague,  
chaoslawful. His Chinese name is ÍõÏþÕÜ 🙂 He did the initial (most  
difficult) work all in his own time 🙂 I also shamelessly borrowed a  
lot of code from Igor’s ngx\_http\_upstream.c and  
ngx\_http\_memcached\_module.c in the nginx 0.8.30 core, as well as Maxim  
Dounin’s excellent upstream\_keepalive module. These parts of code are  
copyrighted by these authors, respectively.

This module is still at its very early phase of development and  
considered highly experimental. But you’re encouraged to test it out  
on your side and report any quirks that you experience 🙂

Here’s some sample configurations:

```
http {
    ...

    upstream cluster {
        # simple round-robin
        drizzle_server 127.0.0.1:3306 dbname=test
             password=some_pass user=monty protocol=mysql;
        drizzle_server 127.0.0.1:1234 dbname=test2
             password=pass user=bob protocol=drizzle;
    }

    upstream backend {
        drizzle_server 127.0.0.1:3306 dbname=test
             password=some_pass user=monty protocol=mysql;
    }

    server {
        location /mysql {
            set $my_sql 'select * from cats';
            drizzle_query $my_sql;

            drizzle_pass backend;
        }
        ...
    }
}

```

Essentially it provides a very efficient and flexible way for nginx  
internals to access mysql, drizzle, sqlite3, as well as other RDBMS’s  
that support the drizzle protocol or mysql protocol. Also it can serve  
as a direct REST interface to those RDBMS backends.

It also has a builtin per-worker connection pool mechanism borrowed  
from Maxim D.'s upstream\_keepalive module.

```
Here's a sample configuration:

    upstream backend {
        drizzle_server 127.0.0.1:3306 dbname=test
             password=some_pass user=monty protocol=mysql;
        drizzle_keepalive max=100 mode=single overflow=reject;
    }

```

You may wonder why it will be useful for your PHP/Python/Perl/Java  
applications fastcgi’d or proxied by nginx. Well, we’ll work out an  
ngx\_accel\_subrequest module some time in the future to allow these  
backend apps directly issue subrequests by means of the special  
X-Accel-Subrequest header and continuation passing style.

Unlike the current X-Accel-Redirect trick we’re already familiar with,  
X-Accel-Subrequest is more like a function invocation that issues one  
(or multiple parallel subrequests), and eventually _returns_ back when  
the resulting data the subrequest obtains is ready and gives control  
back to your backend apps to go on processing the data.

Sadly this mdoule does not have a wiki page yet, just the source  
repository on GitHub:

```
http://github.com/chaoslawful/drizzle-nginx-module

```

I’ve done some work in the README file there. I promise I’ll work on  
the wiki doc in another day 😉

Release tarballs can be downloaded from the page below

```
http://github.com/chaoslawful/drizzle-nginx-module/downloads

```

I’ve also cc’d the nginx-devel mailing list in hope to get interested  
developers to join this project’s development. **YOU** are always  
welcomed!

Happily, we’ve already got a working framework for integrating  
third-party libraries like libdrizzle and libpq into nginx’s upstream  
system as long as the libraries meet the following prerequisites:

1. It exposes the underlying socket fd.
2. It has a truly non-blocking API for its operations.

libdrizzle and libpq meet these conditions while oracle’s OCI library  
needs some hack for the requirement #1. So, you can expect ngx\_oracle  
and even ngx\_pgsql to be announced here in the next few weeks or so,  
and you’ll see even more! If you’d join the fun, please don’t hesitate  
to drop us a line 🙂

Happy new year!

Enjoy!  
-agentzh

P.S. I was hoping to release v0.0.1 by this Christmas, but missed the  
deadline because I had spent too much time on fixing weird bugs in the  
ngx\_chunkin module 😛

The year 2009 is my first year in the nginx community. Thank you all  
for creating such a live community and thanks Igor for creating nginx  
in the first place 😉 I’m going to do more nginx C hacking in the next  
year! 😃

---

<div class="post-metadata">

**Author:** ![agentzh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@agentzh](https://www.ruby-forum.com/u/agentzh)\
**Post date:** [December 31, 2009, 5:27pm UTC](https://www.ruby-forum.com/t/ngx-drizzle-make-nginx-talk-directly-to-mysql-drizzle-and-sqlite3-by-libdrizzle/180911/2 "2009-12-31T17:27:33Z")

</div>

Looks great! Thanks for sharing!

Happy New Year!

Best regards,  
Piotr S. \< removed\_email\_address@domain.invalid \>

---

<div class="post-metadata">

**Author:** ![agentzh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@agentzh](https://www.ruby-forum.com/u/agentzh)\
**Post date:** [February 4, 2010, 3:57pm UTC](https://www.ruby-forum.com/t/ngx-drizzle-make-nginx-talk-directly-to-mysql-drizzle-and-sqlite3-by-libdrizzle/180911/3 "2010-02-04T15:57:56Z")

</div>

This is really wonderful thing! Thx for you work.

libdrizzle and libpq meet these conditions while oracle’s OCI library  
needs some hack for the requirement #1. So, you can expect ngx\_oracle  
and even ngx\_pgsql to be announced here in the next few weeks or so,  
and you’ll see even more! If you’d join the fun, please don’t hesitate  
to drop us a line 🙂

Maybe this code helps:  
[http://www.total-knowledge.com/progs/mod\_plsql/](http://www.total-knowledge.com/progs/mod_plsql/)  
[http://www.sharemation.com/~dmcmahon/modowa.htm](http://www.sharemation.com/~dmcmahon/modowa.htm)

Here is a two opensource apache modules to run pl/sql database  
procedures via the web.  
Alternative to oracle modplsql, dont know about its licence, guess  
propietary one.

Posted at Nginx Forum:

> **[Re: ngx\_drizzle: make nginx talk directly to mysql, drizzle, and sqlite3 by...](https://forum.nginx.org/read.php?2,35329,50464#msg-50464)**
>
> Hi, guys! This is the last day in 2009 and I'm too impatient to hold the first release (version v0.0.1) of our ngx\_drizzle module, an upstream module that talks directly to RDBMS backends like mysql, drizzle, and the drizzle server shipped with...

---

<div class="post-metadata">

**Author:** ![agentzh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@agentzh](https://www.ruby-forum.com/u/agentzh)\
**Post date:** [February 12, 2010, 2:00pm UTC](https://www.ruby-forum.com/t/ngx-drizzle-make-nginx-talk-directly-to-mysql-drizzle-and-sqlite3-by-libdrizzle/180911/4 "2010-02-12T14:00:35Z")

</div>

Here is one more piece of code, in fact ready module for nginx to work  
with OCI:

> **[Игры в OLTP](https://habr.com/en/articles/69974/)**
>
> В последнее время на Хабре стала популярной тема реализации высокопроизводительных приложений. Решили тоже немножко поэкспериментировать в этом направлении и поделиться текущими результатами наших...

at the end of post.

Posted at Nginx Forum:

> **[Re: ngx\_drizzle: make nginx talk directly to mysql, drizzle, and sqlite3 by...](https://forum.nginx.org/read.php?2,35329,53873#msg-53873)**
>
> Hi, guys! This is the last day in 2009 and I'm too impatient to hold the first release (version v0.0.1) of our ngx\_drizzle module, an upstream module that talks directly to RDBMS backends like mysql, drizzle, and the drizzle server shipped with...

---

<div class="post-metadata">

**Author:** ![agentzh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@agentzh](https://www.ruby-forum.com/u/agentzh)\
**Post date:** [February 12, 2010, 3:37pm UTC](https://www.ruby-forum.com/t/ngx-drizzle-make-nginx-talk-directly-to-mysql-drizzle-and-sqlite3-by-libdrizzle/180911/5 "2010-02-12T15:37:10Z")

</div>

Hello!

On Fri, Feb 12, 2010 at 08:00:10AM -0500, jch wrote:

> Here is one more piece of code, in fact ready module for nginx to work with OCI:  
> [Игры в OLTP / Habr](http://habrahabr.ru/blogs/nginx/69974/)
> 
> at the end of post.

It’s not ready module, it’s prototype which shouldn’t be used in  
production due to simple (and really common for nginx modules from  
unaware authors) reason: the code blocks nginx worker on database  
requests.

See catap’s (Kirill Korinskiy) comments there for details.

Maxim D.

---

<div class="post-metadata">

**Author:** ![agentzh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@agentzh](https://www.ruby-forum.com/u/agentzh)\
**Post date:** [February 13, 2010, 11:29am UTC](https://www.ruby-forum.com/t/ngx-drizzle-make-nginx-talk-directly-to-mysql-drizzle-and-sqlite3-by-libdrizzle/180911/6 "2010-02-13T11:29:05Z")

</div>

On Sat, Feb 13, 2010 at 6:20 PM, agentzh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> We hope to kick ngx\_oracle out of the door in the near future. And any  
> sponsorship will be highly appreciated, because our $department’s  
> business no longer heavily replies on Oracle.

And…we’d like ngx\_oracle to share the same upstream mechanism as our  
ngx\_drizzle, as well as the ngx\_postgres module that Piotr S. will  
probably start to work on in the near future 😉 And we’d also like  
them to emit standard RDS outputs so that the RDS toolchain (including  
ngx\_rds\_json) can work automagically across various RDBMS’s.

Yay for ngx\_dbd or ngx\_databases!

-agentzh

---

<div class="post-metadata">

**Author:** ![agentzh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@agentzh](https://www.ruby-forum.com/u/agentzh)\
**Post date:** [February 13, 2010, 11:20am UTC](https://www.ruby-forum.com/t/ngx-drizzle-make-nginx-talk-directly-to-mysql-drizzle-and-sqlite3-by-libdrizzle/180911/7 "2010-02-13T11:20:53Z")

</div>

On Fri, Feb 12, 2010 at 10:36 PM, Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> It’s not ready module, it’s prototype which shouldn’t be used in  
> production due to simple (and really common for nginx modules from  
> unaware authors) reason: the code blocks nginx worker on database  
> requests.
> 
> See catap’s (Kirill Korinskiy) comments there for details.

We (chaoslawful and I) do have something runnable for ngx\_oracle in  
our private repository. Note that not every part of OCI can be made  
non-blocking; notable exceptions are connection/session creation  
operations. So we’re using internal threads to workaround these  
blocking parts and nginx’s event model for other parts.

We hope to kick ngx\_oracle out of the door in the near future. And any  
sponsorship will be highly appreciated, because our $department’s  
business no longer heavily replies on Oracle.

Cheers,  
-agentzh
