Re: (long) improving async support in psycopg
Manlio Perillo <[email protected]> Wed, 24 Mar 2010 15:16:53 +0100
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
Jan UrbaĆski ha scritto:
> [...]
> Well the big advantage of psycopg2 is that it's using the official C
> library, so it's getting the same fixes as libpq gets updated by the
> upstream project and of course it's faster. So it you'd want to use it
> transparently with eventlet you'll have to write some code anyway... My
> Twisted wrapper needs to deal with quite a few things, so going async
> can never be free IMHO. As you said the way you work with async
> connections is quite different.
>
Some days ago, I wrote a libpq wrapper using ctypes.
http://hg.mperillo.ath.cx/libpq
It is rather low level, but it is not hard to write higher level wrappers.
Of course, the main problem is conversion between PostgreSQL types and
Python types, since it requires some parsing.
One advantage of using the low level libpq API is that you have more
control about what you are doing.
> [...]
> A dbapi interface (thus without the extra `cursor.execute()`
>> parameter) would also enable the async psycopg to be used with
>> existing clients, e.g. SQLAlchemy.
>
> I'm not sure I follow: how would SQLAlchemy use the async API? I think
> the user needs to be aware that he's using the async features, so he
> will do select calls (like Twisted) or will yield control on EAGAIN
> errors from the socket (like eventlet).
>
The idea is that you have a generic "reactor" API, with a simple API like:
waitRead(fd)
waitWrite(fd)
or a more generic:
poll(fd, ...)
Using greenlet, these calls will suspend execution of the current
greenlet until a socket is ready.
On top of this API, you can implement an high level API, like:
readn(fd, n)
read n bytes, blocking current greenlet until all data is read
writen(fd, n)
connect(fd, ...)
and so on.
How the reactor is started is unspecified.
As with Daniele, I, too, am interested in greenlet for use in my WSGI
module for Nginx.
In this case the reactor API is implemented on top of Nginx event module.
> [...]
Regards Manlio
_______________________________________________
Psycopg mailing list
[email protected]
http://lists.initd.org/mailman/listinfo/psycopg