Răsfoiți Sursa

增加全局线程限制

xuzhiheng 2 ani în urmă
părinte
comite
b3d4132037
2 a modificat fișierele cu 39 adăugiri și 14 ștergeri
  1. 38 13
      src/client/customerRule.go
  2. 1 1
      src/util/utiltag.go

+ 38 - 13
src/client/customerRule.go

@@ -8,6 +8,7 @@ import (
 	"log"
 	mongoutil "qfw/mongodb"
 	qu "qfw/util"
+	"qfw/util/redis"
 	"regexp"
 	sql "sqlmodel"
 	"strings"
@@ -257,17 +258,32 @@ func (c *CustomerRule) ProductData() {
 		// var n int
 		// 小于1000的直接查
 		// if totalCount < 1000 {
-		err, count = UtilEsFind1(*tag)
-		// UtilEsFind1(*tag)
-		// } else {
-		// 	if totalCount >= 1000 && totalCount < 4000 {
-		// 		n = 3
-		// 	}
-		// 	if totalCount >= 4000 && totalCount < 8000 {
-		// 		n = 1
-		// 	}
-		// 	err, count = UtilEsFind2(*tag, n)
-		// }
+		for {
+			listLen := redis.GetInt("session", "es_status")
+			if listLen == 0 {
+				log.Println("es空闲!")
+				break
+			} else if listLen == 1 || listLen == 2 {
+				log.Println("系统繁忙,请稍后再试 ", listLen)
+			}
+			time.Sleep(2 * time.Second)
+		}
+		var times = 0
+		for {
+			listLens := int(redis.LLEN("datag", "jyqyfw_es_query"))
+			if listLens < 2 {
+				redis.RPUSH("datag", "jyqyfw_es_query", 1)
+				err, count = UtilEsFind1(*tag)
+				redis.LPOP("datag", "jyqyfw_es_query")
+				break
+			} else if times > 10 {
+				err = errors.New("系统繁忙,请稍后再试")
+				break
+			}
+			times += 2
+			time.Sleep(2 * time.Second)
+		}
+
 		if err == nil {
 			rep = true
 			// msg = "数据生成成功"
@@ -277,7 +293,7 @@ func (c *CustomerRule) ProductData() {
 			})
 		} else {
 			rep = false
-			msg := "数据生成失败"
+			msg := "数据生成失败,请稍后再试"
 			c.ServeJson(map[string]interface{}{
 				"rep":   rep,
 				"count": count,
@@ -318,7 +334,16 @@ func (r *CustomerRule) DemoData() {
 		startTime := time.Now().Unix() - 86400*60
 		endTime := time.Now().Unix()
 		esquery, _ = FilterTimeSql(esquery, startTime, endTime)
-
+		for {
+			listLen := redis.GetInt("session", "es_status")
+			if listLen == 0 {
+				log.Println("es空闲!")
+				break
+			} else if listLen == 1 || listLen == 2 {
+				log.Println("系统繁忙,请稍后再试 ", listLen)
+			}
+			time.Sleep(2 * time.Second)
+		}
 		count := Es.Count(InterimIndex, Itype, esquery)
 		esquery = esquery[:len(esquery)-1] + `,"size":` + fmt.Sprintf("%d", 100) + `}`
 		log.Println("esquery ", esquery)

+ 1 - 1
src/util/utiltag.go

@@ -121,7 +121,7 @@ func UtilEsFind1(tags map[string]interface{}) (error, int64) {
 	} else {
 		return errors.New("o_rules no found"), 0
 	}
-	ctx, _ := context.WithTimeout(context.Background(), 5*time.Minute)
+	ctx, _ := context.WithTimeout(context.Background(), 1*time.Hour)
 	esCon := esv.VarEs.(*esv.EsV7)
 	client := esCon.GetEsConn()
 	defer esCon.DestoryEsConn(client)