-
Notifications
You must be signed in to change notification settings - Fork 224
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
Fix over acquiring of tasks in MultiThreadAgent #496
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
14c21f5
Fix over acquiring of tasks in MultiThreadAgent
frsyuki d3950b4
executorQueue.size() + executor.getActiveCount() is not atomic operation
frsyuki 981546e
core pool size should be same with max pool size
frsyuki 6926ec0
Use atomic counter to calculate guaranteed number of idling threads
frsyuki 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 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
62 changes: 62 additions & 0 deletions
62
digdag-tests/src/test/java/acceptance/AgentOverAcquireIT.java
This file contains 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,62 @@ | ||
package acceptance; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.Assert.assertThat; | ||
import static org.junit.Assume.assumeThat; | ||
import static utils.TestUtils.copyResource; | ||
import static utils.TestUtils.main; | ||
import utils.CommandStatus; | ||
|
||
public class AgentOverAcquireIT | ||
{ | ||
@Rule | ||
public TemporaryFolder folder = new TemporaryFolder(); | ||
|
||
private Path projectDir; | ||
private Path config; | ||
private Path outdir; | ||
|
||
@Before | ||
public void setUp() | ||
throws Exception | ||
{ | ||
projectDir = folder.getRoot().toPath(); | ||
config = folder.newFile().toPath(); | ||
|
||
outdir = projectDir.resolve("outdir"); | ||
Files.createDirectories(outdir); | ||
} | ||
|
||
@Test | ||
public void testOverAcquire() | ||
throws Exception | ||
{ | ||
assumeThat(true, is(false)); // disabled by default to avoid too long execution time. | ||
|
||
copyResource("acceptance/over_acquire/over_acquire.dig", projectDir.resolve("over_acquire.dig")); | ||
|
||
CommandStatus runStatus = main("run", | ||
"-o", projectDir.toString(), | ||
"--config", config.toString(), | ||
"--project", projectDir.toString(), | ||
"-X", "agent.heartbeat-interval=5", | ||
"-X", "agent.lock-retention-time=20", | ||
"-X", "agent.max-task-threads=5", | ||
"-p", "outdir=" + outdir, | ||
"over_acquire.dig"); | ||
assertThat(runStatus.errUtf8(), runStatus.code(), is(0)); | ||
|
||
for (int i = 0; i < 20; i++) { | ||
String one = new String(Files.readAllBytes(outdir.resolve(Integer.toString(i))), UTF_8).trim(); | ||
assertThat(one, is("1")); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
digdag-tests/src/test/resources/acceptance/over_acquire/over_acquire.dig
This file contains 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,7 @@ | ||
|
||
+loop: | ||
loop>: 20 | ||
_parallel: true | ||
_do: | ||
sh>: sleep 30 && echo 1 >> ${outdir}/${i} | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
AtomicInteger
makes it a bit simpler.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With
SynchronousQueue
, callingexecutor.submit()
can be blocked holdingtaskCountLock
. As a result, a thread that tries to decrement the counter here can be potentially blocked forever?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SynchronousQueue
is used withmaximumPoolSize: Integer.MAX_VALUE
. So it's usually okay. But it seems a bit naive to me...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point 👍 I changed the code to use AtomicInteger. Now still
AgentOverAcquireIT
passes.