MicroProfile: @Metered vs. @Timed

MicroProfile Metrics comes with @Metered:

public class MeteredResource {

    @Metered(name = "ping_metered")
    public String ping() {
        return "metered " + System.currentTimeMillis();

and @Timed:

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import org.eclipse.microprofile.metrics.annotation.Timed;

public class TimedResource {

    @Timed(name = "ping_timed")
    public String ping() {
        return "timed " + System.currentTimeMillis();


According to the microprofile specification, the @Metered annotation:

"Denotes a meter, which tracks the frequency of invocations of the annotated object."
with default unit: "per second"

In contrary, the @Timed annotation:

"Denotes a timer, which tracks duration of the annotated object."
with default unit: nanoseconds.

The output after a brief stress test:

    "com.airhacks.metrics.boundary.MeteredResource.ping_metered": {
        "count": 10,
        "fiveMinRate": 2.0,
        "oneMinRate": 2.0,
        "fifteenMinRate": 2.0,
        "meanRate": 1.1044614253525735
    "com.airhacks.metrics.boundary.TimedResource.ping_timed": {
        "fiveMinRate": 1.9355159413581935,
        "max": 202722,
        "count": 20,
        "p50": 7658.0,
        "p95": 202722.0,
        "p98": 202722.0,
        "p75": 8228.0,
        "p99": 202722.0,
        "min": 5852,
        "fifteenMinRate": 1.9780232116334415,
        "meanRate": 0.9988264886468711,
        "mean": 23041.21494920979,
        "p999": 202722.0,
        "oneMinRate": 1.7175127368841634,
        "stddev": 47095.42163982647

The @Timed is useful to track the time spent in methods. Particularly the max attribute is useful to track possible performance problems.

On the other hand, the @Metered annotation exposes frequency / throughput, which can be directly used in stress tests / torture tests as thresholds.

See you at Web, MicroProfile and Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


As the @Timer also contains a meter I never use @Meter for methods decorations.

The percentiles are often more relevant than the max for normal flows.
But you're right max can sometimes denote a perf problem when it is not coming from the first call which often requires some class loading/caching/initialization

Posted by Matthieu Brouillard on March 06, 2019 at 09:33 AM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
...the last 150 posts
...the last 10 comments