处理应用程序级并发 - 我有什么选择?

发布于 2024-12-19 19:03:50 字数 493 浏览 1 评论 0原文

我们有一个薄 Web 层 (Scalatra),它将传入的 HTTP 请求转换为发送到的事件(案例类) 线程绑定事件处理参与者。某些事件包含聚合根的 id,由于各种原因我们需要对其进行变异。应用程序数据总量太大,无法容纳在内存中,因此我们需要在对其进行操作之前,通过其 ID 从数据源中检索聚合。当然,我们不希望事件处理 Actor 被阻塞,因此我们的想法是生成一个新的(基于事件?) Actor 来加载数据、对其进行变异并将其存储回数据中来源。理想情况下,我希望处理应用程序中的并发性,而不是依赖数据源的 ACID 功能。基本上我需要对每个聚合进行序列化/事务访问。

这可以通过演员来实现吗? 最好的方法是什么? 在包含以聚合根 id 为键的参与者的事件处理参与者中保留 ConcurrentHashMap 吗?

或者我们是否必须涉及 STM:s (ScalaSTM/Akka) 或类似的东西?

We have a thin web layer (Scalatra) that translates incoming HTTP requests into events (case classes) that are sent to a thread-bound event processing actor. Some of the events contains the id of an aggregate root that we need to mutate for various reasons. The total amount of application data is too big to fit in memory, so we need to retrieve the aggregate, by its id, from a data source before operating on it. Of course we don't want the event processing actor to block, so the idea is to spawn a new (event-based?) actor that loads the data, mutates it and stores it back into the data source. Ideally I would like to handle concurrency in the application instead of relying on ACID capabilities of the data source. Basically I need serialized/transactional access to each aggregate.

Can this be achieved using actors?
What would be the best approach?
Keeping a ConcurrentHashMap inside the event processing actor containing actors keyed on aggregate root id?

Or do we have to involve STM:s (ScalaSTM/Akka) or something similar?

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

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

发布评论

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

评论(1

半城柳色半声笛 2024-12-26 19:03:50

您可以将您的“聚合根”表示为演员。当您想要改变聚合根时,您可以从请求处理参与者发送一条消息来执行此操作。您还可以拥有一个中间代理参与者,将消息转发给正确的参与者,并通过实例化代表按需数据的参与者并根据需要停止它们来管理聚合根参与者的缓存(按 id )如果您需要协调表示数据的参与者之间的突变,则需要 STM。

You can represent your "aggregate root" as an actor. When you want to mutate the aggregate root you can send a message to do so from your request handling actor. You can also have an intermediary broker actor that forwards messages to the correct actor and manages a cache of aggregate root actors ( by id ) by instantiating an actor representing the data on demand and stoping them as needed. STM will be needed if you need to coordinate a mutation across actors that represent data.

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