Connections in a web application

56 views
Skip to first unread message

hernan

unread,
Jun 5, 2012, 3:28:36 AM6/5/12
to CouchDB-Python
Hi everybody,
I'm new using NoSQL databases and I'm introducing now in Couch DB. I
wonder if there is some analog strategy like connection pooling when
I've used relational databases (I understand/think that connection
pooling is independent of database model and has to do with client/
server paradigm). Given that, couchdb request/response service works
under http protocol, how real world web applications works? Works
using a pool of http connections? is there some methods/examples in
couchdb-python? Now I'm using couchdbkit in this way:
When I need to query/modify the database:
server = Server()
db = server.get_or_create_db('db_name')
And use the db object
Do I have to close the server connection? I did not see a method.

Thanks in advance,
Best regards
Hernán

Dirkjan Ochtman

unread,
Jun 5, 2012, 4:00:08 AM6/5/12
to couchdb...@googlegroups.com
On Tue, Jun 5, 2012 at 9:28 AM, hernan <hbe...@gmail.com> wrote:
> I'm new using NoSQL databases and I'm introducing now in Couch DB. I
> wonder if there is some analog strategy like connection pooling when
> I've used relational databases (I understand/think that connection
> pooling is independent of database model and has to do with client/
> server paradigm). Given that, couchdb request/response service works
> under http protocol, how real world web applications works? Works
> using a pool of http connections? is there some methods/examples in
> couchdb-python? Now I'm using couchdbkit in this way:

Recent versions of couchdb-python automatically use a connection pool.
You don't have to close any connections manually.

Cheers,

Dirkjan

Alexander Shorin

unread,
Jun 5, 2012, 4:01:30 AM6/5/12
to couchdb...@googlegroups.com
Hi!

Actually, there is connection pool in couchdb-python [1] already, but
you dont have to keep him in mind and work with it directly - it
already tries to do all job that you need. Connections are stored by
(scheme, host) key, so you shouldn't be able to create thousands
connections to single couchdb server. All connections are relied on
`autoopen` option, so Session object could use old connections many
times without need to recreate them. Connections are closed when
response data was received.

Summarizing, you don't have to work on such low level with
couchdb-python - just relax, open database, run views and fetch docs(:


[1] http://code.google.com/p/couchdb-python/source/browse/couchdb/http.py#411

--
,,,^..^,,,
> --
> You received this message because you are subscribed to the Google Groups "CouchDB-Python" group.
> To post to this group, send email to couchdb...@googlegroups.com.
> To unsubscribe from this group, send email to couchdb-pytho...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/couchdb-python?hl=en.
>

hernan

unread,
Jun 6, 2012, 1:41:08 PM6/6/12
to CouchDB-Python
Dirkjan Ochtman and Alexander Shorin: Thank you for your response!

I've seen http.py and client.py.

I understand looking in Server, Resource and Session classes, that
when a program executes:
server = Server()
then a new http connection (session) is established only if necessary
(using Resource and Session objects).

Is it correct?

Thanks

Regards,
Hernán

On Jun 5, 5:01 am, Alexander Shorin <kxe...@gmail.com> wrote:
> Hi!
>
> Actually, there is connection pool in couchdb-python [1] already, but
> you dont have to keep him in mind and work with it directly - it
> already tries to do all job that you need. Connections are stored by
> (scheme, host) key, so you shouldn't be able to create thousands
> connections to single couchdb server. All connections are relied on
> `autoopen` option,  so Session object could use old connections many
> times without need to recreate them. Connections are closed when
> response data was received.
>
> Summarizing, you don't have to work on such low level with
> couchdb-python - just relax, open database, run views and fetch docs(:
>
> [1]http://code.google.com/p/couchdb-python/source/browse/couchdb/http.py...

Alexander Shorin

unread,
Jun 6, 2012, 2:12:07 PM6/6/12
to couchdb...@googlegroups.com
On Wed, Jun 6, 2012 at 9:41 PM, hernan <hbe...@gmail.com> wrote:
> Dirkjan Ochtman and Alexander Shorin: Thank you for your response!
>
> I've seen http.py and client.py.
>
> I understand looking in Server, Resource and Session classes, that
> when a program executes:
> server = Server()
> then a new http connection (session) is established only if necessary
> (using Resource and Session objects).
>
> Is it correct?

No Session nor Resource initialization establish any HTTP connections.
Any connections are opens only when couchdb-python need send request
to CouchDB or fetch any data from it. That's true also for Server and
Database classes - on their initialization they don't need any
information from CouchDB.
But if you try to get database using Server dict-like interface[1]:
>>> server[dbname]
couchdb-python will send HEAD request to be sure, that requested
database even exists.

[1] http://code.google.com/p/couchdb-python/source/browse/couchdb/client.py#127


>
> Thanks
>
> Regards,
> Hernán
>

--
,,,^..^,,,
Reply all
Reply to author
Forward
0 new messages