You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by Anthony Ananich <an...@inpun.com> on 2014/09/15 15:06:11 UTC

Multitenancy

Hi!

=== The Story ===

I use a single CouchDB server with an application in a design doc to
provide cloud solution to a range of customers. Each customer has a
separate database, this way client data is isolated. I use a custom view
server which allow to create design doc with code written in Java.

And here I've got a problem. I found that CouchDB resets the view server
each time it needs to switch from one database to another. And that becomes
a performance hit, but also it causes memory leak because after libraries
are loaded, the memory allocated to compiled code is never freed.

=== What Have We Tried to Do ===

Our idea is to launch a view server instance per a database in order to
isolate each client's code from each other.

So we started to read source code and found that CouchDB reset the state of
view server each time it needs. Here is the link to sourrce code where it
happens:
https://github.com/apache/couchdb/blob/1.6.x/src/couch_mrview/src/couch_mrview_updater.erl#L136

And also we found that there are two implementations of "map_doc":
1)
https://github.com/apache/couchdb/blob/1.6.x/src/couch_mrview/src/couch_mrview_updater.erl#L127
2)
https://github.com/apache/couchdb/blob/1.6.x/src/couchdb/couch_query_servers.erl#L64

That's quite confusing, so we decided to ask developers why is it so.

=== The Questions ===

1) Is there a way to launch several view servers, one per database?
2) If not, can you suggest a way for us to modify sources and allow that?
We are looking for a way that will be compatible with current architecture,
so it will be possible to push these changes to mainstream.

Thanks,
Anthony