Repository navigation
Report total active threads #28513
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
Report total active threads #28513
Changes from all commits
d333918
fa671b2
6b55b9f
7e60a26
eab8eed
cf3bc0f
9e65c40
b6c6d20
e194aeb
9ecb9c0
66b8430
b7fdb4c
1fc3589
419d4e0
b6db0d3
4843640
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -291,7 +291,7 @@ static Work createMockWork(long workToken, Consumer<Work> processWorkFn) { | |
| Windmill.WorkItem.newBuilder().setKey(ByteString.EMPTY).setWorkToken(workToken).build(), | ||
| Instant::now, | ||
| Collections.emptyList(), | ||
| work -> {}); | ||
| processWorkFn); | ||
| } | ||
|
|
||
| private byte[] intervalWindowBytes(IntervalWindow window) throws Exception { | ||
|
|
@@ -2793,6 +2793,79 @@ public void testMaxThreadMetric() throws Exception { | |
| executor.shutdown(); | ||
| } | ||
|
|
||
| volatile boolean stop = false; | ||
|
|
||
| @Test | ||
| public void testActiveThreadMetric() throws Exception { | ||
| int maxThreads = 5; | ||
| int threadExpirationSec = 60; | ||
| // setting up actual implementation of executor instead of mocking to keep track of | ||
| // active thread count. | ||
| BoundedQueueExecutor executor = | ||
| new BoundedQueueExecutor( | ||
| maxThreads, | ||
| threadExpirationSec, | ||
| TimeUnit.SECONDS, | ||
| maxThreads, | ||
| 10000000, | ||
| new ThreadFactoryBuilder() | ||
| .setNameFormat("DataflowWorkUnits-%d") | ||
| .setDaemon(true) | ||
| .build()); | ||
|
|
||
| ComputationState computationState = | ||
| new ComputationState( | ||
| "computation", | ||
| defaultMapTask(Arrays.asList(makeSourceInstruction(StringUtf8Coder.of()))), | ||
| executor, | ||
| ImmutableMap.of(), | ||
| null); | ||
|
|
||
| ShardedKey key1Shard1 = ShardedKey.create(ByteString.copyFromUtf8("key1"), 1); | ||
|
|
||
| Consumer<Work> sleepProcessWorkFn = | ||
| unused -> { | ||
| synchronized (this) { | ||
| this.notify(); | ||
| } | ||
| int count = 0; | ||
| while (!stop) { | ||
| count += 1; | ||
| } | ||
| }; | ||
|
|
||
| Work m2 = createMockWork(2, sleepProcessWorkFn); | ||
|
|
||
| Work m3 = createMockWork(3, sleepProcessWorkFn); | ||
|
|
||
| Work m4 = createMockWork(4, sleepProcessWorkFn); | ||
| assertEquals(0, executor.activeCount()); | ||
|
edman124 marked this conversation as resolved.
Resolved
|
||
|
|
||
| assertTrue(computationState.activateWork(key1Shard1, m2)); | ||
| synchronized (this) { | ||
| executor.execute(m2, m2.getWorkItem().getSerializedSize()); | ||
| this.wait(); | ||
| // Seems current executor executes the initial work item twice | ||
| this.wait(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this may have caused #28957
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could be the first thread started runs before the synchronized block starts causing a deadlock. I have a fix in #29041 that uses countdown latches.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
| assertEquals(2, executor.activeCount()); | ||
|
|
||
| assertTrue(computationState.activateWork(key1Shard1, m3)); | ||
| assertTrue(computationState.activateWork(key1Shard1, m4)); | ||
| synchronized (this) { | ||
| executor.execute(m3, m3.getWorkItem().getSerializedSize()); | ||
| this.wait(); | ||
| } | ||
| assertEquals(3, executor.activeCount()); | ||
| synchronized (this) { | ||
| executor.execute(m4, m4.getWorkItem().getSerializedSize()); | ||
| this.wait(); | ||
| } | ||
| assertEquals(4, executor.activeCount()); | ||
| stop = true; | ||
| executor.shutdown(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testExceptionInvalidatesCache() throws Exception { | ||
| // We'll need to force the system to limit bundles to one message at a time. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.