Skip to content

Implement metrics for external queue #4292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 66 commits into
base: series/3.x
Choose a base branch
from

Conversation

Atharva-Kanherkar
Copy link

@Atharva-Kanherkar Atharva-Kanherkar commented Mar 5, 2025

WorkStealingThreadPool Metrics Implementation

This PR implements metrics for tracking singleton and batch task submissions to the external queue in WorkStealingThreadPool, as in issue #4269 .

Changes Made:

  1. Added Atomic Counters to WorkStealingThreadPool:

    • singletonsSubmittedCount - tracks total singleton task submissions
    • singletonsPresentCount - tracks current singleton tasks in the queue
    • batchesSubmittedCount - tracks total batch task submissions
    • batchesPresentCount - tracks current batch tasks in the queue
  2. Updated Submission Logic:

    • Changed submitToExternalQueue() to increment counters when tasks are added
    • Changed pollTask() to decrement present counters when tasks are polled
  3. Added Accessor Methods:

    • getSingletonsSubmittedCount() - returns total singleton submissions
    • getSingletonsPresentCount() - returns current singletons in queue
    • getBatchesSubmittedCount() - returns total batch submissions
    • getBatchesPresentCount() - returns current batches in queue
    • logQueueMetrics() - Helper for logging all metrics
  4. Added Verification Test:
    I made a test (which i am not sure about, but It did work -->)
    image

    • Submits singleton tasks and verifies the counter increases
    • Triggers batch creation through local queue overflow
    • Verifies both types of metrics track correctly
  • Singleton submissions: Created 10,000 tasks → Counter increased by exactly 10,000 ✓
  • Batch submissions: Generated queue overflow → Counter increased by 2,053 ✓

This might confirm that the implementation works as fine as it should be. The code too compiles without any errors, at least in my terminal :)
The test is included in the PR for reference, showing how to access these metrics from client code.

@Atharva-Kanherkar
Copy link
Author

Hey @armanbilge! Please ignore some of the previous commits as i got myself into a git command hell :p , Anyways, the PR is now ready to review. Please only check the recent commit. It will clearly show what the code I have changed. Thanks :)

@armanbilge armanbilge self-requested a review March 6, 2025 04:34
Copy link
Member

@armanbilge armanbilge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work on this!

May I suggest an alternative approach? I think we should make ScalQueue no longer generic. Internally, it can be backed by queues of AnyRef. Then, we can adjust its API to be:

def offer(a: Runnable, random: ThreadLocalRandom): Unit
def offer(a: Array[Runnable], random: ThreadLocalRandom): Unit

Then, we can keep the counters inside of ScalQueue, and increment the appropriate counters in the specific offer methods.

poll will have to return AnyRef and use isInstanceOf checks to decrement the appropriate counter.

@Atharva-Kanherkar
Copy link
Author

Thanks for your work on this!

May I suggest an alternative approach? I think we should make ScalQueue no longer generic. Internally, it can be backed by queues of AnyRef. Then, we can adjust its API to be:

def offer(a: Runnable, random: ThreadLocalRandom): Unit
def offer(a: Array[Runnable], random: ThreadLocalRandom): Unit

Then, we can keep the counters inside of ScalQueue, and increment the appropriate counters in the specific offer methods.

poll will have to return AnyRef and use isInstanceOf checks to decrement the appropriate counter.

For sure. Give me a day, i will look into it!

@Atharva-Kanherkar
Copy link
Author

Hey @armanbilge :) I have added the requested changes. Please review! If there is anything to fix again, please let me know!

@armanbilge
Copy link
Member

Thanks for making those changes! It looks like the code doesn't compile currently.

@Atharva-Kanherkar
Copy link
Author

Thanks for making those changes! It looks like the code doesn't compile currently.

Yes! I am sorry, I actually slept after pushing the changes and forgot fixing the issues. I will be doing it right away! ~Atharva

@Atharva-Kanherkar
Copy link
Author

@armanbilge Actually there were so many references and inter dependencies of how scalqueue was generic, that is why this happened. It seems like there is a lot of code which is written kept in mind that it is generic. However, Ill fix it soon:)

@Atharva-Kanherkar
Copy link
Author

Update :
image
I guess the code works as we wanted it to work! There are still warnings and formatting issues, which can be fixed promptly, but the functionality is working fine now.

@armanbilge armanbilge self-requested a review March 24, 2025 07:54
@Atharva-Kanherkar
Copy link
Author

Hello @armanbilge ! I have added the changes! Please review :)

@Atharva-Kanherkar Atharva-Kanherkar marked this pull request as ready for review April 8, 2025 20:45
@Atharva-Kanherkar
Copy link
Author

Hey @armanbilge!
Just wanted to follow up on this PR — marked it as ready a couple days ago. No rush at all, but when you get a chance, your review would be super appreciated! 🙌

@Atharva-Kanherkar
Copy link
Author

hey @armanbilge ! do you need anything else from my side! :) happy to help..

@armanbilge armanbilge changed the title Enhancement : Track Singleton vs Batch Tasks in External Queue Metrics Implement metrics for external queue Apr 13, 2025
@armanbilge
Copy link
Member

@djspiewak do you have any performance concerns here, should we run some benchmarks?

@djspiewak
Copy link
Member

I would definitely like to run some benchmarks on this one. I'll review the diff more closely though.

@Atharva-Kanherkar
Copy link
Author

Atharva-Kanherkar commented Apr 20, 2025

Hi @armanbilge @djspiewak! Hope you're doing well. Just wanted to follow up on this—any updates by chance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants