What's the recommended way to add gzip support to CouchDB?
Asked Answered
G

1

7

I am trying to setup a CouchDB deployment that needs to have the ability to return gzip'd responses (12mb uncompressed vs 400kb compressed responses). I also need to have SSL support and CORS.

I have used Apache as a reverse proxy before, but I have found that it is unreliable for large replications over poor connections. My preference is to directly serve CouchDB, without any proxy, and we are currently serving SSL from within CouchDB.

I have had success setting up this proxy: http://broken-by.me/tag/accept-encoding-gzip/ which uses node and the connect module (plus cors and compression). It's super simple and works fine. Then, anytime I need a gzip'd response I just send the request to a different port. But this means I lose SSL for these requests. Should I figure out how to add SSL to node? Or do people recommend ngingx as a proxy in front of everything, and then use nginx to do gzip, cors and ssl? What is best practice for production CouchDB deployment?

Glossator answered 28/9, 2016 at 13:21 Comment(2)
I've never seen a 5 year old question as a bounty. I haven't tested it yet but this indicates gzip is supported on all endpoints?Headwaiter
I believe that is only for gzipped requests. In other words, you can post gzip'd content to couchdb, but the response will not be compressed.Glossator
H
0

Use a reverse proxy.

For illustration, install nginx and setup a reverse proxy at port 8080 for port 5984 on your dev box.

This proxy config will get you started

server {

listen 8080;

gzip_min_length     1000;
gzip_buffers        4 8k;
gzip_http_version   1.0;
gzip_types          application/json;
gzip_vary           on;
gzip on;
gzip_proxied any;

location / {

proxy_pass http://127.0.0.1:5984;

}

Use curl to verify responses over about 1000b are compressed, e.g.

curl -D -G -H "Accept-Encoding: gzip" http://user:[email protected]:8080/mydb/_all_docs > out.gz

The response will be compressed. Use an endpoint like _all_docs to be sure the response has more than a 1000b of response data, to confirm.

CouchDB has been getting away from the web server track for some time, as evidenced by the deprecation of the list and show functions for example. CouchDB isn't a web server, and a separation of concerns matters.

Headwaiter answered 30/9, 2021 at 20:35 Comment(3)
I left out nginx conf for SSL, but it's available.Headwaiter
Thanks for the answer, I gave you the bounty. I'm not convinced this nails it though - see the link in my question which talks about how nginx breaks etags when gzip is on. I also seemed to notice some gzip compression coming direct from couchdb - but I am just not sure. Is anybody moving largish chunks of data out of couchdb over http?Glossator
You're welcome. I believe the problem with gzip/ETag has been resolved. I don't have any experience with moving huge attachments, if that is what you mean.Headwaiter

© 2022 - 2024 — McMap. All rights reserved.