简体   繁体   English

Python数据库扭曲

[英]Database for Python Twisted

There's an API for Twisted apps to talk to a database in a scalable way: twisted.enterprise.dbapi Twisted应用程序有一个API可以以可扩展的方式与数据库通信: twisted.enterprise.dbapi

The confusing thing is, which database to pick? 令人困惑的是,要选择哪个数据库?

The database will have a Twisted app that is mostly making inserts and updates and relatively few selects, and then other strictly-read-only clients that are accessing the database directly making selects. 该数据库将有一个Twisted应用程序,主要是进行插入和更新以及相对较少的选择,然后其他严格只读的客户端正在访问数据库直接进行选择。

(The read-only users are not necessarily selecting the data that the Twisted app is inserting; its not as though the database is being used as a message-queue) (只读用户不一定选择Twisted应用程序正在插入的数据;它不像数据库被用作消息队列一样)

My understanding - which I'd like corrected/adviced - is that: 我的理解 - 我想纠正/建议 - 是:

  • Postgres is a great DB, but almost all the Python bindings - and there is a confusing maze of them - are abandonware Postgres是一个很棒的数据库,但是几乎所有的Python绑定 - 以及它们中令人困惑的迷宫 - 都是弃用的
  • There is psycopg2 for postgres, but that makes a lot of noise about doing its own connection-pooling and things; postgres有psycopg2 ,但这对于做自己的连接池和事情会产生很多噪音; does this co-exist gracefully/usefully/transparently with the Twisted async database connection pooling and such? 这是否与Twisted异步数据库连接池优雅/有用/透明地共存?
  • SQLLite is a great database for little things but if used in a multi-user way it does whole-database locking, so performance would suck in the usage pattern I envisage; SQLLite对于小东西来说是一个很棒的数据库,但是如果以多用户方式使用它会进行全数据库锁定,那么性能会影响我设想的使用模式; it also has different mechanisms for typing column values? 它还有不同的键值列表机制?
  • MySQL - after the Oracle takeover, who'd want to adopt it now or adopt a fork? MySQL - 在Oracle收购之后,谁想要现在采用它或采用分支?
  • Is there anything else out there? 还有什么吗?

Scalability 可扩展性

twisted.enterprise.adbapi isn't necessarily an interface for talking to databases in a scalable way. twisted.enterprise.adbapi不一定是以可扩展的方式与数据库通信的接口。 Scalability is a problem you get to solve separately. 可伸缩性是您需要单独解决的问题。 The only thing twisted.enterprise.adbapi really claims to do is let you use DB-API 2.0 modules without the blocking that normally implies. twisted.enterprise.adbapi唯一真正声称要做的就是让你使用DB-API 2.0模块而没有通常所暗示的阻塞。

Postgres Postgres的

Yes. 是。 This is the correct answer. 这是正确的答案。 I don't think all of the Python bindings are abandonware - psycopg2, for example, seems to be actively maintained. 我不认为所有的Python绑定都是弃用软件 - 例如,psycopg2似乎是积极维护的。 In fact, they just added some new bindings for async access which Twisted might eventually offer an interface. 事实上,他们刚刚为异步访问添加了一些新的绑定,Twisted最终可能会提供一个接口。

SQLite3 is pretty cool too. SQLite3也很酷。 You might want to make it possible to use either Postgres or SQLite3 in your app; 您可能希望在您的应用中使用Postgres或SQLite3; your unit tests will definitely be happier running against SQLite3, for example, even if you want to deploy against Postgres. 例如,即使你想针对Postgres进行部署,你的单元测试肯定会更快地运行SQLite3。

Other? 其他?

It's hard to know if another database entirely (something non-relational, perhaps) would fit your application better than Postgres. 很难知道另一个数据库是否完全(非关系型)可能比Postgres更适合您的应用程序。 That depends a lot on the specific data you're going to be storing and the queries you need to run against it. 这在很大程度上取决于您要存储的特定数据以及您需要针对它运行的查询。 If there are interesting relationships in your database, Postgres does seem like a pretty good answer. 如果您的数据库中存在有趣的关系,Postgres确实是一个非常好的答案。 If all your queries look like "SELECT foo, bar FROM baz" though, there might be a simpler, higher performance option. 如果您的所有查询看起来像“SELECT foo,bar FROM baz”,那么可能会有一个更简单,更高性能的选项。

There is the txpostgres library which is a drop in replacement for twisted.enterprise.dbapi , —instead of a thread pool and blocking DB IO, it is fully asynchronous, leveraging the built in async capabilities of psycopg2 . 有一个txpostgres库,它替代twisted.enterprise.dbapi ,而不是线程池和阻塞DB IO,它完全异步,利用psycopg2的内置异步功能。

We are using it in production in a big corporation and it's been serving us very well so far. 我们在大公司的生产中使用它,到目前为止它一直很好地为我们服务。 Also, it's actively developed—a bug we reported recently was solved very quickly. 此外,它已经积极开发 - 我们最近报告的一个错误很快就得到了解决。

You could look at nosql databases like mongodb or couchdb with twisted. 您可以查看nosql数据库,如mongodb或couchdb with twisted。 Scaling out could be rather easier with nosql based databases than with mysql or postgres. 使用基于nosql的数据库比使用mysql或postgres更容易扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM