-
Notifications
You must be signed in to change notification settings - Fork 3k
NIFI-15862: Moved Processors to using Virtual Threads with a Semaphor… #11164
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
Merged
+2,559
−155
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1f5d274
NIFI-15862: Move Component Scheduling to Virtual Threads
markap14 c78511d
NIFI-15862: Configure Component Scheduling Mode
markap14 f637504
NIFI-15862: Refine Scheduling Strategy Configuration
markap14 a87ca6d
NIFI-15862: Clear Interrupt Status Between Invocations
markap14 300f0c6
NIFI-15862: Select Scheduling Strategy by Java Version
markap14 947b12a
NIFI-15862: Reduce Permit Polling Frequency
markap14 97d0afe
NIFI-15862: Separate Framework and Component Thread Counts
markap14 d39ac04
NIFI-15862: Exercise Automatic Scheduling in System Tests
markap14 35dc8b9
NIFI-15862: Address Scheduling Review Feedback
markap14 3f69ddc
NIFI-15862: Address Additional Virtual Thread Review Feedback
markap14 558290c
NIFI-15862: Prevent Stopped Scheduling Generation Invocation
markap14 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
105 changes: 105 additions & 0 deletions
105
nifi-framework-api/src/test/java/org/apache/nifi/diagnostics/ThreadDumpTaskTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.nifi.diagnostics; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.lang.management.ManagementFactory; | ||
| import java.util.concurrent.CountDownLatch; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| class ThreadDumpTaskTest { | ||
|
|
||
| @Test | ||
| void testCaptureDumpIncludesPlatformAndVirtualThreads() throws InterruptedException { | ||
| final String platformThreadName = "thread-dump-platform-thread"; | ||
| final String virtualThreadName = "thread-dump-virtual-thread"; | ||
| final CountDownLatch threadsStarted = new CountDownLatch(2); | ||
| final CountDownLatch releaseThreads = new CountDownLatch(1); | ||
| final Runnable task = () -> { | ||
| threadsStarted.countDown(); | ||
| try { | ||
| releaseThreads.await(); | ||
| } catch (final InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| } | ||
| }; | ||
|
|
||
| final Thread platformThread = Thread.ofPlatform().name(platformThreadName).start(task); | ||
| final Thread virtualThread = Thread.ofVirtual().name(virtualThreadName).start(task); | ||
|
|
||
| try { | ||
| assertTrue(threadsStarted.await(2, TimeUnit.SECONDS)); | ||
|
|
||
| final DiagnosticsDumpElement dumpElement = new ThreadDumpTask().captureDump(false); | ||
| final String threadDump = dumpElement.getDetails().getFirst(); | ||
|
|
||
| assertTrue(threadDump.contains(platformThreadName)); | ||
| assertTrue(threadDump.contains(virtualThreadName)); | ||
| } finally { | ||
| releaseThreads.countDown(); | ||
| platformThread.join(2_000L); | ||
| virtualThread.join(2_000L); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void testPlatformFallbackIncludesBlockedMonitor() throws InterruptedException { | ||
| final Object monitor = new Object(); | ||
| final CountDownLatch monitorAcquired = new CountDownLatch(1); | ||
| final CountDownLatch releaseMonitor = new CountDownLatch(1); | ||
| final Thread lockOwner = Thread.ofPlatform().name("thread-dump-lock-owner").start(() -> { | ||
| synchronized (monitor) { | ||
| monitorAcquired.countDown(); | ||
| try { | ||
| releaseMonitor.await(); | ||
| } catch (final InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| try { | ||
| assertTrue(monitorAcquired.await(2, TimeUnit.SECONDS)); | ||
| final Thread blockedThread = Thread.ofPlatform().name("thread-dump-blocked-thread").start(() -> { | ||
| synchronized (monitor) { | ||
| } | ||
| }); | ||
|
|
||
| try { | ||
| final long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(2L); | ||
| while (blockedThread.getState() != Thread.State.BLOCKED && System.nanoTime() < deadline) { | ||
| Thread.onSpinWait(); | ||
| } | ||
| assertEquals(Thread.State.BLOCKED, blockedThread.getState()); | ||
|
|
||
| final String threadDump = new ThreadDumpTask().capturePlatformThreadDump(ManagementFactory.getThreadMXBean()); | ||
| final String blockedThreadHeader = "\"thread-dump-blocked-thread\" Id=" + blockedThread.threadId() + " BLOCKED on "; | ||
| assertTrue(threadDump.contains(blockedThreadHeader)); | ||
| } finally { | ||
| releaseMonitor.countDown(); | ||
| blockedThread.join(2_000L); | ||
| } | ||
| } finally { | ||
| releaseMonitor.countDown(); | ||
| lockOwner.join(2_000L); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.