简体   繁体   English

如何测量Apache Storm中线程之间的经过时间?

[英]How do I measure the elapsed time between thread in Apache Storm?

I am getting metrics of Storm's bolts and spouts using [codahale-metrics] and sending to Graphite server. 我正在使用[codahale-metrics]获取Storm的螺栓和喷口的度量并将其发送到Graphite服务器。 How do I get the time to send messages between bolts and spouts? 如何获得时间在螺栓和喷嘴之间发送消息? For example. 例如。 this code is just for metrics on each executor: 这段代码仅用于每个执行者的指标:

import com.codahale.metrics.Histogram;
import com.codahale.metrics.Meter;
import com.codahale.metrics.Timer;

public class MqttSensorDetailSpout extends BaseRichSpout {
    private Meter tupleMeter;
    private Timer tupleTimer;
    private Histogram tupleHistogram;
    public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
        this.context = context;
        this.collector = collector;
        this.tupleMeter = context.registerMeter("meterSpout-" + this.topic);
        this.tupleTimer = context.registerTimer("timerSpout-" + this.topic);
        this.tupleHistogram = context.registerHistogram("histogramSpout-" + this.topic);
    }
    public void nextTuple() {
        final Timer.Context timeContext = this.tupleTimer.time();
        this.tupleMeter.mark();
        try {
        …
        } finally {
            timeContext.stop();
        }
    }
}

I want to know the elapsed time to send messages between executors. 我想知道执行者之间发送消息所花费的时间。 How would I implement it? 我将如何实施? Thanks, Felipe 谢谢,费利佩

Storm doesn't timestamp the messages, since we can't know for sure that people have set up NTP or something similar on their servers. Storm不会为消息加时间戳,因为我们无法确定人们是否在服务器上设置了NTP或类似内容。 If you want to know how long it takes to send a tuple from one executor to another, you should add a timestamp manually to the tuples you send. 如果您想知道从一个执行器向另一个执行器发送元组需要多长时间,则应手动向发送的元组添加时间戳。 You can just add it like any other tuple field. 您可以像其他任何元组字段一样添加它。 Then your downstream bolt can read the timestamp of the input tuple, and calculate how long it took to transfer. 然后您的下游螺栓可以读取输入元组的时间戳,并计算传输所需的时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM