Ver código fonte

fix:清除阻塞

zhangxinlei1996 11 meses atrás
pai
commit
cfa4c2d156
3 arquivos alterados com 27 adições e 21 exclusões
  1. 8 5
      data_project/load_data.go
  2. 5 4
      data_project/project.go
  3. 14 12
      data_project/task.go

+ 8 - 5
data_project/load_data.go

@@ -3,20 +3,23 @@ package main
 import (
 	"encoding/json"
 	"fmt"
+	"strings"
+	"sync"
+	"time"
+
 	"go.uber.org/zap"
 	util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
 	"jygit.jydev.jianyu360.cn/data_processing/common_utils/log"
 	"jygit.jydev.jianyu360.cn/data_processing/common_utils/redis"
-	"strings"
-	"sync"
-	"time"
 )
 
 // 初始加载数据,默认加载最近6个月的数据
 func (p *ProjectTask) loadData(starttime int64) {
 	log.Info("load project start..", zap.Int64("starttime", starttime))
-	p.findLock.Lock()
-	defer p.findLock.Unlock()
+
+	//清除进程时 会卡住注释掉
+	// p.findLock.Lock()
+	// defer p.findLock.Unlock()
 	sess := MgoP.GetMgoConn()
 	defer MgoP.DestoryMongoConn(sess)
 	loadOver := make(chan bool)

+ 5 - 4
data_project/project.go

@@ -3,16 +3,17 @@ package main
 import (
 	"encoding/json"
 	"fmt"
+	"math"
+	"sort"
+	"strings"
+	"time"
+
 	"go.mongodb.org/mongo-driver/bson"
 	"go.mongodb.org/mongo-driver/bson/primitive"
 	util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
 	"jygit.jydev.jianyu360.cn/data_processing/common_utils/log"
 	"jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
 	"jygit.jydev.jianyu360.cn/data_processing/common_utils/redis"
-	"math"
-	"sort"
-	"strings"
-	"time"
 )
 
 /**

+ 14 - 12
data_project/task.go

@@ -3,6 +3,13 @@ package main
 import (
 	"encoding/json"
 	"fmt"
+	"project/config"
+	"regexp"
+	"strings"
+	"sync"
+	"time"
+	"unicode/utf8"
+
 	"github.com/goinggo/mapstructure"
 	"github.com/robfig/cron"
 	"go.mongodb.org/mongo-driver/bson"
@@ -12,12 +19,6 @@ import (
 	"jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
 	"jygit.jydev.jianyu360.cn/data_processing/common_utils/redis"
 	"jygit.jydev.jianyu360.cn/data_processing/common_utils/udp"
-	"project/config"
-	"regexp"
-	"strings"
-	"sync"
-	"time"
-	"unicode/utf8"
 )
 
 /**
@@ -118,10 +119,11 @@ func NewPT() *ProjectTask {
 
 		//saveSign:   make(chan bool, 1),
 		//updateSign: make(chan bool, 1),
-		coll:       ProjectColl,
-		validTime:  int64(util.IntAllDef(config.Conf.Serve.ValidDays, 150)) * 86400,
-		statusTime: int64(util.IntAllDef(config.Conf.Serve.StatusDays, 15) * 86400),
-		jgTime:     int64(util.IntAllDef(7, 7) * 86400),
+		coll:        ProjectColl,
+		validTime:   int64(util.IntAllDef(config.Conf.Serve.ValidDays, 150)) * 86400,
+		statusTime:  int64(util.IntAllDef(config.Conf.Serve.StatusDays, 15) * 86400),
+		jgTime:      int64(util.IntAllDef(7, 7) * 86400),
+		currentType: "ql",
 	}
 	return p
 }
@@ -170,8 +172,8 @@ func (p *ProjectTask) clearMem() {
 	// 创建项目的时间大于7天
 	//在内存中保留最近6个月的信息
 	//跑全量时每5分钟跑一次,跑增量时400分钟跑一次
-	_ = c.AddFunc("50 0/5 * * * *", func() {
-		if (p.currentType == "ql" && SingleClear == 0) || p.clearContimes >= 80 {
+	_ = c.AddFunc("0 */30 * * * ?", func() {
+		if (p.currentType == "ql" && SingleClear == 0) || p.clearContimes >= 20 {
 			SingleClear = 1
 			//跳过的次数清零
 			p.clearContimes = 0