Skip to content

Consider different mechanism for computing time of exemplar measurements #6403

@jack-berg

Description

@jack-berg

When we offer a measurement to an exemplar reservoir cell, we call Clock.now(), which is resolved inefficiently for java 9+:

  @Override
  public long currentTimeNanos() {
    Instant now = Clock.systemUTC().instant();
    return TimeUnit.SECONDS.toNanos(now.getEpochSecond()) + now.getNano();
  }

For java 8, the implementation is simpler and more efficient:

  /** Returns the number of nanoseconds since the epoch (00:00:00, 01-Jan-1970, GMT). */
  public long currentTimeNanos() {
    return TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis());
  }

As discussed here, this is a factor in reduced performance when exemplars are enabled. Its particularly impactful for explicit bucket histograms, which always take the last value for each cell, and are therefore calling currentTimeNanos() for each and every measurement.

We should consider optimizing the java 9+ or using the simpler (but likely less accurate) java 8 version for java 9+. Perhaps we only use the simpler / less accurate implementation for exemplars, which are less important.

cc @jsuereth

Metadata

Metadata

Assignees

No one assigned

    Labels

    Feature RequestSuggest an idea for this project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions