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

8307425: Socket input stream read burns CPU cycles with back-to-back poll(0) calls #1341

Closed
wants to merge 1 commit into from
Closed

8307425: Socket input stream read burns CPU cycles with back-to-back poll(0) calls #1341

wants to merge 1 commit into from

Conversation

roy-soumadipta
Copy link
Contributor

@roy-soumadipta roy-soumadipta commented May 10, 2023

Backport 73ac710533a45bf5ba17f308aa49556b877b8bf9 to JDK 17u.

Backporting the fix for https://bugs.openjdk.org/browse/JDK-8307425 merged as part of openjdk/jdk#13798
Almost all the hunks were rejected. DatagramChannelImpl doesn't override park in jdk17, and hence has been left unchanged. Respective hunks for NioSocketImpl and SelChImpl were not cleanly applied due to the difference in how park is implemented for the respective classes between openjdk/jdk17u and openjdk/jdk. In openjdk/jdk in park, current thread is checked to be virtual or not and if that equates to true Poller.poll is used instead of Net.poll.

NioSocketImpl.java in openjdk/jdk17u:

private void park(FileDescriptor fd, int event, long nanos) throws IOException {
        long millis;
        if (nanos == 0) {
            millis = -1;
        } else {
            millis = NANOSECONDS.toMillis(nanos);
        }
        Net.poll(fd, event, millis);
    }

NioSocketImpl.java in openjdk/jdk:

private void park(FileDescriptor fd, int event, long nanos) throws IOException {
        Thread t = Thread.currentThread();
        if (t.isVirtual()) {
            Poller.poll(fdVal(fd), event, nanos, this::isOpen);
            if (t.isInterrupted()) {
                throw new InterruptedIOException();
            }
        } else {
            long millis;
            if (nanos == 0) {
                millis = -1;
            } else {
                millis = NANOSECONDS.toMillis(nanos);
                if (nanos > MILLISECONDS.toNanos(millis)) {
                    // Round up any excess nanos to the nearest millisecond to
                    // avoid parking for less than requested.
                    millis++;
                }
            }
            Net.poll(fd, event, millis);
        }
    }

SelChImpl.java in openjdk/jdk17u:

default void park(int event, long nanos) throws IOException {
        long millis;
        if (nanos <= 0) {
            millis = -1;
        } else {
            millis = NANOSECONDS.toMillis(nanos);
        }
        Net.poll(getFD(), event, millis);
    }

SelChImpl.java in openjdk/jdk17u:

default void park(int event, long nanos) throws IOException {
        if (Thread.currentThread().isVirtual()) {
            Poller.poll(getFDVal(), event, nanos, this::isOpen);
        } else {
            long millis;
            if (nanos <= 0) {
                millis = -1;
            } else {
                millis = NANOSECONDS.toMillis(nanos);
                if (nanos > MILLISECONDS.toNanos(millis)) {
                    // Round up any excess nanos to the nearest millisecond to
                    // avoid parking for less than requested.
                    millis++;
                }
            }
            Net.poll(getFD(), event, millis);
        }
    }

Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8307425: Socket input stream read burns CPU cycles with back-to-back poll(0) calls

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk17u-dev.git pull/1341/head:pull/1341
$ git checkout pull/1341

Update a local copy of the PR:
$ git checkout pull/1341
$ git pull https://git.openjdk.org/jdk17u-dev.git pull/1341/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 1341

View PR using the GUI difftool:
$ git pr show -t 1341

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk17u-dev/pull/1341.diff

Webrev

Link to Webrev Comment

@bridgekeeper bridgekeeper bot added the oca Needs verification of OCA signatory status label May 10, 2023
@bridgekeeper
Copy link

bridgekeeper bot commented May 10, 2023

Hi @roy-soumadipta, welcome to this OpenJDK project and thanks for contributing!

We do not recognize you as Contributor and need to ensure you have signed the Oracle Contributor Agreement (OCA). If you have not signed the OCA, please follow the instructions. Please fill in your GitHub username in the "Username" field of the application. Once you have signed the OCA, please let us know by writing /signed in a comment in this pull request.

If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please use "Add GitHub user roy-soumadipta" as summary for the issue.

If you are contributing this work on behalf of your employer and your employer has signed the OCA, please let us know by writing /covered in a comment in this pull request.

@openjdk openjdk bot changed the title Backport 73ac710533a45bf5ba17f308aa49556b877b8bf9 8307425: Socket input stream read burns CPU cycles with back-to-back poll(0) calls May 10, 2023
@openjdk
Copy link

openjdk bot commented May 10, 2023

This backport pull request has now been updated with issue from the original commit.

@openjdk openjdk bot added the backport label May 10, 2023
@roy-soumadipta
Copy link
Contributor Author

/covered

@bridgekeeper bridgekeeper bot added the oca-verify Needs verification of OCA signatory status label May 10, 2023
@bridgekeeper
Copy link

bridgekeeper bot commented May 10, 2023

Thank you! Please allow for a few business days to verify that your employer has signed the OCA. Also, please note that pull requests that are pending an OCA check will not usually be evaluated, so your patience is appreciated!

@bridgekeeper bridgekeeper bot removed oca Needs verification of OCA signatory status oca-verify Needs verification of OCA signatory status labels May 10, 2023
@openjdk openjdk bot added the rfr Pull request is ready for review label May 10, 2023
@mlbridge
Copy link

mlbridge bot commented May 10, 2023

Webrevs

Copy link
Contributor

@olivergillespie olivergillespie left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks :)

Copy link
Member

@shipilev shipilev left a comment

Choose a reason for hiding this comment

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

Looks fine to me. Please ask @olivergillespie to tag the issue for maintainer approval.

@openjdk
Copy link

openjdk bot commented May 15, 2023

@roy-soumadipta This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8307425: Socket input stream read burns CPU cycles with back-to-back poll(0) calls

Reviewed-by: ogillespie, shade

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 10 new commits pushed to the master branch:

  • bf7ceda: 8282201: Consider removal of expiry check in VerifyCACerts.java test
  • 398da7e: 8305088: SIGSEGV in Method::is_method_handle_intrinsic
  • 1970b63: 8304054: Linux: NullPointerException from FontConfiguration.getVersion in case no fonts are installed
  • 5b29c6e: 8304867: Explicitly disable dtrace for ppc builds
  • d5a2309: 8297587: Upgrade JLine to 3.22.0
  • 8656141: 8301216: ForkJoinPool invokeAll() ignores timeout
  • 3f52961: 8296934: Write a test to verify whether Undecorated Frame can be iconified or not
  • efa1786: 8292206: TestCgroupMetrics.java fails as getMemoryUsage() is lower than expected
  • d4467a7: 8307331: Correctly update line maps when class redefine rewrites bytecodes
  • b9eca2d: 8305993: Add handleSocketErrorWithMessage to extend nio Net.c exception message

Please see this link for an up-to-date comparison between the source branch of this pull request and the master branch.
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@shipilev) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label May 15, 2023
@roy-soumadipta
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label May 15, 2023
@openjdk
Copy link

openjdk bot commented May 15, 2023

@roy-soumadipta
Your change (at version 462ed18) is now ready to be sponsored by a Committer.

@RealCLanger
Copy link
Contributor

/integrate

You should have waited with /integrate until the backport is approved via JBS label.

@RealCLanger
Copy link
Contributor

And also please enable and run GHA for a basic verification of this fix. Thanks.

@roy-soumadipta
Copy link
Contributor Author

/integrate

You should have waited with /integrate until the backport is approved via JBS label.

Thanks, OpenJDK GHA is now running. Workflows were enabled after the PR was raised and didn't run automatically. Apologies for the early /integrate, was not aware of this.

@RealCLanger
Copy link
Contributor

Thanks. Backport is approved and somebody can sponsor it now.

@shipilev
Copy link
Member

@roy-soumadipta, could you please go to GHA checks and re-schedule the GHA run? I'd like to make sure it is completely green. Then I can sponsor.

@roy-soumadipta
Copy link
Contributor Author

Hi @shipilev,

I tried to re-run the failed jobs quite a few times and the failure seems to be unrelated to the change.

Prepare all required actions
Getting action download info
Download action repository 'actions/download-artifact@v3' (SHA:9bc31d5ccc31df68ecc42ccf4149144866c47d8a)
Run ./.github/actions/get-bundles
Run actions/download-artifact@v3
Starting download for bundles-linux-x64
Error: Unable to find an artifact with the name: bundles-linux-x64
Run actions/download-artifact@v3
Starting download for bundles-linux-x64
Error: Unable to find an artifact with the name: bundles-linux-x64

Is there any suggested course of action for this?

@shipilev
Copy link
Member

Is there any suggested course of action for this?

This is probably a GHA infra failure. I see you have another run in cooking, let's see how that one does.

@roy-soumadipta
Copy link
Contributor Author

@roy-soumadipta, could you please go to GHA checks and re-schedule the GHA run? I'd like to make sure it is completely green. Then I can sponsor.

@shipilev all the checks have passed. The PR is now ready to sponsor.

@shipilev
Copy link
Member

Good!

/sponsor

@openjdk
Copy link

openjdk bot commented May 17, 2023

Going to push as commit 7610862.
Since your change was applied there have been 16 commits pushed to the master branch:

  • 1087e3b: 8306996: Open source Swing MenuItem related tests
  • bcb1f86: 8248001: javadoc generates invalid HTML pages whose ftp:// links are broken
  • f655ccd: 8304760: Add 2 Microsoft TLS roots
  • e55bea4: 8299544: Improve performance of CRC32C intrinsics (non-AVX-512) for small inputs
  • e7bac42: 8295974: jni_FatalError and Xcheck:jni warnings should print the native stack when there are no Java frames
  • 093f02a: 8305975: Add TWCA Global Root CA
  • bf7ceda: 8282201: Consider removal of expiry check in VerifyCACerts.java test
  • 398da7e: 8305088: SIGSEGV in Method::is_method_handle_intrinsic
  • 1970b63: 8304054: Linux: NullPointerException from FontConfiguration.getVersion in case no fonts are installed
  • 5b29c6e: 8304867: Explicitly disable dtrace for ppc builds
  • ... and 6 more: https://git.openjdk.org/jdk17u-dev/compare/6a8497437ad11c8afbe7f02390ab5491a9390277...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label May 17, 2023
@openjdk openjdk bot closed this May 17, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels May 17, 2023
@openjdk
Copy link

openjdk bot commented May 17, 2023

@shipilev @roy-soumadipta Pushed as commit 7610862.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@roy-soumadipta roy-soumadipta deleted the backport-JDK-8307425 branch May 17, 2023 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants