-
Notifications
You must be signed in to change notification settings - Fork 10
Add worker thread #1
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
Conversation
|
@yaron2 , @cgillum I plan to test this PR out tomorrow. Can you folks tell me your initial thoughts on this please ? This is the github issue: github.com/dapr/java-sdk/issues/1331 |
|
I looked at dotnet durable task implementation. It just uses a simple run https://github.com/microsoft/durabletask-dotnet/blob/main/src/Worker/Grpc/GrpcDurableTaskWorker.Processor.cs#L333 So followed a similar implementation |
| this.sidecarClient = TaskHubSidecarServiceGrpc.newBlockingStub(sidecarGrpcChannel); | ||
| this.dataConverter = builder.dataConverter != null ? builder.dataConverter : new JacksonDataConverter(); | ||
| this.maximumTimerInterval = builder.maximumTimerInterval != null ? builder.maximumTimerInterval : DEFAULT_MAXIMUM_TIMER_INTERVAL; | ||
| this.workerPool = Executors.newCachedThreadPool(); |
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.
Please allow client to pass the workerPool, so that client can make use of the VirtualThread pool if and when required.
2. Await for the executor to shutdown before closing the connection to mitigate the risk on inflight requests being processed by threadpool
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.
For the second point, we need to use the this.workerPoolshutdown() method in the public void stop() {} function.
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.
Provided the ability to pass in the worker poll too and added the workerPoolShutdown
client/src/main/java/com/microsoft/durabletask/DurableTaskGrpcWorker.java
Show resolved
Hide resolved
|
@siri-varma @rishi-dev89 ok.. I am looking at this PR and I am trying to understand a bit the expected behaviour that is implemented. |
|
Also the TODO validated that this was the original intention from the author: |
client/src/main/java/com/microsoft/durabletask/DurableTaskGrpcWorker.java
Outdated
Show resolved
Hide resolved
Signed-off-by: siri-varma <[email protected]>
Signed-off-by: siri-varma <[email protected]>
Signed-off-by: siri-varma <[email protected]>
7ecfa96 to
5b2db59
Compare
Signed-off-by: siri-varma <[email protected]>
cgillum
left a comment
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.
Overall LGTM. I especially appreciate the change to allow the user code to provide the executor pool. Just one main concern about the management of the worker's while loop.
|
|
||
| // TODO: How do we interrupt manually? | ||
| while (true) { | ||
| while (!this.workerPool.isShutdown()) { |
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.
I'm wondering what the side effects of this change might be. For sure we'll need to update the logging code to account for this new exit condition. But does this mean that user code could also accidentally shut down this loop by shutting down the worker pool? Is this change critical?
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.
Once the workerpool is closed they cannot submit new activities anyway so I thought we could safely come out of the while loop.
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.
If that's the case, we should at least log a warning.
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.
is this resolved? @siri-varma
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.
Yes. Took care of it.
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.
|
@cgillum, @JoshVanL, @rishi-dev89, @cicoyle, @salaboy Addressed all the feedback on this PR. Thank you for the reviews |
Signed-off-by: siri-varma <[email protected]>
| .setCustomStatus(StringValue.of(taskOrchestratorResult.getCustomStatus())) | ||
| .build(); | ||
|
|
||
| this.sidecarClient.completeOrchestratorTask(response); |
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.
Please use a try catch here as well as it can throw StatusRuntimeException
catch (StatusRuntimeException e) {
if (e.getStatus().getCode() == Status.Code.UNAVAILABLE) {
logger.log(Level.INFO, "The sidecar at address {0} is unavailable. Will continue retrying.", this.getSidecarAddress());
} else if (e.getStatus().getCode() == Status.Code.CANCELLED) {
logger.log(Level.INFO, "Durable Task worker has disconnected from {0}.", this.getSidecarAddress());
logger.log(Level.INFO, "Durable Task worker has disconnected from {0}.", this.getSidecarAddress());
} else {
logger.log(Level.WARNING, "Unexpected failure connecting to {0}.", this.getSidecarAddress());
}
| responseBuilder.setFailureDetails(failureDetails); | ||
| } | ||
|
|
||
| this.sidecarClient.completeActivityTask(responseBuilder.build()); |
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.
Try catch block would be required here as well, otherwise the exception will never be logged and could be difficult to debbug
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.
good idea. I will do a quick small PR to address this
| } | ||
|
|
||
| private void shutDownWorkerPool() { | ||
| logger.log(Level.WARNING, "ExecutorService shutdown initiated. No new tasks will be accepted"); |
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.
This is not correct. Now this warning will be logged every time a user shuts down their worker, but we only want to log the warning when the worker pool was shut down unexpectedly.
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.
I opened a PR here. I think this addresses your comment.
Fix release package name

Issue describing the changes in this PR
resolves #
github.com/dapr/java-sdk/issues/1331
Pull request checklist
CHANGELOG.mdAdditional information
Additional PR information