32 lines
1.2 KiB
Go
32 lines
1.2 KiB
Go
package common
|
|
|
|
import (
|
|
"context"
|
|
|
|
"rag-local/kb/consts"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"github.com/gogf/gf/v2/os/grpool"
|
|
)
|
|
|
|
// 各并行点协程池。池内任务只做读查询与 LLM/Embedding 调用(纯 IO),
|
|
// SQLite 写一律收敛回主 goroutine 串行执行(business.db 无 WAL,并发写会 database is locked)。
|
|
// 防死锁:被等待的池(AnnotationDatasetPool / ChatRetrievePool)任务内不得再等待任何池,
|
|
// 等待链单向「主 → A池 → B池」;池无 Wait 方法,等待用调用方的 sync.WaitGroup。
|
|
var (
|
|
KgExtractPool = newPool(consts.KgExtractPoolSize, "kg_extract")
|
|
AnnotationClausePool = newPool(consts.AnnotationClausePoolSize, "annotation_clause")
|
|
AnnotationDatasetPool = newPool(consts.AnnotationDatasetPoolSize, "annotation_dataset")
|
|
ChatPool = newPool(consts.ChatPoolSize, "chat")
|
|
ChatRetrievePool = newPool(consts.ChatRetrievePoolSize, "chat_retrieve")
|
|
)
|
|
|
|
// newPool 从 config pool.<key> 读取池大小(<1 或缺失时回退默认值 def)
|
|
func newPool(def int, key string) *grpool.Pool {
|
|
size := g.Cfg().MustGet(context.Background(), "pool."+key, def).Int()
|
|
if size < 1 {
|
|
size = def
|
|
}
|
|
return grpool.New(size)
|
|
}
|