使用 EventMachine 进行异步数据库访问
我已经开始开发一个简单的 EventMachine 项目,用于接收来自一组网络客户端的数据,将其记录到数据库中,并同时将其发送给另一组不同的客户端。 A客户=> B 客户端的部分是反应器使事情变得非常容易的事情,但数据库访问却没有那么多——至少以非阻塞、事件的方式。我一直在试图找到一个像样的 ORM,它以一种能够与 EventMachine 很好地配合的方式支持异步访问,同时仍然提供我所知道和喜爱的所有 ORM 抽象 - 我希望避免打开一堆套接字并谈论 SQL他们!另外,保持数据库支持的合理分布是可取的(例如,我看过几篇文章解释如何使异步 ActiveRecord 仅与 mysql 一起工作)。
到目前为止,我发现的只是 swift,它看起来应该可以解决问题,但看起来相当不错与 ActiveRecord 和 DataMappers 相比是最小的。
这里还有其他值得追求的道路吗?也许主要的 ORM 巨头之一有一个鲜为人知的异步分支? :P
I've started work on a simple EventMachine project to accept data from a set of network clients, record it into a database, and simultaneously send it out to a different set of clients. The A client's => B client's part is the sort of thing a reactor makes crazy easy, but the database access not so much - at least, in a non-blocking, evented kind of way. I've been trying to find a decent ORM that supports asynchronous access in a fashion that will play nicely with EventMachine, while still providing all the ORM abstractions I know and love - I am hoping to avoid opening a bunch of sockets and talking SQL over them! Also, maintaing a reasonable spread of DB support is desirable (i've seen a couple of articles explaining how to make async ActiveRecord work with mysql only, for instance).
So far, all i've found is swift, which looks like it should do the trick, but seems quite minimal in comparison to your ActiveRecord's and DataMappers.
Are there any other paths worth pursuing here? Perhaps one of the major ORM powerhouses has a little known async branch? :P
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
就我个人而言,我更喜欢直接在基于 EM 的服务器中使用 DB 驱动程序。
原因是需要 EM 服务器的项目类型也需要高性能但处理量相当小。因此,将少量 SQL 语句放在一起通常比正确配置 ORM 并使其与 EM 一起工作更简单。
对于 ORM,尤其是高级 ORM,很容易引入某种瓶颈。此外,EM 仍然不是很普遍,因此如果您尝试在简单的驱动程序上使用 ORM,那么遇到一些奇怪错误的机会会更大。
Mysql2 gem 内置了对异步操作的支持。 Postgresql 我最近没用过所以不确定。
Personally I prefer to use DB drivers directly in EM based servers.
The reason for this is that the type of projects that require EM servers also require high performance but fairly minimal amount of processing. As such, it is often simpler to put together few SQL statements rather than configure ORM properly and have it work with EM.
With ORM, especially advanced ones, it is far too easy to introduce a bottleneck of some kind. Additionaly, EM is still not very widespread so the chances of hitting some weird bug are larger if you try to use ORM over a simple driver.
Mysql2 gem has builtin support for async operations. Postgresql I haven't used lately so not sure.
同意格雷戈里所说,如果您可以使用支持异步操作的本机适配器 - 使用它们。 mysql2 & pg gems 有很好的异步支持。
作为旁注, swift (免责声明:我是合著者)已经进行了一些 api 清理工作这样做是为了简化异步用例。你可能会发现这很方便。
agree as gregory says, if you can use the native adapters that support async operations - use them. mysql2 & pg gems have pretty good async support.
as a side note, swift (disclaimer: i'm a co-author) has had some api cleanup work done to simplify the async use-cases. you may find this handy.