FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: reduce Java 21 Virtual Thread Pinning in IO operations by BenWhitehead · Pull Request #2553 · googleapis/java-storage · GitHub

fix: reduce Java 21 Virtual Thread Pinning in IO operations - #2553

Merged
BenWhitehead merged 2 commits into
mainfrom
java21-reduce-io-pinning
May 30, 2024
Merged

fix: reduce Java 21 Virtual Thread Pinning in IO operations#2553
BenWhitehead merged 2 commits into
mainfrom
java21-reduce-io-pinning

Conversation

Copy link
Copy Markdown
Collaborator

Setup a small workload using virtual threads and turned on pinning detection (-Djdk.tracePinnedThreads=full), and run various methods for uploading and downloading object data.

I then reduced the pinning sights to a minimized list (grep 'monitor' run.log | grep 'com.google.cloud.storage' | sort -u)

    com.google.cloud.storage.BaseStorageReadChannel.read(BaseStorageReadChannel.java:105) <== monitors:1
    com.google.cloud.storage.BlobWriteSessions$WritableByteChannelSessionAdapter.open(BlobWriteSessions.java:46) <== monitors:1
    com.google.cloud.storage.LazyWriteChannel.getSession(LazyWriteChannel.java:59) <== monitors:1
    com.google.cloud.storage.ParallelCompositeUploadWritableByteChannel.close(ParallelCompositeUploadWritableByteChannel.java:268) <== monitors:1
    com.google.cloud.storage.ParallelCompositeUploadWritableByteChannel.write(ParallelCompositeUploadWritableByteChannel.java:178) <== monitors:1
    com.google.cloud.storage.StorageByteChannels$SynchronizedBufferedWritableByteChannel.close(StorageByteChannels.java:119) <== monitors:1
    com.google.cloud.storage.StorageByteChannels$SynchronizedBufferedWritableByteChannel.write(StorageByteChannels.java:109) <== monitors:1
    com.google.cloud.storage.StorageByteChannels$SynchronizedUnbufferedReadableByteChannel.read(StorageByteChannels.java:139) <== monitors:1

To avoid pinning during IO operations, uses of synchronization have been replaced with ReenterantLock. There were a few synchronization sites that were also guarded by an outer operations synchronization, these too have been updated to use ReenterantLock.

We stick with synchronized for init related operations. In the case of creating a WriteChannel, the ability to open depends on the resumable session being created successfully, which requires a network request. Our objects in this area are not written in a top to bottom async friendly way to remove the synchronization at this time. Given these operations are performed at most once per WriteChannel impact is much less drastic compared to write(ByteBuffer) and close().

After this change, I ran the same workload and we are left with only the two following pins detected

    com.google.cloud.storage.BlobWriteSessions$WritableByteChannelSessionAdapter.open(BlobWriteSessions.java:46) <== monitors:1
    com.google.cloud.storage.LazyWriteChannel.getSession(LazyWriteChannel.java:59) <== monitors:1

Some investigation into if/how this type of pinning detection can be introduced to integration suite still needs to happen. Superficially, I'm not sure if it's practical to get JUnit4 to run everything in virtual threads, we might need to depend on some other CI external validation.

Part of work needed for googleapis/google-cloud-java#12641

BenWhitehead added do not merge Indicates a pull request not ready for merge, due to either quality or timing. owlbot:ignore instruct owl-bot to ignore a PR labels May 17, 2024
BenWhitehead requested a review from a team May 17, 2024 17:56
product-auto-label Bot added size: l Pull request size is large. api: storage Issues related to the googleapis/java-storage API. labels May 17, 2024
BenWhitehead removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label May 22, 2024

JesseLovelace 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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM, thanks!

BenWhitehead merged commit 498fd0b into main May 30, 2024
BenWhitehead deleted the java21-reduce-io-pinning branch May 30, 2024 19:40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the googleapis/java-storage API. owlbot:ignore instruct owl-bot to ignore a PR size: l Pull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL