Python Twisted 数据库

发布于 2024-08-30 23:37:49 字数 743 浏览 2 评论 0原文

Twisted 应用程序有一个 API 以可扩展的方式与数据库通信:twisted.enterprise .dbapi

令人困惑的是,选择哪个数据库?

该数据库将有一个 Twisted 应用程序,主要进行插入和更新以及相对较少的选择,然后其他严格只读的客户端直接访问数据库进行选择。

(只读用户不一定选择 Twisted 应用程序插入的数据;它不像数据库被用作消息队列)

我的理解 - 我希望更正/建议 - 是这样的:

  • Postgres 是一个很棒的数据库,但几乎所有的 Python 绑定 - 并且其中有一个令人困惑的迷宫 - 都是废弃
  • 软件org/psycopg/" rel="noreferrer">psycopg2 用于 postgres,但这会在做自己的连接池之类的事情时产生很多噪音;这是否与 Twisted 异步数据库连接池等优雅/有用/透明地共存?
  • SQLLite 对于小事情来说是一个很棒的数据库,但如果以多用户方式使用,它会进行整个数据库锁定,因此性能会降低我设想的使用模式;它还有不同的机制来输入列值?
  • MySQL - 在 Oracle 接管之后,谁愿意现在采用它还是采用一个分支?
  • 那里还有其他东西吗?

There's an API for Twisted apps to talk to a database in a scalable way: 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.

(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)

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
  • There is psycopg2 for postgres, but that makes a lot of noise about doing its own connection-pooling and things; does this co-exist gracefully/usefully/transparently with the Twisted async database connection pooling and such?
  • 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; 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?
  • Is there anything else out there?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

花落人断肠 2024-09-06 23:37:49

可扩展性

twisted.enterprise.adbapi 不一定是用于以可扩展方式与数据库通信的接口。可扩展性是一个需要单独解决的问题。 twisted.enterprise.adbapi 真正声称要做的唯一一件事是让您使用 DB-API 2.0 模块,而不会出现通常意味着的阻塞。

Postgres

是的。这是正确的答案。我不认为所有 Python 绑定都是废弃软件 - 例如,psycopg2 似乎得到了积极维护。事实上,他们只是添加了一些用于异步访问的新绑定,Twisted 最终可能会提供一个接口。

SQLite3 也很酷。您可能希望在您的应用程序中使用 Postgres 或 SQLite3;例如,即使您想针对 Postgres 进行部署,您的单元测试肯定会更适合在 SQLite3 上运行。

其他?

很难知道另一个数据库(也许是非关系数据库)是否比 Postgres 更适合您的应用程序。这在很大程度上取决于您要存储的具体数据以及您需要对其运行的查询。如果您的数据库中存在有趣的关系,Postgres 似乎确实是一个很好的答案。如果您的所有查询看起来都像“SELECT foo, bar FROM baz”,那么可能有一个更简单、性能更高的选项。

Scalability

twisted.enterprise.adbapi isn't necessarily an interface for talking to databases in a scalable way. 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.

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. In fact, they just added some new bindings for async access which Twisted might eventually offer an interface.

SQLite3 is pretty cool too. You might want to make it possible to use either Postgres or SQLite3 in your app; your unit tests will definitely be happier running against SQLite3, for example, even if you want to deploy against Postgres.

Other?

It's hard to know if another database entirely (something non-relational, perhaps) would fit your application better than 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. If all your queries look like "SELECT foo, bar FROM baz" though, there might be a simpler, higher performance option.

摇划花蜜的午后 2024-09-06 23:37:49

有一个 txpostgres 库,它是 twisted.enterprise.dbapi 的替代品,它不是线程池和阻塞 DB IO,而是完全异步的,利用psycopg2 内置异步功能。

我们正在一家大公司的生产中使用它,到目前为止它一直为我们提供良好的服务。此外,它还在积极开发中——我们最近报告的一个错误很快就得到了解决。

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.

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.

美人如玉 2024-09-06 23:37:49

您可以使用twisted 查看nosql 数据库,例如mongodb 或couchdb。
使用基于 nosql 的数据库比使用 mysql 或 postgres 更容易进行横向扩展。

You could look at nosql databases like mongodb or couchdb with twisted.
Scaling out could be rather easier with nosql based databases than with mysql or postgres.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文