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

8294437: java/nio/channels/FileChannel tests slow on Windows #10464

Closed
wants to merge 20 commits into from

Conversation

djelinski
Copy link
Member

@djelinski djelinski commented Sep 28, 2022

Please review this test-only change that improves the execution speed of a few FileChannel tests:

  • Transfer2GPlus, Transfer4GBFile, and TransferTo6GBFile were modified to use sparse files. Their speed is now consistent across platforms, provided that the platform / filesystem supports sparse files.
  • LargeMapTest was rewritten to use sparse files, and to more precisely target the issue it was written to detect. In my tests it still crashed with EXCEPTION_ACCESS_VIOLATION when JDK-8286637 was reverted.
  • MapTest: repetition was removed from testForce method; I'm not sure what issues it was supposed to catch, but at far as I can tell, it was only triggering timeouts, see JDK-8289526, JDK-8224480

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-8294437: java/nio/channels/FileChannel tests slow on Windows

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/10464/head:pull/10464
$ git checkout pull/10464

Update a local copy of the PR:
$ git checkout pull/10464
$ git pull https://git.openjdk.org/jdk pull/10464/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 10464

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/10464.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 28, 2022

👋 Welcome back djelinski! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot changed the title 8294437 8294437: java/nio/channels/FileChannel tests slow on Windows Sep 28, 2022
@openjdk
Copy link

openjdk bot commented Sep 28, 2022

@djelinski The following label will be automatically applied to this pull request:

  • nio

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the nio nio-dev@openjdk.org label Sep 28, 2022
@djelinski djelinski marked this pull request as ready for review September 28, 2022 11:15
@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 28, 2022
@mlbridge
Copy link

mlbridge bot commented Sep 28, 2022

Webrevs

Copy link
Contributor

@AlanBateman AlanBateman left a comment

Choose a reason for hiding this comment

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

Creating the files as sparse files make sense, we probably should have changed these tests a long time ago.

raf.write(b);
return b;
try (FileChannel fc = FileChannel.open(src, StandardOpenOption.CREATE_NEW,
StandardOpenOption.SPARSE, StandardOpenOption.WRITE)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

LargeMapFile uses import static java.nio.file.StandardOpenOption.* which makes it easier to fit the open options on the same line.

ByteBuffer bb;
try (FileChannel fc = FileChannel.open(p, CREATE_NEW, SPARSE, WRITE)) {
fc.position(BASE);
Random r = new Random(System.nanoTime());
Copy link
Contributor

Choose a reason for hiding this comment

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

It might not matter here but we usually use RandomFactory to allow for reproducibility in the event of test failure.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the hint! It shouldn't matter here, but I'll change it.

out.println("Exceptions: OK");
t1 = System.nanoTime();
out.printf("Exceptions: done in %d ns (%d ms) %n",
t1 - t0, TimeUnit.NANOSECONDS.toMillis(t1 - t0));
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you planning to leave all these timestamps in the output? I can't tell if they are left over from your testing or intentional.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I wanted to leave them here; they don't take up much space, and are very useful when trying to figure out why the tests are slow.

@bplb
Copy link
Member

bplb commented Sep 28, 2022

Overall I don’t see any problems aside from the copyright years which I assume you will fix before integrating. It’s good that you removed RandomAccessFile in one place. It might be good to try to remove all java.io uses where possible, e.g., not deleteOnExit(). Also, instead of creating a temporary file and then deleting it, maybe something else could be done. For example, creating a temporary directory and then creating a file with a hard-coded name within it. Or using Random to create a file name and using the REPLACE_EXISTING open option. Another thought would be to add a method createSparseTempFile() or something to lib/util/FileUtils.

@djelinski
Copy link
Member Author

I went with adding FileUtils.createSparseTempFile(); the method implementation is still ugly, but at least it's not visible when looking at the tests.

I added one more modification to Transfer2GPlus; noticed that testToWritableByteChannel doesn't need to write to disk, and modified the code to take advantage of that; it's much faster now.

@AlanBateman
Copy link
Contributor

I went with adding FileUtils.createSparseTempFile(); the method implementation is still ugly, but at least it's not visible when looking at the tests.

I would prefer if the FileChannel tests do not use this. The reason is that these are tests for FileChannel and should not be dependent on test infrastructure that it out of sight. It would be okay for non-FileChannel tests to use of course.

@djelinski
Copy link
Member Author

... should not be dependent on test infrastructure that it out of sight.

would it be okay if I moved the method to, say, FileChannelUtils in FileChannel directory?

WritableByteChannel wbc = Channels.newChannel(os)){

long n;
if ((n = srcCh.transferTo(0, LENGTH, wbc)) < LENGTH)
Copy link
Member

Choose a reason for hiding this comment

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

The contract of FileChannel::transferTo does not guarantee that all bytes are transferred:

An invocation of this method may or may not transfer all of the requested bytes [...].

Copy link
Member Author

Choose a reason for hiding this comment

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

preexisting, and unlikely to change because of Hyrum's law. I can file a ticket to update the docs if you think it makes sense.

Copy link
Member

Choose a reason for hiding this comment

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

No, I think the docs should be left as they are.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ack that. If that's okay with you, I'd rather not change this code here; it was always like that, and I haven't found any related failure reports. The tests continue to pass.

sinkChannel.close();
try (FileChannel sourceChannel = FileChannel.open(source, StandardOpenOption.READ);
FileChannel sinkChannel = FileChannel.open(sink, StandardOpenOption.WRITE)) {
long bytesWritten = sinkChannel.transferFrom(sourceChannel,
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as for FileChannel::transferTo:

An invocation of this method may or may not transfer all of the requested bytes.

@openjdk openjdk bot removed the rfr Pull request is ready for review label Sep 30, 2022
@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 30, 2022
Copy link
Contributor

@AlanBateman AlanBateman left a comment

Choose a reason for hiding this comment

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

I think this version looks okay and probably okay drop the loop from testForce. It's probably best to wait until @bplb gets to see the updated version as he has been doing most of the work in this area recently.

@openjdk
Copy link

openjdk bot commented Sep 30, 2022

@djelinski 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:

8294437: java/nio/channels/FileChannel tests slow on Windows

Reviewed-by: alanb, bpb

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 81 new commits pushed to the master branch:

  • e137f9f: 8293877: Rewrite MineField test
  • 4f44fd6: 8237467: jlink plugin to save the argument files as input to jlink in the output image
  • edfb18a: 8294695: Remove redundant deprecation suppression in ThreadGroup
  • 46633e6: 8294698: Remove unused 'checkedExceptions' param from MethodAccessorGenerator.generateMethod()
  • f2a32d9: 8293691: converting a defined BasicType value to a string should not crash the VM
  • ccc1d31: 8294529: IGV: Highlight the current graphs in the Outline
  • 08a7ecf: 8294671: Remove unused CardValues::last_card
  • 5fe837a: 8294236: [IR Framework] CPU preconditions are overriden by regular preconditions
  • 8e9cfeb: 8294431: jshell reports error on initialisation of static final field of anonymous class
  • 6e8f038: 8294567: IGV: IllegalStateException in search
  • ... and 71 more: https://git.openjdk.org/jdk/compare/dd51f7e0b75d3a16403608d89cd206ac0bedf882...master

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.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Sep 30, 2022
Copy link
Contributor

@AlanBateman AlanBateman left a comment

Choose a reason for hiding this comment

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

Thanks for the update, I don't have any other comments. Will be good to get this change in as these tests are so slow on Windows right now.

throw new RuntimeException("Premature EOF!");
nread += n;
}
// Setup looback connection and echo server
Copy link
Member

@bplb bplb Oct 3, 2022

Choose a reason for hiding this comment

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

"looback" -> "loopback"

@djelinski
Copy link
Member Author

Typo fixed.

Thanks for the reviews!

/integrate

@openjdk
Copy link

openjdk bot commented Oct 3, 2022

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

  • c6e3daa: 8242115: C2 SATB barriers are not safepoint-safe
  • e137f9f: 8293877: Rewrite MineField test
  • 4f44fd6: 8237467: jlink plugin to save the argument files as input to jlink in the output image
  • edfb18a: 8294695: Remove redundant deprecation suppression in ThreadGroup
  • 46633e6: 8294698: Remove unused 'checkedExceptions' param from MethodAccessorGenerator.generateMethod()
  • f2a32d9: 8293691: converting a defined BasicType value to a string should not crash the VM
  • ccc1d31: 8294529: IGV: Highlight the current graphs in the Outline
  • 08a7ecf: 8294671: Remove unused CardValues::last_card
  • 5fe837a: 8294236: [IR Framework] CPU preconditions are overriden by regular preconditions
  • 8e9cfeb: 8294431: jshell reports error on initialisation of static final field of anonymous class
  • ... and 72 more: https://git.openjdk.org/jdk/compare/dd51f7e0b75d3a16403608d89cd206ac0bedf882...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Oct 3, 2022
@openjdk openjdk bot closed this Oct 3, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Oct 3, 2022
@openjdk
Copy link

openjdk bot commented Oct 3, 2022

@djelinski Pushed as commit a4f2078.

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

@djelinski djelinski deleted the filechannel-tests branch October 3, 2022 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated nio nio-dev@openjdk.org
Development

Successfully merging this pull request may close these issues.

3 participants