GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Potential for time skew in JFR event time? · Issue #884 · async-profiler/async-profiler

Potential for time skew in JFR event time? #884

New issue
Copy link
New issue
Copy link
Closed
Closed
Potential for time skew in JFR event time?#884
Copy link
Labels
enhancement

Description

@indygreg
indygreg
opened on Feb 2, 2024
Issue body actions

I was looking at the source code of async-profiler and noticed that the TSC time is queried at JFR event record creation time, which occurs towards the end of the sampling signal handler.

The code leading to the writing of the JFR event entails locks, stack walking, calling into JVMTI internals, etc.

It seems to me there is a potential for time jitter and for the JFR event time to lag the actual sample time by a meaningful margin.

Is the approach of waiting to query the time appropriate or should the time be queried closer to interrupt / instruction pointer resolution?

Activity

  1. apangin commented on Feb 4, 2024

    @apangin
    apangin
    on Feb 4, 2024
    Collaborator
    More actions

    Thank you for raising the question.
    Did you observe a real problem with the way how timestamps are recorded, or is it more like an assumption from studying the code?
    I haven't encountered issues with timestamps before, but if there are some, I will be glad to know details.

  2. indygreg commented on Feb 4, 2024

    @indygreg
    indygreg
    on Feb 4, 2024
    Author
    More actions

    I started looking at the source code after noticing potential time skew in data.

    I visualized per-thread CPU samples taken at 977 Hz from a JVM with dozens of active threads and noticed that hot CPU threads were still reported as executing multiple sampling periods after GC pauses purportedly began. You can clearly see these GC pauses across all the threads (CPU samples disappear) but the threads all appear to enter and leave the GC pause at different times. When I saw the visualization - which I later confirmed by looking at the raw JFR events - I immediately thought that's too much jitter: it kinda looks like CPU sample times aren't being recorded properly.

    I'm receptive to other theories. But the approach of not reading the time as close to stack walk initiation didn't sit well with me, so I filed this issue. There are plenty of other potential theories, of course. I'll comment here if I learn anything more.

  3. apangin commented on Feb 4, 2024

    @apangin
    apangin
    on Feb 4, 2024
    Collaborator
    More actions

    Thank you for your input - it's useful.

    I think it's easy to adjust the code to get timestamps earlier - at least, before collecting stack traces. I can make a branch to see if it makes data more accurate.
    Anyway, there are delay possibilities that async-profiler cannot directly affect, e.g., a latency between an event occurs and a signal is delivered.

  4. apangin
    added a commit that references this issue on Feb 6, 2024

    #884: Record event timestamps early

    deec218
  5. apangin commented on Feb 6, 2024

    @apangin
    apangin
    on Feb 6, 2024
    Collaborator
    More actions

    I've committed the fix to record timestamps early.
    Please check if it improves your use case.

  6. apangin
    added
    enhancement
    on Feb 6, 2024
  7. apangin
    closed this as completedon Feb 7, 2024
  8. indygreg commented on Mar 6, 2024

    @indygreg
    indygreg
    on Mar 6, 2024
    Author
    More actions

    Thank you for the code change!

    I've performed limited testing of a build from VCS and the recorded times appear to be a bit better. I looked at the commit and the new timing logic appears reasonable to me.

    But I haven't done very comprehensive testing, so there may still be problems with skew. But I don't suppose there's much we can do about it.

    Reacted by Andrei Pangin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.