Skip to content
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

Shorten timeout used for recording task started #3268

Merged
merged 1 commit into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions service/matching/matchingEngine.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,14 @@ import (
serviceerrors "go.temporal.io/server/common/serviceerror"
)

// If sticky poller is not seem in last 10s, we treat it as sticky worker unavailable
// This seems aggressive, but the default sticky schedule_to_start timeout is 5s, so 10s seems reasonable.
const stickyPollerUnavailableWindow = 10 * time.Second
const (
// If sticky poller is not seem in last 10s, we treat it as sticky worker unavailable
// This seems aggressive, but the default sticky schedule_to_start timeout is 5s, so 10s seems reasonable.
stickyPollerUnavailableWindow = 10 * time.Second

recordTaskStartedDefaultTimeout = 10 * time.Second
recordTaskStartedSyncMatchTimeout = 1 * time.Second
)

// Implements matching.Engine
// TODO: Switch implementation from lock/channel based to a partitioned agent
Expand Down Expand Up @@ -987,6 +992,9 @@ func (e *matchingEngineImpl) recordWorkflowTaskStarted(
pollReq *workflowservice.PollWorkflowTaskQueueRequest,
task *internalTask,
) (*historyservice.RecordWorkflowTaskStartedResponse, error) {
ctx, cancel := newRecordTaskStartedContext(ctx, task)
defer cancel()

return e.historyClient.RecordWorkflowTaskStarted(ctx, &historyservice.RecordWorkflowTaskStartedRequest{
NamespaceId: task.event.Data.GetNamespaceId(),
WorkflowExecution: task.workflowExecution(),
Expand All @@ -1003,6 +1011,9 @@ func (e *matchingEngineImpl) recordActivityTaskStarted(
pollReq *workflowservice.PollActivityTaskQueueRequest,
task *internalTask,
) (*historyservice.RecordActivityTaskStartedResponse, error) {
ctx, cancel := newRecordTaskStartedContext(ctx, task)
defer cancel()

return e.historyClient.RecordActivityTaskStarted(ctx, &historyservice.RecordActivityTaskStartedRequest{
NamespaceId: task.event.Data.GetNamespaceId(),
WorkflowExecution: task.workflowExecution(),
Expand Down Expand Up @@ -1050,3 +1061,21 @@ func (m *lockableQueryTaskMap) delete(key string) {
defer m.Unlock()
delete(m.queryTaskMap, key)
}

// newRecordTaskStartedContext creates a context for recording
// activity or workflow task started. The parentCtx from
// pollActivity/WorkflowTaskQueue endpoint (which is a long poll
// API) has long timeout and unsutiable for recording task started,
// especially if the task is doing sync match and has caller
// (history transfer queue) waiting for response.
func newRecordTaskStartedContext(
parentCtx context.Context,
task *internalTask,
) (context.Context, context.CancelFunc) {
timeout := recordTaskStartedDefaultTimeout
if task.isSyncMatchTask() {
timeout = recordTaskStartedSyncMatchTimeout
}

return context.WithTimeout(parentCtx, timeout)
}
4 changes: 4 additions & 0 deletions service/matching/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ func (task *internalTask) isForwarded() bool {
return task.forwardedFrom != ""
}

func (task *internalTask) isSyncMatchTask() bool {
return task.responseC != nil
}

func (task *internalTask) workflowExecution() *commonpb.WorkflowExecution {
switch {
case task.event != nil:
Expand Down