Former-commit-id: 0c57af8f024f976ffcc6f6970f0d783463b12a63
This commit is contained in:
zhangwei 2024-06-22 21:18:20 +08:00
commit 7f791a9e6b
2 changed files with 12 additions and 5 deletions

View File

@ -269,6 +269,7 @@ func infer(opt *option.InferOption, clusters []*strategy.AssignedCluster, ts []s
var result_ch = make(chan *types.ImageResult, len(ts)) var result_ch = make(chan *types.ImageResult, len(ts))
var results []*types.ImageResult var results []*types.ImageResult
limit := make(chan bool, 7)
var imageNumIdx int32 = 0 var imageNumIdx int32 = 0
var imageNumIdxEnd int32 = 0 var imageNumIdxEnd int32 = 0
@ -284,7 +285,7 @@ func infer(opt *option.InferOption, clusters []*strategy.AssignedCluster, ts []s
imageNumIdx = imageNumIdx + c.imageNum imageNumIdx = imageNumIdx + c.imageNum
wg.Add(len(new_images)) wg.Add(len(new_images))
go sendInferReq(new_images, c, &wg, result_ch) go sendInferReq(new_images, c, &wg, result_ch, limit)
} }
wg.Wait() wg.Wait()
close(result_ch) close(result_ch)
@ -375,8 +376,9 @@ func sendInferReq(images []struct {
clusterId string clusterId string
clusterName string clusterName string
imageNum int32 imageNum int32
}, wg *sync.WaitGroup, ch chan<- *types.ImageResult) { }, wg *sync.WaitGroup, ch chan<- *types.ImageResult, limit chan bool) {
for _, image := range images { for _, image := range images {
limit <- true
go func(t struct { go func(t struct {
imageResult *types.ImageResult imageResult *types.ImageResult
file multipart.File file multipart.File
@ -395,6 +397,7 @@ func sendInferReq(images []struct {
t.imageResult.Card = c.urls[0].Card t.imageResult.Card = c.urls[0].Card
ch <- t.imageResult ch <- t.imageResult
wg.Done() wg.Done()
<-limit
return return
} }
t.imageResult.ImageResult = r t.imageResult.ImageResult = r
@ -404,6 +407,7 @@ func sendInferReq(images []struct {
ch <- t.imageResult ch <- t.imageResult
wg.Done() wg.Done()
<-limit
return return
} else { } else {
idx := rand.Intn(len(c.urls)) idx := rand.Intn(len(c.urls))
@ -415,6 +419,7 @@ func sendInferReq(images []struct {
t.imageResult.Card = c.urls[idx].Card t.imageResult.Card = c.urls[idx].Card
ch <- t.imageResult ch <- t.imageResult
wg.Done() wg.Done()
<-limit
return return
} }
t.imageResult.ImageResult = r t.imageResult.ImageResult = r
@ -424,9 +429,11 @@ func sendInferReq(images []struct {
ch <- t.imageResult ch <- t.imageResult
wg.Done() wg.Done()
<-limit
return return
} }
}(image, cluster) }(image, cluster)
<-limit
} }
} }
@ -526,9 +533,9 @@ func SendRequest(method, url string, file multipart.File, fileName string) (stri
res, err := signedR.Do(request) res, err := signedR.Do(request)
if err != nil { if err != nil {
fmt.Println("Error sending request:", err) fmt.Println("Error sending request:", err)
//return nil, err return "", err
} }
defer res.Body.Close() //defer res.Body.Close()
Resbody, err := io.ReadAll(res.Body) Resbody, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
fmt.Println("Error reading response body:", err) fmt.Println("Error reading response body:", err)

View File

@ -89,7 +89,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
NamingStrategy: schema.NamingStrategy{ NamingStrategy: schema.NamingStrategy{
SingularTable: true, // 使用单数表名,启用该选项,此时,`User` 的表名应该是 `t_user` SingularTable: true, // 使用单数表名,启用该选项,此时,`User` 的表名应该是 `t_user`
}, },
Logger: logger.Default.LogMode(logger.Info), Logger: logger.Default.LogMode(logger.Warn),
}) })
if err != nil { if err != nil {
logx.Errorf("数据库连接失败, err%v", err) logx.Errorf("数据库连接失败, err%v", err)