[Twisted-web] database best practices

tarjei tarjei at nu.no
Wed Nov 26 05:12:43 EST 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi there,
Michał Pasternak wrote:
> Martin Bright wrote:
>>
>> Hi!
>>
>> What is the best way to implement synchronous DB access in a twisted
>> application?
>>
> For newly created software I would use Divmod Axiom. It uses SQLite as a
> backend.
> For already existing databases (in MySQL or PostgreSQL) I would use
> Canonical Storm. It even has a branch for integreation with Twisted,
> which uses separate thread to access database.
Has anyone tested this branch? I'd love to see a smallish usage example.


>> Do I have restructure my code such that everything that depends on
>> results from a database query is in a callback to a deferred object?
>>
> I believe it was Glyph Lefkowitz who once said, that he finds
> asynchronous data access APIs extremely painful (and that's why Divmod
> Axiom has synchronous API). I could not agree more; I think this is also
> a concern for you, that's why you asked this question. Even if using SQL
> with Twisted is not a problem, basing on my experience I would rather
> suggest one of mentioned approaches, than anything else.

AFAIK some of the db interfaces (at least MysqlDB) will not block other
threads when running in one so it makes a lot of sense to throw those
operations into a separate thread.

I usually try to separate out the code doing db operations into threads
to keep the application responsive - instead of just the call to the db
operation. This makes for easier coding but with more code in the thread.

regards,
Tarjei




> 
> -- 
> m
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Twisted-web mailing list
> Twisted-web at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFJLSEbYVRKCnSvzfIRAkX7AKCqg3RB2LAAlaGjbZMPYz8m1jws6QCfRic5
KHX3nnnPr+C6rUdwUqY3isg=
=4Vdg
-----END PGP SIGNATURE-----



More information about the Twisted-web mailing list