Motor——一個非同步MongoDB驅動器

jieforest發表於2012-07-11
[i=s] 本帖最後由 jieforest 於 2012-7-11 20:23 編輯

Tornado is a popular asynchronous Python web server, and MongoDB a widely used non-relational database. Alas, to connect to MongoDB from a Tornado app requires a tradeoff: You can either use PyMongo and give up the advantages of an async web server, or use AsyncMongo, which is non-blocking but lacks key features.

I decided to fill the gap by writing a new async driver called Motor (for "MOngo + TORnado"), and it's reached the public alpha stage. Please try it out and tell me what you think. I'll maintain a homepage for it here, including basic documentation.

Status

Motor is alpha. It is certainly buggy. Its implementation and possibly its API will change in the coming months. I hope you'll help me by reporting bugs, requesting features, and pointing out how it could be better.

Advantages


Two good projects, AsyncMongo and APyMongo, took the straightforward approach to implementing an async MongoDB driver:

they forked PyMongo and rewrote it to use callbacks. But this approach creates a maintenance headache: now every improvement to PyMongo must be manually ported over.

Motor sidesteps the problem. It uses a Gevent-like technique to wrap PyMongo and run it asynchronously, while presenting a classic callback interface to Tornado applications.

This wrapping means Motor reuses all of PyMongo's code and, aside from GridFS support, Motor is already feature-complete. Motor can easily keep up with PyMongo development in the future.


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-735212/,如需轉載,請註明出處,否則將追究法律責任。

相關文章