Fix Cgo lock os thread failed (#19148)

Signed-off-by: xiaofan-luan <xiaofan.luan@zilliz.com>

Signed-off-by: xiaofan-luan <xiaofan.luan@zilliz.com>
pull/18949/head
Xiaofan 2022-09-13 10:16:30 +08:00 committed by GitHub
parent 5b077ae980
commit ec48e2405a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -240,15 +240,20 @@ func (node *QueryNode) Init() error {
return return
} }
// ensure every cgopool go routine is locked with a OS thread
// so openmp in knowhere won't create too much request
sig := make(chan struct{}) sig := make(chan struct{})
wg := sync.WaitGroup{}
wg.Add(cpuNum)
for i := 0; i < cpuNum; i++ { for i := 0; i < cpuNum; i++ {
node.cgoPool.Submit(func() (interface{}, error) { node.cgoPool.Submit(func() (interface{}, error) {
runtime.LockOSThread() runtime.LockOSThread()
wg.Done()
<-sig <-sig
return nil, nil return nil, nil
}) })
} }
wg.Wait()
close(sig) close(sig)
node.metaReplica = newCollectionReplica(node.cgoPool) node.metaReplica = newCollectionReplica(node.cgoPool)