2

据我了解,要使应用程序真正实现非阻塞,所有执行 IO 的库(例如数据库驱动程序)都应该知道它们在select循环内运行,并且应该将它们的文件描述符添加到主列表中,以便它们的 IO 可以安排妥当。因此,如果我使用随机驱动程序(例如https://github.com/mauricio/postgresql-async),它将在等待查询完成时阻止其他客户端的所有 HTTP 处理。我应该使用一些特定的 Play(或其他任何东西)感知驱动程序吗?

4

2 回答 2

1

我不知道实现细节,但根据这篇博文,它至少适用于一个人:

http://mauricio.github.io/2013/04/29/async-database-access-with-postgresql-play-scala-and-heroku.html

我认为 Future 实例虽然对应用程序不透明,但当它告诉系统等待套接字和期货的集合时,会将文件描述符移交给 runloop 中的 select() 调用。

于 2014-12-13T06:57:11.060 回答
-1

将您的数据库查询扔到后台线程上,并返回一个 Promise to Play:

http://www.playframework.com/documentation/2.0/ScalaAsync

Scala 2.10 集成了 Akka 的 Futures 实现:

http://doc.akka.io/docs/akka/2.2.1/scala/futures.html#introduction

免责声明 - 我从未使用过 Play ...

于 2013-10-22T03:19:01.480 回答