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 #9166 - Jetty 12: review/remove ByteBufferPool #9195

Merged
merged 6 commits into from
Jan 27, 2023

Conversation

sbordet
Copy link
Contributor

@sbordet sbordet commented Jan 22, 2023

  • Replaced usages of ByteBufferPool with RetainableByteBufferPool.
  • Removed ByteBufferPool and related classes.
  • Updated all methods such as getBuffer() to getByteBuffer() for consistency.
  • Updated javadocs.

Signed-off-by: Simone Bordet [email protected]

* Replaced usages of ByteBufferPool with RetainableByteBufferPool.
* Removed ByteBufferPool and related classes.

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

sbordet commented Jan 22, 2023

@gregw @lachlan-roberts @lorban these are the major files to review:

oej.client.ContentDecoder
oej.fcgi.generator.*
oej.http.GZIPContentDecoder
oej.io.RetainableByteBuffer
oej.io.RetainableByteBufferPool
oej.server bytebufferpool-quadratic.mod & jetty-bytebufferpool-quadratic.xml
oej.server.GzipRequest
oej.server.AbstractConnector
oej.server.Server
oej.websocket.core.Parser
oej.websocket.core.PerMessageDeflateExtension

Note in particular that I changed the use of Server.getBean(...) for the Scheduler and the RetainableByteBufferPool.

Also changed the ArrayRetainableByteBufferPool.[Exponential|Logarithmic] to Quadratic.

One thing open for discussion is whether the Jetty module bytebufferpool.mod should be renamed to the mouthful retainablebytebufferpool.mod, or perhaps just bufferpool.mod.

{
bufferPool = new ArrayRetainableByteBufferPool()
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a leak tracking RetainableByteBufferPool implementation? why delete TestableLeakTrackingBufferPool then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because it was using the other pool class.

Copy link
Contributor

Choose a reason for hiding this comment

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

But why not just update TestableLeakTrackingBufferPool to be a RetainableByteBufferPool then other tests can potentially use it.


@AfterEach
public void afterEach()
{
bufferPool.assertNoLeaks();
// TODO: restore leak tracking.
// bufferPool.assertNoLeaks();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why have these tests been commented out but you have a different change for the same ee9 test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, restore here too.

Removed Accumulator.acquire(), and updated code to use RetainableByteBufferPool.acquire() instead.

Signed-off-by: Simone Bordet <[email protected]>
@joakime joakime linked an issue Jan 24, 2023 that may be closed by this pull request
@joakime joakime added this to the 12.0.x milestone Jan 24, 2023
@gregw
Copy link
Contributor

gregw commented Jan 24, 2023

Wouldn't it be cool if code like this:

        RetainableByteBuffer retainableByteBuffer = byteBufferPool.acquire(getBufferSize(), isUseDirectByteBuffers());
        ByteBuffer byteBuffer = retainableByteBuffer.getByteBuffer();

        int read;
        try
        {
            BufferUtil.clearToFill(byteBuffer);
            read = read(channel, byteBuffer);
            BufferUtil.flipToFlush(byteBuffer, 0);
        }
        catch (Throwable x)
        {
            retainableByteBuffer.release();
            return failure(x);
        }

could become

        RetainableByteBuffer retainableByteBuffer = byteBufferPool.acquire(getBufferSize(), isUseDirectByteBuffers());

        int read;
        try
        {
            read = retainableByteBuffer.fill(channel);
        }
        catch (Throwable x)
        {
            retainableByteBuffer.release();
            return failure(x);
        }

The RetainableByteBuffer could then be renamed Buffer and have methods like:

  • Buffer.fill(Channel)
  • Buffer.fill(InputStream)
  • Buffer.fill(EndPoint)
  • Buffer.fill(Buffer)
  • Buffer.fill(ByteBuffer)
  • Buffer.fill(byte[],int,int)

But that is a different PR :)

Copy link
Contributor

@gregw gregw left a comment

Choose a reason for hiding this comment

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

First pass.

Generally i think we need to review all our acquires and comment how they are released if it is not obvious.

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 have found one last problem in fcgi, but we should review the places where Greg found that we may leak a buffer.
And we should document the retain/release doctrine somewhere.

Signed-off-by: Simone Bordet <[email protected]>
@sbordet sbordet requested review from gregw and lorban January 26, 2023 10:22
…) and super.onCompleteFailure().

Signed-off-by: Simone Bordet <[email protected]>
@sbordet sbordet merged commit ded18f5 into jetty-12.0.x Jan 27, 2023
@sbordet sbordet deleted the fix/jetty-12-9166-review-bytebufferpool branch January 27, 2023 12:40
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.

Jetty 12: review/remove ByteBufferPool
5 participants