微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

scala – AKKA演员和数据库操作

我试图找出在使用actor系统时如何最好地处理数据库操作.确实数据库操作是阻塞的,而我们试图不阻止在AKKA.

我在主文档中以一种方式来处理,就是在路由器后面创建一个执行器池,可能在一个分离的executeContext上,这将处理数据库访问.

所以我有以下问题:

1 – 数据库工具是否保持连接全部打开?

2 – 如何与许多数据库提供的连接池一起工作?

3 – 我们将两者结合起来,并且每次请求时,DatabaseActors都会从池中请求一个新的连接.如果不是,它是不是一直在打开一个连接一个坏事呢?

4 – 有人可以向我解释一个微妙的东西,使它成为一种避免线程饥饿的方法.例如使用Play或spray,处理请求是一个异步任务,但是如果该任务需要数据库访问,并且向DatabaseActor发送请求,数据库Actor上的块(如果发生)不会引发,一个块在异步任务中,导致可能的线程饿死?

5 – 是否100%确定DB ACID属性确保多次读写的安全性,因此在关系之前发生.

6 – 我使用的语义数据库也称为三重存储,并在我的请求期间大量使用语义推理能力.我还执行大量的写入访问,任何建议,关于池和演员号码或专用执行上下文的调优参数?

最好,

中号

解决方法

1 – Does the databaseActors keep the connection open the all time?

Akka演员是有状态的,即您可以安全地在演员内部存储状态(在这种情况下为DB连接).您可以编写自己的连接管理逻辑或使用数据库驱动程序提供的逻辑.

2 – How does it work together with connection Pooling as offered by many database?

3 – Shall we combine both,and have the DatabaseActors request a new connection from the pool each time they are solicited. If not,isn’t it keeping a connection open at all time a bad thing to do?

你可以组合两者.为游戏中的每个连接设置一个演员.你为什么认为连接活着是坏事?连接池的全部要点不是重用资源(连接),而是每次都不支付创建/销毁它们的价格.

4 – Can someone explain to me the subtle thing that make it an approach that avoid thread starvation. For instance using Play or spray,the handling of a request is an asynchronous task,however if that task need a database access and we send an ask to the DatabaseActor,does the block on the database Actor (if it occur) do not induce,a block in the asynchronous task,leading to possible thread starvation ?

如果您的数据库驱动程序阻塞,那么您最终也必须阻止.推荐的做法是在单独的执行上下文/线程池中执行此块代码.或者如果您有选项选择一个具有反应数据库驱动程序的数据存储区(例如,对于MongoDB的ReactiveMongo),这是完全异步和非阻塞的.

5 – Is it 100% sure the DB ACID property ensures the safety of the multiple read and write and therefore happens before relationship.

我不明白你的意思是什么

6 – I’m using the semantic database also called triple store and make heavy using of semantic reasoning capability during my request. I also perform a lot of write access,any advise,concerning tuning parameters of pooling and actor numbers or dedicated execution context?

你应该使用不同的执行上下文.参数的转换实际上取决于您的硬件配置和软件的其他细节(数据库类型,远程db与嵌入式数据库,请求/秒等).

对于Akka调度员来说,我认为没有一个适合所有的尺寸.这更像艺术.我唯一的建议是确保你的代码中没有任何地方.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐