如何检测scala执行上下文耗尽? [英] How to detect scala executioncontext exhaustion?

查看:88
本文介绍了如何检测scala执行上下文耗尽?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Playframework应用程序有时无法响应,我想在运行时检测到它,并在疲惫的执行上下文中记录当前正在运行的内容的信息.

I'm having problems with my Playframework application not being responsive from time to time and I would like to detect this at runtime + log information on what is currently running on the exhausted execution context.

实施此策略的最佳策略是什么?我考虑过将小的可运行对象发布到执行上下文中,如果它们没有及时执行,我会记录一条警告.这个最大等待时间当然应该是可配置的.例如,主要的Web执行上下文永远不会被阻止超过1秒,但是后台数据库执行上下文可能会允许30秒的阻止.

What would the best strategy for implementing this be? I thought about posting small runnables to the execution contexts and if they don't get executed in time I would log a warning. This max wait time should of course be configurable. Eg the main web execution context should never be blocked for more than 1 sec but a background db execution context might allow 30 sec of blocking.

必须有人做过吗?

相关信息: http://www.playframework.com/documentation/2.2.x/ThreadPools

推荐答案

这是一个很难回答的问题.

That is pretty hard question to answer.

调度员的配置实际上取决于演员的工作类型.

Configuration of dispatchers really depends on the type of work your actors are doing.

也许您应该看看催生期货的演员来做他们的工作.在配置文件中预定义执行上下文并像这样使用它们可能是一个好主意:

Probably you should look at the actors that spawn futures to do their work. It may be a good idea to predefine execution context in the configuration file and use them like this:

implicit val ec : ExecutionContext = context.system.dispatchers.lookup("someDispatcher")

那些演员很可能引起饥饿效应.

those actors are likely to cause the starvation effect.

您想要实现的效果是确保快速处理邮件,并且长时间运行的任务不会影响它们,因此分离是此处的关键.

The effect you want to achieve is to make sure messages are processed quickly and long running task does not affect them so separation is the key thing here.

Typesafe Console 是监视应用程序的一个很好的工具.您可以查看那里的调度程序,发现处理消息的延迟增加了.

A good tool for monitoring your application is the Typesafe Console. You can look at the dispatcher there and see that the latency in handling messages increase.

另一个需要关注的问题是确定使高风险工作如网络I/O的参与者.如果在线程池中发生了一些无法再使用的线程时,它将产生问题.

Another concern is to identify actors that make a high risk work like network I/O. If something happens to the thread making in not available again in the pool it will create problems.

很可能在不尝试线程池大小的情况下,您将不知道什么是最适合您的设置.

It is very likely that without experimenting with the threadpool size you won't know what is the best setting for you.

我从书Effective Akka by Jamie Allen中知道的我写的大多数建议都对我有效. 本书Fixing Starvation中有一节.您可能需要仔细看一下.

Most of those advises I wrote I know from the book Effective Akka by Jamie Allen and they seem to be working quite well for me. There is a section in this book Fixing Starvation. You may want to look at it closer.

这篇关于如何检测scala执行上下文耗尽?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆