Search code examples
javaapache-stormdropwizardcodahale-metrics

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. 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


Solution

  • 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. 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.