将 Dispatcher 与 Spray HttpService 结合使用

Use a Dispatcher with Spray HttpService

我的应用程序有一个 API 使用 SprayCan。在应用程序中,任何阻塞代码都有针对每个特定资源的单独调度程序。

是否有必要通过配置自己的 Dispatcher 来保护 API 服务不被应用程序阻止?

通常的做法是将路由器用于 API 服务以处理更大容量的请求?

 class MyService extends Actor with HttpService {...}

 val service = system.actorOf(MyService.props(...).withDispatcher(???))

Is it necessary to protect the API service from being blocked by the application by configuring it with it's own Dispatcher too?

通常不需要。检查 Spray 的默认配置 reference.conf 以查看该调度程序是否满足您的需求。如果没有,请提供自定义的。

Also is it common practice to use a Router for an API service to handle a larger capacity of requests?

通常将请求传递给另一个 Actor 以解锁路由或 运行 作为 Future(可能在单独的线程池中)。在此处查看所有可用选项:.

最后,您不应阻塞路由处理程序,因为它会阻塞您的服务。根据您的描述,您的阻塞代码听起来像是在 Future 或类似的环境中运行。只要它不让路由处理程序等待 result/block 就可以了。