Skip to content
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

Fixes #12706 - Export ArrayByteBufferPool statistics via JMX. #12709

Open
wants to merge 3 commits into
base: jetty-12.0.x
Choose a base branch
from

Conversation

sbordet
Copy link
Contributor

@sbordet sbordet commented Jan 14, 2025

  • Exposed bucket statistics as a list of maps.
  • Exposed non-bucket statistic map.
  • Fixed get[Direct|Heap]Memory() and exposed getAvailable[Direct|Heap]Memory().

* Exposed bucket statistics as a list of maps.
* Exposed non-bucket statistic map.
* Fixed get[Direct|Heap]Memory() and exposed getAvailable[Direct|Heap]Memory().

Signed-off-by: Simone Bordet <[email protected]>
@sbordet sbordet requested a review from lorban January 14, 2025 09:26
@sbordet sbordet linked an issue Jan 14, 2025 that may be closed by this pull request
Copy link
Contributor

@lorban lorban left a comment

Choose a reason for hiding this comment

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

There's a minor perf issue in toString, otherwise LGTM.

private Statistics getStatistics()
{
List<Pool.Entry<RetainableByteBuffer>> entries = getPool().stream().toList();
int inUse = (int)entries.stream().filter(Pool.Entry::isInUse).count();
Copy link
Contributor

Choose a reason for hiding this comment

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

Converting to a list is needlessly wasteful, you could directly stream the pool here with:

int inUse = (int)getPool().stream().filter(Pool.Entry::isInUse).count();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I need both the in-use count and the total count, and I would like them to be consistent, that's why I copy the pool to a list.

long pooled = _pooled.longValue();
long acquires = _acquires.longValue();
float hitRatio = acquires == 0 ? Float.NaN : pooled * 100F / acquires;
return new Statistics(getCapacity(), inUse, entries.size(), pooled, acquires, _releases.longValue(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Without the list, you can replace entries.size() with getPool().size() which is as cheap.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But not consistent.

Copy link
Contributor

@lorban lorban Jan 14, 2025

Choose a reason for hiding this comment

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

None of those numbers are strictly consistent with each other at any point in time. Having an extra pair of slightly inconsistent numbers won't change anything in practice. Embrace the race.

private List<Map<String, Object>> getBucketsStatistics(boolean direct)
{
RetainedBucket[] buckets = direct ? _direct : _indirect;
return Arrays.stream(buckets).map(b -> b.getStatistics().toMap()).toList();
Copy link

Choose a reason for hiding this comment

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

can we filter out buckets that don't have allocations at all?

Copy link
Contributor

Choose a reason for hiding this comment

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

That looks like something better left to the caller of this method as we do want to report the buckets that did no allocation.

@wendigo
Copy link

wendigo commented Jan 14, 2025

btw. how can I export statistics for two distinct ArrayByteBufferPools - one used in the client and one in the server? It seems that I'm always getting a single pool exported.

This allow to distinguish ByteBufferPools, Schedulers, etc. among multiple servers and from HttpClient or other components.

Signed-off-by: Simone Bordet <[email protected]>
@sbordet
Copy link
Contributor Author

sbordet commented Jan 14, 2025

btw. how can I export statistics for two distinct ArrayByteBufferPools - one used in the client and one in the server? It seems that I'm always getting a single pool exported.

The pools should have different ObjectNames, so there should be two.

Use MBeanServer.queryNames(new ObjectName("org.eclipse.jetty.io:type=arraybytebufferpool,*"), null) to get the two ObjectNames.

Signed-off-by: Simone Bordet <[email protected]>
@wendigo
Copy link

wendigo commented Jan 14, 2025

@sbordet how these object pools are getting name assigned? I can't find that. I'm always seeing a single buffer pool in the mbean browser:

Screenshot 2025-01-14 at 17 42 37

@sbordet
Copy link
Contributor Author

sbordet commented Jan 14, 2025

It is possible that you are not registering the HttpClient instances in JMX?

See: https://jetty.org/docs/jetty/12/programming-guide/arch/jmx.html#enabling-jmx-support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

Export ArrayByteBufferPool statistics via JMX
3 participants