feat(configuration): update asynq concurrency settings and enhance FAQ handling
- Increased the default worker pool size for the asynq server from 16 to 32 to improve performance during concurrent uploads. - Updated the .env.example and docker-compose.yml files to reflect the new default concurrency setting. - Enhanced the handling of FAQ entries in the tool results, ensuring distinct identification through standard questions, improving user experience and clarity in the output. - Refactored related components to utilize the new FAQ attributes, ensuring consistent display and interaction across the application.
This commit is contained in:
@@ -115,10 +115,10 @@ func asynqRetryDelayFunc(n int, e error, t *asynq.Task) time.Duration {
|
||||
// runtime.NumCPU(), which under-provisions during batch document uploads:
|
||||
// a single 4-core container can only process 4 documents in parallel even
|
||||
// when 100 are queued, so the queue wait time eats into each task's
|
||||
// DocumentProcessTimeout budget. 16 is a safer default for the I/O-bound
|
||||
// DocumentProcessTimeout budget. 32 is a safer default for the I/O-bound
|
||||
// nature of doc parsing (most time is spent in DocReader / embedding RPCs,
|
||||
// not on local CPU).
|
||||
const defaultAsynqConcurrency = 16
|
||||
const defaultAsynqConcurrency = 32
|
||||
|
||||
func NewAsynqServer(svc interfaces.SystemSettingService) *asynq.Server {
|
||||
opt := getAsynqRedisClientOpt()
|
||||
|
||||
@@ -106,6 +106,69 @@ func (a *asynqTaskInspector) CancelTasksForKnowledge(
|
||||
return deleted, cancelled, nil
|
||||
}
|
||||
|
||||
// HasQueuedTasksForKnowledge reports whether any pending / scheduled /
|
||||
// retry / active task referencing knowledgeID still lives in the queue.
|
||||
// Read-only counterpart of CancelTasksForKnowledge — the housekeeping
|
||||
// sweep uses it to avoid flagging a backlogged-but-not-orphaned row as
|
||||
// failed. Short-circuits on the first match and never deletes anything.
|
||||
func (a *asynqTaskInspector) HasQueuedTasksForKnowledge(
|
||||
ctx context.Context, knowledgeID string,
|
||||
) (bool, error) {
|
||||
if a == nil || a.inspector == nil || knowledgeID == "" {
|
||||
return false, nil
|
||||
}
|
||||
listers := []struct {
|
||||
state string
|
||||
list func(string, ...asynq.ListOption) ([]*asynq.TaskInfo, error)
|
||||
}{
|
||||
{"pending", a.inspector.ListPendingTasks},
|
||||
{"scheduled", a.inspector.ListScheduledTasks},
|
||||
{"retry", a.inspector.ListRetryTasks},
|
||||
{"active", a.inspector.ListActiveTasks},
|
||||
}
|
||||
for _, queue := range queuesScanned {
|
||||
for _, l := range listers {
|
||||
if a.queueStateHasMatch(ctx, queue, knowledgeID, l.state, l.list) {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// queueStateHasMatch pages through one (queue, state) list looking for a
|
||||
// task that references knowledgeID. Mirrors the delete* scanners but is
|
||||
// strictly read-only and returns early on the first hit. A backend error
|
||||
// is logged and treated as "no match" (false); the caller's fail-safe
|
||||
// then errs toward recovering the row rather than preserving it forever.
|
||||
func (a *asynqTaskInspector) queueStateHasMatch(
|
||||
ctx context.Context, queue, knowledgeID, state string,
|
||||
list func(string, ...asynq.ListOption) ([]*asynq.TaskInfo, error),
|
||||
) bool {
|
||||
page := 1
|
||||
for {
|
||||
tasks, err := list(queue, asynq.PageSize(listPageSize), asynq.Page(page))
|
||||
if err != nil {
|
||||
if !errors.Is(err, asynq.ErrQueueNotFound) {
|
||||
logger.Warnf(ctx, "[TaskInspector] probe %s queue=%s page=%d: %v", state, queue, page, err)
|
||||
}
|
||||
return false
|
||||
}
|
||||
if len(tasks) == 0 {
|
||||
return false
|
||||
}
|
||||
for _, t := range tasks {
|
||||
if matchesKnowledge(t.Type, t.Payload, knowledgeID) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
if len(tasks) < listPageSize {
|
||||
return false
|
||||
}
|
||||
page++
|
||||
}
|
||||
}
|
||||
|
||||
// matchesKnowledge returns true when the task type is one we cancel
|
||||
// AND its payload references the target knowledge ID.
|
||||
func matchesKnowledge(taskType string, payload []byte, knowledgeID string) bool {
|
||||
@@ -262,3 +325,12 @@ func (noopTaskInspector) CancelTasksForKnowledge(
|
||||
) (int, int, error) {
|
||||
return 0, 0, nil
|
||||
}
|
||||
|
||||
// HasQueuedTasksForKnowledge always reports false in Lite mode: inline
|
||||
// executors never enqueue, so there is no backlog to protect against and
|
||||
// the housekeeping sweep's span/updated_at checks stay authoritative.
|
||||
func (noopTaskInspector) HasQueuedTasksForKnowledge(
|
||||
ctx context.Context, knowledgeID string,
|
||||
) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user