Skip to content

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

Merged
sbordet merged 3 commits into
jetty-12.0.xfrom
fix/jetty-12.0.x/12706/abbp-jmx
Feb 6, 2025
Merged

sbordet merged 3 commits into
jetty-12.0.xfrom
fix/jetty-12.0.x/12706/abbp-jmx

Conversation

@sbordet

@sbordet sbordet commented Jan 14, 2025

Copy link
Copy Markdown
Contributor
  • 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 <simone.bordet@gmail.com>
@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

@lorban lorban left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@lorban lorban Jan 14, 2025 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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
Copy Markdown
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

wendigo commented Jan 14, 2025

Copy link
Copy Markdown
Contributor

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 <simone.bordet@gmail.com>
@sbordet

sbordet commented Jan 14, 2025

Copy link
Copy Markdown
Contributor Author

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 <simone.bordet@gmail.com>
@wendigo

wendigo commented Jan 14, 2025

Copy link
Copy Markdown
Contributor

@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

sbordet commented Jan 14, 2025

Copy link
Copy Markdown
Contributor Author

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

@sbordet
sbordet merged commit a57b7db into jetty-12.0.x Feb 6, 2025
@sbordet
sbordet deleted the fix/jetty-12.0.x/12706/abbp-jmx branch February 6, 2025 09:44
sbordet added a commit that referenced this pull request Feb 9, 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().
* Updated JMX context attribute for Server in ServerMBean.
  This allow to distinguish ByteBufferPools, Schedulers, etc. among multiple servers and from HttpClient or other components.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

Export ArrayByteBufferPool statistics via JMX

3 participants