Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doujutun3207
flink
提交
56cdec7d
F
flink
项目概览
doujutun3207
/
flink
与 Fork 源项目一致
从无法访问的项目Fork
通知
24
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
flink
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
56cdec7d
编写于
6月 15, 2016
作者:
Z
zentol
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[FLINK-4074] Make metric reporters less blocking
This closes #2105
上级
9487fcbf
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
33 addition
and
15 deletion
+33
-15
flink-core/src/main/java/org/apache/flink/metrics/MetricRegistry.java
...rc/main/java/org/apache/flink/metrics/MetricRegistry.java
+24
-15
flink-metric-reporters/flink-metrics-statsd/src/main/java/org/apache/flink/metrics/statsd/StatsDReporter.java
.../java/org/apache/flink/metrics/statsd/StatsDReporter.java
+9
-0
未找到文件。
flink-core/src/main/java/org/apache/flink/metrics/MetricRegistry.java
浏览文件 @
56cdec7d
...
...
@@ -31,6 +31,8 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
java.util.TimerTask
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.TimeUnit
;
/**
...
...
@@ -60,7 +62,7 @@ public class MetricRegistry {
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
MetricRegistry
.
class
);
private
final
MetricReporter
reporter
;
private
final
java
.
util
.
Timer
time
r
;
private
final
ScheduledExecutorService
executo
r
;
private
final
ScopeFormats
scopeFormats
;
...
...
@@ -86,12 +88,11 @@ public class MetricRegistry {
// by default, create JMX metrics
LOG
.
info
(
"No metrics reporter configured, exposing metrics via JMX"
);
this
.
reporter
=
new
JMXReporter
();
this
.
time
r
=
null
;
this
.
executo
r
=
null
;
}
else
{
MetricReporter
reporter
;
java
.
util
.
Timer
timer
;
ScheduledExecutorService
executor
=
null
;
try
{
String
configuredPeriod
=
config
.
getString
(
KEY_METRICS_REPORTER_INTERVAL
,
null
);
TimeUnit
timeunit
=
TimeUnit
.
SECONDS
;
...
...
@@ -117,24 +118,20 @@ public class MetricRegistry {
reporter
.
open
(
reporterConfig
);
if
(
reporter
instanceof
Scheduled
)
{
executor
=
Executors
.
newSingleThreadScheduledExecutor
();
LOG
.
info
(
"Periodically reporting metrics in intervals of {} {}"
,
period
,
timeunit
.
name
());
long
millis
=
timeunit
.
toMillis
(
period
);
timer
=
new
java
.
util
.
Timer
(
"Periodic Metrics Reporter"
,
true
);
timer
.
schedule
(
new
ReporterTask
((
Scheduled
)
reporter
),
millis
,
millis
);
}
else
{
timer
=
null
;
executor
.
scheduleWithFixedDelay
(
new
ReporterTask
((
Scheduled
)
reporter
),
period
,
period
,
timeunit
);
}
}
catch
(
Throwable
t
)
{
reporter
=
new
JMXReporter
();
timer
=
null
;
shutdownExecutor
()
;
LOG
.
error
(
"Could not instantiate custom metrics reporter. Defaulting to JMX metrics export."
,
t
);
}
this
.
reporter
=
reporter
;
this
.
timer
=
time
r
;
this
.
executor
=
executo
r
;
}
}
...
...
@@ -142,9 +139,6 @@ public class MetricRegistry {
* Shuts down this registry and the associated {@link org.apache.flink.metrics.reporter.MetricReporter}.
*/
public
void
shutdown
()
{
if
(
timer
!=
null
)
{
timer
.
cancel
();
}
if
(
reporter
!=
null
)
{
try
{
reporter
.
close
();
...
...
@@ -152,6 +146,21 @@ public class MetricRegistry {
LOG
.
warn
(
"Metrics reporter did not shut down cleanly"
,
t
);
}
}
shutdownExecutor
();
}
private
void
shutdownExecutor
()
{
if
(
executor
!=
null
)
{
executor
.
shutdown
();
try
{
if
(!
executor
.
awaitTermination
(
1
,
TimeUnit
.
SECONDS
))
{
executor
.
shutdownNow
();
}
}
catch
(
InterruptedException
e
)
{
executor
.
shutdownNow
();
}
}
}
public
ScopeFormats
getScopeFormats
()
{
...
...
flink-metric-reporters/flink-metrics-statsd/src/main/java/org/apache/flink/metrics/statsd/StatsDReporter.java
浏览文件 @
56cdec7d
...
...
@@ -53,6 +53,8 @@ public class StatsDReporter extends AbstractReporter implements Scheduled {
// public static final String ARG_CONVERSION_RATE = "rateConversion";
// public static final String ARG_CONVERSION_DURATION = "durationConversion";
private
boolean
closed
=
false
;
private
DatagramSocket
socket
;
private
InetSocketAddress
address
;
...
...
@@ -81,6 +83,7 @@ public class StatsDReporter extends AbstractReporter implements Scheduled {
@Override
public
void
close
()
{
closed
=
true
;
if
(
socket
!=
null
&&
!
socket
.
isClosed
())
{
socket
.
close
();
}
...
...
@@ -95,10 +98,16 @@ public class StatsDReporter extends AbstractReporter implements Scheduled {
// operator creation and shutdown
try
{
for
(
Map
.
Entry
<
Gauge
<?>,
String
>
entry
:
gauges
.
entrySet
())
{
if
(
closed
)
{
return
;
}
reportGauge
(
entry
.
getValue
(),
entry
.
getKey
());
}
for
(
Map
.
Entry
<
Counter
,
String
>
entry
:
counters
.
entrySet
())
{
if
(
closed
)
{
return
;
}
reportCounter
(
entry
.
getValue
(),
entry
.
getKey
());
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录