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

Extensible RetainableByteBufferPool #6322 #6513

Closed

Conversation

gregw
Copy link
Contributor

@gregw gregw commented Jul 12, 2021

Improves on #6332 for #6322

Add a Log2 bucket size imple for ArrayRetainableByteBufferPool

Even if we don't actually add/use the LogBucket class, I think the changes made to make the ArrayRetainableByteBufferPool extensible are good ones to have.

Signed-off-by: Greg Wilkins gregw@webtide.com

lorban added 30 commits June 10, 2021 16:30
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
…Buffer> for encrypted input

Signed-off-by: Ludovic Orban <lorban@bitronix.be>
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
@gregw
Copy link
Contributor Author

gregw commented Jul 13, 2021

@lorban The intention is not to change the existing behaviour. I don't think I have and the CI failure appears to be exactly that.... a CI failure. Will redo the CI tests to see.

But I'm a strong advocate of making this class extensible, even if we don't add the badly named LogBuckets. Unless the class is extensible then we won't ever be able to do any comparisons.
Also I'll include in this making the pool dumpable so that we can see a lot more detail of how the buckets are being used (regardless of allocation). We can then get some dumps from real live servers and do a calculation to see how alternate bucket strategies might affect the pattern we see.

Dumpable

Signed-off-by: Greg Wilkins <gregw@webtide.com>
…f github.com:eclipse/jetty.project into jetty-10.0.x-6322-UseRetainableByteBuffer-LogBuckets

Signed-off-by: Greg Wilkins <gregw@webtide.com>
Sampled Pool

Signed-off-by: Greg Wilkins <gregw@webtide.com>
…yteBuffer' into jetty-10.0.x-6322-UseRetainableByteBuffer-LogBuckets
@gregw gregw requested a review from lorban July 13, 2021 06:42
@gregw gregw marked this pull request as ready for review July 14, 2021 00:52
@gregw
Copy link
Contributor Author

gregw commented Jul 14, 2021

@sbordet @lorban ignoring the LogBucket class itself, I think this PR has some good improvements for:

  • code clarity with the Bucket sub class
  • setting defaults (not duplicated in constructors)
  • dumpability so we can see the distribution in buckets and how buffers are being used
  • extensibility, we can have a LogBuckets if it proves necessary.

maxBucketSize,
maxHeapMemory,
maxDirectMemory,
TypeUtil::log2NextPowerOf2,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not against the power of 2 idea, but perhaps it should be stripped out to maintain, as you say, dumpability and statistics.

@gregw
Copy link
Contributor Author

gregw commented Jul 15, 2021

@sbordet The problem with stripping it out, is that we then have no way of actually testing that the class is really extensible. There were a lot of little assumptions in the code that depended on linear buckets. This PR fixes them, but if we took out LogBuckets, it would be easy for a change to revert to having such a assumptions. I could move LogBuckets to test??? But I really don't see any harm having it available, as it will allow us to test with it in real world deployments.

…yteBuffer' into jetty-10.0.x-6322-UseRetainableByteBuffer-LogBuckets

Updates from review

Signed-off-by: Greg Wilkins <gregw@webtide.com>
@gregw gregw requested a review from sbordet July 19, 2021 03:05
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.

I quite like the idea behind this change. More visibility and extensibility is always good to have. I just think that the buckets should be sampled instead of the pool.

{
private final RetainableByteBufferPool _pool;
private final SampleStatistic _heap = new SampleStatistic();
private final SampleStatistic _direct = new SampleStatistic();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think those two counters are going to be a bit meaningless at the pool layer. IMHO it would be a lot more informative to move them to the Bucket layer, maybe by creating a DumpableBucket class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm good test for extensibility to have SampledBuckets. Will try....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actaully, thinking about it, we can just run with a small factor and then we will effectively get a histogram of the acquired sizes. So maybe this class is not needed after all.

if (maxCapacity <= 0)
maxCapacity = 64 * 1024;
if ((maxCapacity % _factor) != 0 || _factor >= maxCapacity)

final int f = factor <= 0 ? 1024 : factor;
Copy link
Contributor

Choose a reason for hiding this comment

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

Drop final, not necessary.

* uses buckets of buffers that increase in size by a power of
* 2 (eg 1k, 2k, 4k, 8k, etc.).
*/
public static class ExponentialPool extends ArrayRetainableByteBufferPool
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure we want to make this public, as it binds us to maintain it, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want to make it public so we can easily try using it in real deployments.
But as there appears to be resistance to this idea, I'll move to test and we can used the sampled one to gather data to see if ExponentialPool is worthwhile or not.

* @see SampleStatistic
*/
@ManagedObject
class SampledPool implements RetainableByteBufferPool, Dumpable
Copy link
Contributor

Choose a reason for hiding this comment

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

This class is implicitly public, which I don't think it's a good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We want at least this one to be public, so we can run real deployments and capture data about the pool usage. You can't simultaneously argue that ExponentialPool is not justified by any data and then prevent anything that allows the data to be collected!

}

@ManagedAttribute("Heap acquire samples")
public SampleStatistic getHeapSample()
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately SampleStatistic is not manageable, so this JMX exposure results in no data being exposed.
I think we need either more specific getters, or MXBean-ify SampleStatistic which may not be easy.

I would make this class package private in ArrayRBBP for now, and eventually open it up later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it is private, then we can't use it to gather any info.
Anyway, I'm going to look at sampling on buckets rather than on acquire.

capacity = capacity * 2;
}

System.err.println(pool.dump());
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this?

…yteBuffer' into jetty-10.0.x-6322-UseRetainableByteBuffer-LogBuckets

Updates from review

Signed-off-by: Greg Wilkins <gregw@webtide.com>
@gregw gregw requested review from sbordet and lorban July 20, 2021 02:10
@gregw
Copy link
Contributor Author

gregw commented Jul 20, 2021

@lorban @sbordet I have removed SampledPool as we get a reasonable histogram of acquire size by using the normal linear pool and dumping the bucket sizes.
I have added a bit more info into the bucket dumps, but as the sampling is in a race, it may be of marginal value on a server underload, but will be OK if dumped after a load test.

I have moved the ExponentialPool to be an inner class of the test. So process from here is to release this.... ask some real clients do give us some server dumps; analyse the "histograms"; if an ExponentialPool looks like it will work, then re-release with that class public and test.

…yteBuffer' into jetty-10.0.x-6322-UseRetainableByteBuffer-LogBuckets

Updates from review

Signed-off-by: Greg Wilkins <gregw@webtide.com>
@gregw
Copy link
Contributor Author

gregw commented Jul 21, 2021

@lorban @sbordet nudge

@gregw gregw changed the title Improve #6322 log buckets in RetainableByteBufferPool Extensible RetainableByteBufferPool #6322 Jul 21, 2021
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.

Besides the checkstyle failure, LGTM.

}
}

return String.format("%s{capacity=%d,inuse=%d(%d%%),used=%d%%}",
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure the used calculation will report anything meaningful, a more useful metric would be to calculate the mean 'waste' (i.e.: the difference between the requested size and the returned buffer's capacity) but that would require some extra processing.

I think we should leave this as-is and eventually revisit that later on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. We are kind of thwarted by the fact that we have no idea if a buffer is in fill or flush mode.
At least with this metric, it is sampling buffers that have a pointer between 0 and capacity, which is at least a hint of partial usage.

…yteBuffer' into jetty-10.0.x-6322-UseRetainableByteBuffer-LogBuckets

fix checkstyle

Signed-off-by: Greg Wilkins <gregw@webtide.com>
…yteBuffer' into jetty-10.0.x-6322-UseRetainableByteBuffer-LogBuckets

fix checkstyle
removed useless metric

Signed-off-by: Greg Wilkins <gregw@webtide.com>
@gregw
Copy link
Contributor Author

gregw commented Jul 21, 2021

@sbordet nudge!!!

Base automatically changed from jetty-10.0.x-6322-UseRetainableByteBuffer to jetty-10.0.x July 24, 2021 09:19
@gregw
Copy link
Contributor Author

gregw commented Jul 25, 2021

Closed in favour of #6538

@gregw gregw closed this Jul 25, 2021
@joakime joakime deleted the jetty-10.0.x-6322-UseRetainableByteBuffer-LogBuckets branch August 2, 2021 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use RetainableByteBuffer in HttpConnection
3 participants