我的应用程序具有使用SprayCan的API。在应用程序中,任何阻塞代码都为每个特定资源都有一个单独的调度程序。
是否也需要通过使用自己的Dispatcher配置API服务来保护API服务免受应用程序的阻止?
使用Router进行API服务来处理更大容量的请求也是一种惯例吗?
类MyService使用HttpService扩展Actor {...} val service = system.actorOf(MyService.props(...)。withDispatcher(??? ))解决方案
是吗
通常不是通过使用自己的Dispatcher配置API服务来防止应用程序阻止API服务吗?必要。使用Spray检查默认配置附带的 reference.conf ,看看该调度程序是否可以满足您的需求。如果不是这样,请提供自定义的。
另外,将路由器用于API服务的常见做法是处理一个请求容量更大吗? (可能在单独的线程池上)。在此处查看所有可用选项: spray.routing.HttpService调度请求如何? a>。
最后,您不应阻塞路由处理程序,因为它会阻塞您的服务。从您的描述看来,您的阻止代码运行在 Future 或类似版本中。只要它不使路由处理程序等待结果/阻止就可以了。
My application has an API using SprayCan. In the application, any blocking code has a separate dispatcher for each specific resource.
Is it necessary to protect the API service from being blocked by the application by configuring it with it's own Dispatcher too?
Also is it common practice to use a Router for an API service to handle a larger capacity of requests?
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?
Usually not necessary. Check reference.conf that comes as default config with Spray to see if that dispatcher will satisfy your needs. If not, provide a custom one.
Also is it common practice to use a Router for an API service to handle a larger capacity of requests?
Usually requests are handed off to another Actor to unblock the route or ran as Future (possibly on a separate thread pool). See all available options here: How does spray.routing.HttpService dispatch requests?.
Finally, you should not block in the route handler because it will block your service. From your description it sounds like your blocking code runs in a Future or similar. As long as it does not make route handler wait for result/block it's fine.
更多推荐
将Dispatcher与Spray HttpService一起使用
发布评论