How to use mettics for non-blocking methods

87 views
Skip to first unread message

Shehan Perera

unread,
Jan 24, 2018, 2:02:02 AM1/24/18
to metrics-user
Hi,
I like to know a way to get metrics of non-blocking methods.
for example, i used like this,

public void methodRequest(){
  final Timer.Context context=responses.time();
  try{
    doWorks.
  } finally{
    context.stop();
  }
}

Can we do this same for the non-blocking methods?

Erik van Oosten

unread,
Jan 24, 2018, 9:12:16 AM1/24/18
to metric...@googlegroups.com
It depends on what you want to measure.

Do you want to keep track of your asynchronous executions? Then you should use an instrumented execution service (http://metrics.dropwizard.io/4.0.0/apidocs/com/codahale/metrics/InstrumentedExecutorService.html).

Do you want to know how long it takes before the method finishes after you started it? Then you can use the update method on timer. An example looks like this:

public void methodRequest() {
    static long start = System.nanoTime();
    executor.schedule(new Runnable() {
        public void run() {
            // ... do some work ...
            responses.update(System.nanoTime() - start, NANOSECONDS);
        }
    });
}

Do you want to know how long the method is running (excluding waiting time)? Then just move the entire measurement in its original form (using the time method) into the asynchronously run task.

Do you want to measure the wait time before an async job is picked up? Then you should extend the instrumented executor service to also measure wait time (again using the update method).

Kind regards,
    Erik.

--
Erik van Oosten
http://day-to-day-stuff.blogspot.nl/


Op 24-01-18 om 08:02 schreef Shehan Perera:
--
You received this message because you are subscribed to the Google Groups "metrics-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to metrics-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ANIRBAN GHOSH

unread,
May 9, 2018, 11:21:56 AM5/9/18
to metrics-user
Hi Erik van Oosten,

Thank you very much for suggesting instrumented execution service for asynchronous.
I was wondering how we can get the count of success and failure in case of asynchronous execution.

Will be really thankful if you please enlighten on this.

Thanks.

Erik van Oosten

unread,
May 14, 2018, 1:49:02 AM5/14/18
to metric...@googlegroups.com
Hi,

You could take a copy of the instrumented executor service and add the metrics you need. You probably need to check the license before you do so.

Kind regards,
    Erik.


Op 09-05-18 om 17:21 schreef ANIRBAN GHOSH:
Reply all
Reply to author
Forward
0 new messages