2 Commits b6413af5d1 ... 64aac7e44d

Author SHA1 Message Date
  jiantao 64aac7e44d Merge branch 'master' of http://code.jschengta.com/zhanlang/miads 4 years ago
  jiantao a17c3726f8 性能调优 4 years ago

+ 9 - 0
ads_handler.go

@@ -100,6 +100,7 @@ func adsHandler(c *gin.Context) {
100
 			Androidid    string `json:"android_id"`
100
 			Androidid    string `json:"android_id"`
101
 			ShortMessage string `json:"short_message"`
101
 			ShortMessage string `json:"short_message"`
102
 			ReqSource    string `json:"req_source"`
102
 			ReqSource    string `json:"req_source"`
103
+			Hehe         string `json:"hehe"`
103
 		}{
104
 		}{
104
 			Ip:           ip,
105
 			Ip:           ip,
105
 			Imei:         request.Imei,
106
 			Imei:         request.Imei,
@@ -113,6 +114,7 @@ func adsHandler(c *gin.Context) {
113
 			Androidid:    request.Androidid,
114
 			Androidid:    request.Androidid,
114
 			ShortMessage: "ads_api_log",
115
 			ShortMessage: "ads_api_log",
115
 			ReqSource:    "zhiku",
116
 			ReqSource:    "zhiku",
117
+			Hehe:         "heheheheh",
116
 		}
118
 		}
117
 
119
 
118
 		graylog.Log(grayLogData)
120
 		graylog.Log(grayLogData)
@@ -506,6 +508,7 @@ func adsHandler(c *gin.Context) {
506
 			// 先跑定投
508
 			// 先跑定投
507
 			customAdData, err := addata.GetCustomAdsInfos(&dspInfo, 0, 0, xiaomiResponseFlag)
509
 			customAdData, err := addata.GetCustomAdsInfos(&dspInfo, 0, 0, xiaomiResponseFlag)
508
 			if err != nil {
510
 			if err != nil {
511
+				log.WithField("request_id", dspInfo.RequestId).Infof("get custom ads info failed: %s", err)
509
 				c.String(404, "get custom ads info failed: %s", err.Error())
512
 				c.String(404, "get custom ads info failed: %s", err.Error())
510
 				return
513
 				return
511
 			}
514
 			}
@@ -515,6 +518,7 @@ func adsHandler(c *gin.Context) {
515
 			if customAdData == nil {
518
 			if customAdData == nil {
516
 				customAdData, err = addata.GetCustomAdsInfos(&dspInfo, 0, 1, xiaomiResponseFlag)
519
 				customAdData, err = addata.GetCustomAdsInfos(&dspInfo, 0, 1, xiaomiResponseFlag)
517
 				if err != nil {
520
 				if err != nil {
521
+					log.WithField("request_id", dspInfo.RequestId).Errorf("get fix custom ads info failed: %s", err)
518
 					c.String(404, "get fix custom ads info failed: %s", err.Error())
522
 					c.String(404, "get fix custom ads info failed: %s", err.Error())
519
 					return
523
 					return
520
 				}
524
 				}
@@ -603,6 +607,7 @@ func adsHandler(c *gin.Context) {
603
 					log.WithField("request_id", dspInfo.RequestId).Infof("rsp1: %+v", customAdData)
607
 					log.WithField("request_id", dspInfo.RequestId).Infof("rsp1: %+v", customAdData)
604
 					jsonBytes, err := json.Marshal(customAdData)
608
 					jsonBytes, err := json.Marshal(customAdData)
605
 					if err != nil {
609
 					if err != nil {
610
+						log.WithField("request_id", dspInfo.RequestId).Errorf("marshal rsp1 custom ad failed: %s", err)
606
 						c.String(404, "marsha custom addata failed: %s", err.Error())
611
 						c.String(404, "marsha custom addata failed: %s", err.Error())
607
 						return
612
 						return
608
 					}
613
 					}
@@ -617,6 +622,7 @@ func adsHandler(c *gin.Context) {
617
 					graylog.ReportGrayLog(request, dspInfo, 0, 0)
622
 					graylog.ReportGrayLog(request, dspInfo, 0, 0)
618
 					rspBytes, err := json.Marshal(response)
623
 					rspBytes, err := json.Marshal(response)
619
 					if err != nil {
624
 					if err != nil {
625
+						log.WithField("request_id", dspInfo.RequestId).Errorf("marshal rsp1 failed: %s", err)
620
 						c.String(404, "marshal Response failed: %s", err.Error())
626
 						c.String(404, "marshal Response failed: %s", err.Error())
621
 						return
627
 						return
622
 					}
628
 					}
@@ -629,9 +635,11 @@ func adsHandler(c *gin.Context) {
629
 					graylog.ReportGrayLog(request, dspInfo, 0, 0)
635
 					graylog.ReportGrayLog(request, dspInfo, 0, 0)
630
 					rspBytes, err := json.Marshal(customAdData)
636
 					rspBytes, err := json.Marshal(customAdData)
631
 					if err != nil {
637
 					if err != nil {
638
+						log.WithField("request_id", dspInfo.RequestId).Errorf("marshal rsp2 failed: %s", err)
632
 						c.String(404, err.Error())
639
 						c.String(404, err.Error())
633
 						return
640
 						return
634
 					}
641
 					}
642
+					log.WithField("request_id", dspInfo.RequestId).Infof("rsp2: %s", rspBytes)
635
 					c.String(200, string(rspBytes))
643
 					c.String(200, string(rspBytes))
636
 					return
644
 					return
637
 				}
645
 				}
@@ -641,6 +649,7 @@ func adsHandler(c *gin.Context) {
641
 	redis_data.SetAdsRealRequestNum(advertiser)
649
 	redis_data.SetAdsRealRequestNum(advertiser)
642
 	rspBytes, err := json.Marshal(response)
650
 	rspBytes, err := json.Marshal(response)
643
 	if err != nil {
651
 	if err != nil {
652
+		log.WithField("request_id", dspInfo.RequestId).Errorf("marshal rsp3 failed: %s", err)
644
 		c.String(404, err.Error())
653
 		c.String(404, err.Error())
645
 		return
654
 		return
646
 	}
655
 	}

+ 13 - 10
adslib/addata/custom.go

@@ -54,6 +54,8 @@ func GetOneAds(dsp *utils.DspParam, orderType int, fixFlag int) (*redis_data.AdO
54
 	if err != nil {
54
 	if err != nil {
55
 		return nil, err
55
 		return nil, err
56
 	}
56
 	}
57
+
58
+	log.WithField("request_id", dsp.RequestId).Infof("get one ads, order len: %d", len(orders))
57
 	if len(orders) == 0 {
59
 	if len(orders) == 0 {
58
 		return nil, nil
60
 		return nil, nil
59
 	}
61
 	}
@@ -150,11 +152,12 @@ func GetCustomAdsInfos(dsp *utils.DspParam, orderType int, fixFlag int, xiaomiHa
150
 		log.WithField("request_id", dsp.RequestId).Errorf("get one ads failed: %s", err)
152
 		log.WithField("request_id", dsp.RequestId).Errorf("get one ads failed: %s", err)
151
 		return nil, err
153
 		return nil, err
152
 	}
154
 	}
155
+	log.WithField("request_id", dsp.RequestId).Infof("lat get one ad info, order: %+v, xiaomi has flag: %d", order, xiaomiHasFlag)
156
+
153
 	if order == nil {
157
 	if order == nil {
154
 		return nil, nil
158
 		return nil, nil
155
 	}
159
 	}
156
 
160
 
157
-	log.WithField("request_id", dsp.RequestId).Infof("begin got custom ad info, xiaomi has flag: %d", xiaomiHasFlag)
158
 	if xiaomiHasFlag == 1 {
161
 	if xiaomiHasFlag == 1 {
159
 		if strings.Index(order.Title, "_ios") > 0 {
162
 		if strings.Index(order.Title, "_ios") > 0 {
160
 			return nil, nil
163
 			return nil, nil
@@ -186,16 +189,17 @@ func GetCustomAdsInfos(dsp *utils.DspParam, orderType int, fixFlag int, xiaomiHa
186
 	rate := float32(order.ShowKpi) / float32(needDispatchCnt)
189
 	rate := float32(order.ShowKpi) / float32(needDispatchCnt)
187
 
190
 
188
 	lineValue := 0
191
 	lineValue := 0
192
+	key := ""
189
 	if order.LineType == 1 {
193
 	if order.LineType == 1 {
190
 		// 订单定制曲线
194
 		// 订单定制曲线
191
-		lineValue, err = redis_data.GetOrderPerMinuteNeedDispatchCnt(order.OrderID, curTime)
195
+		lineValue, key, err = redis_data.GetOrderPerMinuteNeedDispatchCnt(order.OrderID, curTime)
192
 	} else {
196
 	} else {
193
-		lineValue, err = redis_data.GetPerMinuteNeedDispatchCnt(curTime)
197
+		lineValue, key, err = redis_data.GetPerMinuteNeedDispatchCnt(curTime)
194
 	}
198
 	}
195
 	if err != nil {
199
 	if err != nil {
196
 		return nil, err
200
 		return nil, err
197
 	}
201
 	}
198
-	log.WithField("request_id", dsp.RequestId).Infof("line value: %d, rate: %f", lineValue, rate)
202
+	log.WithField("request_id", dsp.RequestId).Infof("key: %s, line value: %d, rate: %f", key, lineValue, rate)
199
 
203
 
200
 	// 当前分钟需要放出去的数量
204
 	// 当前分钟需要放出去的数量
201
 	curMinuteNeedDispatchCnt := int(float32(lineValue) * rate)
205
 	curMinuteNeedDispatchCnt := int(float32(lineValue) * rate)
@@ -205,11 +209,10 @@ func GetCustomAdsInfos(dsp *utils.DspParam, orderType int, fixFlag int, xiaomiHa
205
 
209
 
206
 	redis_data.SetOrderPlanDispatchCount(order.OrderID, "show", curMinuteNeedDispatchCnt, curTime)
210
 	redis_data.SetOrderPlanDispatchCount(order.OrderID, "show", curMinuteNeedDispatchCnt, curTime)
207
 
211
 
208
-	log.WithField("request_id", dsp.RequestId).Infof("tt thirds: %+v", order)
209
 	// 获取当前分钟已经完成的下发
212
 	// 获取当前分钟已经完成的下发
210
-	curMinuteFinishedDispatchCnt, err := redis_data.GetPreMinuteFinishedDispatchCount(order.OrderID, "show", curTime)
213
+	curMinuteFinishedDispatchCnt, key, err := redis_data.GetPreMinuteFinishedDispatchCount(order.OrderID, "show", curTime)
211
 
214
 
212
-	log.WithField("request_id", dsp.RequestId).Infof("o value: %d, w value: %d", curMinuteFinishedDispatchCnt, curMinuteNeedDispatchCnt)
215
+	log.WithField("request_id", dsp.RequestId).Infof("o value: %s, %d, w value: %d", key, curMinuteFinishedDispatchCnt, curMinuteNeedDispatchCnt)
213
 	if curMinuteFinishedDispatchCnt < curMinuteNeedDispatchCnt {
216
 	if curMinuteFinishedDispatchCnt < curMinuteNeedDispatchCnt {
214
 		data := AdData{
217
 		data := AdData{
215
 			Duration:  5,
218
 			Duration:  5,
@@ -219,11 +222,11 @@ func GetCustomAdsInfos(dsp *utils.DspParam, orderType int, fixFlag int, xiaomiHa
219
 		}
222
 		}
220
 
223
 
221
 		//放量
224
 		//放量
222
-		_, err := redis_data.IncrFinishedDispatchCount(order.OrderID, "show", 1, curTime)
225
+		_, err := redis_data.IncrFinishedDispatchCount(order.OrderID, "show", curTime)
223
 		if err != nil {
226
 		if err != nil {
224
 			return nil, err
227
 			return nil, err
225
 		}
228
 		}
226
-		_, err = redis_data.IncrPreMinuteFinishedDispatchCount(order.OrderID, "show", 1, curTime)
229
+		_, err = redis_data.IncrPreMinuteFinishedDispatchCount(order.OrderID, "show", curTime)
227
 		if err != nil {
230
 		if err != nil {
228
 			return nil, err
231
 			return nil, err
229
 		}
232
 		}
@@ -326,7 +329,7 @@ func GetCustomAdsInfos(dsp *utils.DspParam, orderType int, fixFlag int, xiaomiHa
326
 			addi = genMonitorAction("CLICK", order.Title, dsp.ReqSource, clickUrl)
329
 			addi = genMonitorAction("CLICK", order.Title, dsp.ReqSource, clickUrl)
327
 			data.TargetAddition = append(data.TargetAddition, *addi)
330
 			data.TargetAddition = append(data.TargetAddition, *addi)
328
 			md5Skip := utils.Md5(targetUrl)
331
 			md5Skip := utils.Md5(targetUrl)
329
-			_, err = redis_data.IncrFinishedDispatchCount(order.OrderID, "click", 1, curTime)
332
+			_, err = redis_data.IncrFinishedDispatchCount(order.OrderID, "click", curTime)
330
 			if err != nil {
333
 			if err != nil {
331
 				log.WithField("request_id", dsp.RequestId).Errorf("incr finished dispatch count failed: %s", err)
334
 				log.WithField("request_id", dsp.RequestId).Errorf("incr finished dispatch count failed: %s", err)
332
 			}
335
 			}

+ 3 - 8
adslib/ads_redis/redis.go

@@ -14,9 +14,9 @@ func Setup() error {
14
 	host := adslib.GetConf().RedisHost
14
 	host := adslib.GetConf().RedisHost
15
 	password := adslib.GetConf().RedisPassword
15
 	password := adslib.GetConf().RedisPassword
16
 	RedisConn = &redis.Pool{
16
 	RedisConn = &redis.Pool{
17
-		MaxIdle:     10,
18
-		MaxActive:   10,
19
-		IdleTimeout: 50,
17
+		MaxIdle:     20,
18
+		MaxActive:   50,
19
+		IdleTimeout: 3 * time.Minute,
20
 		Dial: func() (redis.Conn, error) {
20
 		Dial: func() (redis.Conn, error) {
21
 			c, err := redis.Dial("tcp", host)
21
 			c, err := redis.Dial("tcp", host)
22
 			if err != nil {
22
 			if err != nil {
@@ -32,11 +32,6 @@ func Setup() error {
32
 			}
32
 			}
33
 			return c, err
33
 			return c, err
34
 		},
34
 		},
35
-		TestOnBorrow: func(c redis.Conn, t time.Time) error {
36
-			_, err := c.Do("PING")
37
-			fmt.Println(err)
38
-			return err
39
-		},
40
 	}
35
 	}
41
 
36
 
42
 	return nil
37
 	return nil

+ 1 - 0
adslib/config.go

@@ -26,6 +26,7 @@ type SvrConf struct {
26
 	LogPath            string                                `toml:"log_path"`
26
 	LogPath            string                                `toml:"log_path"`
27
 	RedisHost          string                                `toml:"redis_host"`
27
 	RedisHost          string                                `toml:"redis_host"`
28
 	RedisPassword      string                                `toml:"redis_password"`
28
 	RedisPassword      string                                `toml:"redis_password"`
29
+	LogLevel           string                                `toml:"log_level"`
29
 }
30
 }
30
 type FlogControlItem struct {
31
 type FlogControlItem struct {
31
 	Percent  int `toml:"percent"`
32
 	Percent  int `toml:"percent"`

+ 3 - 3
adslib/graylog/graylog.go

@@ -16,9 +16,9 @@ var grayLog *gelf.Gelf
16
 
16
 
17
 func init() {
17
 func init() {
18
 	grayLog = gelf.New(gelf.Config{
18
 	grayLog = gelf.New(gelf.Config{
19
-		GraylogPort:     62001,
20
-		GraylogHostname: "172.18.138.7",
21
-		Connection:      "wan",
19
+		GraylogPort:     62002,
20
+		GraylogHostname: "172.18.199.72",
21
+		Connection:      "lan",
22
 		MaxChunkSizeWan: 42,
22
 		MaxChunkSizeWan: 42,
23
 		MaxChunkSizeLan: 1337,
23
 		MaxChunkSizeLan: 1337,
24
 	})
24
 	})

+ 2 - 1
adslib/redis_data/order.go

@@ -113,6 +113,7 @@ func GetOrderInfos(dsp *utils.DspParam, fixFlag int) ([]AdOrderInfo, error) {
113
 					}
113
 					}
114
 				}
114
 				}
115
 				if !isValidChannel {
115
 				if !isValidChannel {
116
+					log.WithField("request_id", dsp.RequestId).Tracef("not valid channel ad: %+v", order)
116
 					continue
117
 					continue
117
 				}
118
 				}
118
 			}
119
 			}
@@ -153,7 +154,7 @@ func GetOrderInfos(dsp *utils.DspParam, fixFlag int) ([]AdOrderInfo, error) {
153
 		}
154
 		}
154
 
155
 
155
 		if !needInsert {
156
 		if !needInsert {
156
-			return []AdOrderInfo{}, nil
157
+			continue
157
 		}
158
 		}
158
 
159
 
159
 		if dsp != nil {
160
 		if dsp != nil {

+ 20 - 18
adslib/redis_data/redis_data.go

@@ -312,12 +312,12 @@ func GetFinishedDispatchCount(orderId int64, dispatchType string, curTime time.T
312
 
312
 
313
 // 增加已经投放的量
313
 // 增加已经投放的量
314
 // dispatchType: "click", "show"
314
 // dispatchType: "click", "show"
315
-func IncrFinishedDispatchCount(orderId int64, dispatchType string, incrCnt int, curTime time.Time) (int, error) {
315
+func IncrFinishedDispatchCount(orderId int64, dispatchType string, curTime time.Time) (int, error) {
316
 	conn := ads_redis.RedisConn.Get()
316
 	conn := ads_redis.RedisConn.Get()
317
 	defer conn.Close()
317
 	defer conn.Close()
318
 
318
 
319
 	key := fmt.Sprintf("order_kpi_%d_%d%d%d_%s_kpi", orderId, curTime.Year(), curTime.Month(), curTime.Day(), dispatchType)
319
 	key := fmt.Sprintf("order_kpi_%d_%d%d%d_%s_kpi", orderId, curTime.Year(), curTime.Month(), curTime.Day(), dispatchType)
320
-	rsp, err := conn.Do("INCR", key, incrCnt)
320
+	rsp, err := conn.Do("INCR", key)
321
 	if err != nil {
321
 	if err != nil {
322
 		return 0, err
322
 		return 0, err
323
 	}
323
 	}
@@ -328,35 +328,34 @@ func IncrFinishedDispatchCount(orderId int64, dispatchType string, incrCnt int,
328
 
328
 
329
 // 获取当前分钟已经投放的量
329
 // 获取当前分钟已经投放的量
330
 // dispatchType: "click", "show"
330
 // dispatchType: "click", "show"
331
-func GetPreMinuteFinishedDispatchCount(orderId int64, dispatchType string, curTime time.Time) (int, error) {
331
+func GetPreMinuteFinishedDispatchCount(orderId int64, dispatchType string, curTime time.Time) (int, string, error) {
332
 	conn := ads_redis.RedisConn.Get()
332
 	conn := ads_redis.RedisConn.Get()
333
 	defer conn.Close()
333
 	defer conn.Close()
334
 
334
 
335
 	curMinutes := curTime.Hour()*60 + curTime.Minute()
335
 	curMinutes := curTime.Hour()*60 + curTime.Minute()
336
 	key := fmt.Sprintf("order_kpi_%d_%d%d%d_%d_%s_kpi", orderId, curTime.Year(), curTime.Month(), curTime.Day(), curMinutes, dispatchType)
336
 	key := fmt.Sprintf("order_kpi_%d_%d%d%d_%d_%s_kpi", orderId, curTime.Year(), curTime.Month(), curTime.Day(), curMinutes, dispatchType)
337
 	rsp, err := conn.Do("GET", key)
337
 	rsp, err := conn.Do("GET", key)
338
-	log.Infof("%s %s", key, rsp)
339
 	if err != nil {
338
 	if err != nil {
340
-		return 0, err
339
+		return 0, key, err
341
 	}
340
 	}
342
 
341
 
343
 	if rsp == nil {
342
 	if rsp == nil {
344
-		return 0, nil
343
+		return 0, key, nil
345
 	}
344
 	}
346
 
345
 
347
 	count, _ := redis.Int(rsp, err)
346
 	count, _ := redis.Int(rsp, err)
348
-	return count, nil
347
+	return count, key, nil
349
 }
348
 }
350
 
349
 
351
 // 增加当前分钟已经投放的量
350
 // 增加当前分钟已经投放的量
352
 // dispatchType: "click", "show"
351
 // dispatchType: "click", "show"
353
-func IncrPreMinuteFinishedDispatchCount(orderId int64, dispatchType string, incrCnt int, curTime time.Time) (int, error) {
352
+func IncrPreMinuteFinishedDispatchCount(orderId int64, dispatchType string, curTime time.Time) (int, error) {
354
 	conn := ads_redis.RedisConn.Get()
353
 	conn := ads_redis.RedisConn.Get()
355
 	defer conn.Close()
354
 	defer conn.Close()
356
 
355
 
357
 	curMinutes := curTime.Hour()*60 + curTime.Minute()
356
 	curMinutes := curTime.Hour()*60 + curTime.Minute()
358
 	key := fmt.Sprintf("order_kpi_%d_%d%d%d_%d_%s_kpi", orderId, curTime.Year(), curTime.Month(), curTime.Day(), curMinutes, dispatchType)
357
 	key := fmt.Sprintf("order_kpi_%d_%d%d%d_%d_%s_kpi", orderId, curTime.Year(), curTime.Month(), curTime.Day(), curMinutes, dispatchType)
359
-	rsp, err := conn.Do("INCR", key, incrCnt)
358
+	rsp, err := conn.Do("INCR", key)
360
 	if err != nil {
359
 	if err != nil {
361
 		return 0, err
360
 		return 0, err
362
 	}
361
 	}
@@ -386,7 +385,7 @@ func SetOrderPlanDispatchCount(orderId int64, dispatchType string, cnt int, curT
386
 }
385
 }
387
 
386
 
388
 // 获取总量每分钟要投放的量
387
 // 获取总量每分钟要投放的量
389
-func GetPerMinuteNeedDispatchCnt(curTime time.Time) (int, error) {
388
+func GetPerMinuteNeedDispatchCnt(curTime time.Time) (int, string, error) {
390
 	conn := ads_redis.RedisConn.Get()
389
 	conn := ads_redis.RedisConn.Get()
391
 	defer conn.Close()
390
 	defer conn.Close()
392
 
391
 
@@ -395,19 +394,19 @@ func GetPerMinuteNeedDispatchCnt(curTime time.Time) (int, error) {
395
 	rsp, err := conn.Do("GET", key)
394
 	rsp, err := conn.Do("GET", key)
396
 
395
 
397
 	if err != nil {
396
 	if err != nil {
398
-		return 0, err
397
+		return 0, key, err
399
 	}
398
 	}
400
 
399
 
401
 	if rsp == nil {
400
 	if rsp == nil {
402
-		return 0, nil
401
+		return 0, key, nil
403
 	}
402
 	}
404
 
403
 
405
 	count, _ := redis.Int(rsp, err)
404
 	count, _ := redis.Int(rsp, err)
406
-	return count, nil
405
+	return count, key, nil
407
 }
406
 }
408
 
407
 
409
 // 获取订单每分钟要投放的量
408
 // 获取订单每分钟要投放的量
410
-func GetOrderPerMinuteNeedDispatchCnt(orderId int64, curTime time.Time) (int, error) {
409
+func GetOrderPerMinuteNeedDispatchCnt(orderId int64, curTime time.Time) (int, string, error) {
411
 	conn := ads_redis.RedisConn.Get()
410
 	conn := ads_redis.RedisConn.Get()
412
 	defer conn.Close()
411
 	defer conn.Close()
413
 
412
 
@@ -416,15 +415,15 @@ func GetOrderPerMinuteNeedDispatchCnt(orderId int64, curTime time.Time) (int, er
416
 	rsp, err := conn.Do("GET", key)
415
 	rsp, err := conn.Do("GET", key)
417
 
416
 
418
 	if err != nil {
417
 	if err != nil {
419
-		return 0, err
418
+		return 0, key, err
420
 	}
419
 	}
421
 
420
 
422
 	if rsp == nil {
421
 	if rsp == nil {
423
-		return 0, nil
422
+		return 0, key, nil
424
 	}
423
 	}
425
 
424
 
426
 	count, _ := redis.Int(rsp, err)
425
 	count, _ := redis.Int(rsp, err)
427
-	return count, nil
426
+	return count, key, nil
428
 }
427
 }
429
 
428
 
430
 // 获取ios的ua和imei
429
 // 获取ios的ua和imei
@@ -464,8 +463,11 @@ func GetIosUaImei(ip string) (string, string, error) {
464
 		Imei string
463
 		Imei string
465
 		Ua   string
464
 		Ua   string
466
 	}
465
 	}
466
+
467
 	rspBytes, _ := redis.Bytes(rsp, err)
467
 	rspBytes, _ := redis.Bytes(rsp, err)
468
-	err = json.Unmarshal(rspBytes, &uaImeiInfo)
468
+	rspStr := strings.ReplaceAll(string(rspBytes), "'", "\"")
469
+
470
+	err = json.Unmarshal([]byte(rspStr), &uaImeiInfo)
469
 	if err != nil {
471
 	if err != nil {
470
 		return "", "", err
472
 		return "", "", err
471
 	}
473
 	}

+ 1 - 0
conf/config.toml

@@ -12,6 +12,7 @@ ip2region_file = "../conf/ip2region_20200113.db"
12
 log_path = "../log"
12
 log_path = "../log"
13
 redis_host="r-wz9sbx1faq7j6zxxgt.redis.rds.aliyuncs.com:6379"
13
 redis_host="r-wz9sbx1faq7j6zxxgt.redis.rds.aliyuncs.com:6379"
14
 redis_password="3iXAJFuI$J"
14
 redis_password="3iXAJFuI$J"
15
+log_level=trace
15
 
16
 
16
 
17
 
17
 ## 流量占比控制
18
 ## 流量占比控制

+ 1 - 0
go.mod

@@ -8,6 +8,7 @@ require (
8
 	github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
8
 	github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
9
 	github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
9
 	github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
10
 	github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6
10
 	github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6
11
+	github.com/gin-contrib/pprof v1.3.0
11
 	github.com/gin-gonic/gin v1.6.3
12
 	github.com/gin-gonic/gin v1.6.3
12
 	github.com/gomodule/redigo v2.0.0+incompatible
13
 	github.com/gomodule/redigo v2.0.0+incompatible
13
 	github.com/jarcoal/httpmock v1.0.5
14
 	github.com/jarcoal/httpmock v1.0.5

+ 3 - 0
go.sum

@@ -11,8 +11,11 @@ github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 h1:Ghm4eQYC0nEPnSJ
11
 github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239/go.mod h1:Gdwt2ce0yfBxPvZrHkprdPPTTS3N5rwmLE8T22KBXlw=
11
 github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239/go.mod h1:Gdwt2ce0yfBxPvZrHkprdPPTTS3N5rwmLE8T22KBXlw=
12
 github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6 h1:6VSn3hB5U5GeA6kQw4TwWIWbOhtvR2hmbBJnTOtqTWc=
12
 github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6 h1:6VSn3hB5U5GeA6kQw4TwWIWbOhtvR2hmbBJnTOtqTWc=
13
 github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6/go.mod h1:YxOVT5+yHzKvwhsiSIWmbAYM3Dr9AEEbER2dVayfBkg=
13
 github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6/go.mod h1:YxOVT5+yHzKvwhsiSIWmbAYM3Dr9AEEbER2dVayfBkg=
14
+github.com/gin-contrib/pprof v1.3.0 h1:G9eK6HnbkSqDZBYbzG4wrjCsA4e+cvYAHUZw6W+W9K0=
15
+github.com/gin-contrib/pprof v1.3.0/go.mod h1:waMjT1H9b179t3CxuG1cV3DHpga6ybizwfBaM5OXaB0=
14
 github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
16
 github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
15
 github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
17
 github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
18
+github.com/gin-gonic/gin v1.6.2/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
16
 github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14=
19
 github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14=
17
 github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
20
 github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
18
 github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
21
 github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=

+ 9 - 2
main_linux.go

@@ -10,6 +10,7 @@ import (
10
 	"time"
10
 	"time"
11
 
11
 
12
 	"github.com/fvbock/endless"
12
 	"github.com/fvbock/endless"
13
+	"github.com/gin-contrib/pprof"
13
 	log "github.com/sirupsen/logrus"
14
 	log "github.com/sirupsen/logrus"
14
 )
15
 )
15
 
16
 
@@ -40,6 +41,7 @@ func setupLogger(logName string, logLevel log.Level) {
40
 
41
 
41
 func setupRouter() *gin.Engine {
42
 func setupRouter() *gin.Engine {
42
 	r := gin.Default()
43
 	r := gin.Default()
44
+	pprof.Register(r) // 性能
43
 
45
 
44
 	r.POST("/ads", adsHandler)
46
 	r.POST("/ads", adsHandler)
45
 	return r
47
 	return r
@@ -47,8 +49,13 @@ func setupRouter() *gin.Engine {
47
 
49
 
48
 func main() {
50
 func main() {
49
 	ads_redis.Setup()
51
 	ads_redis.Setup()
50
-	adslib.GetConf()
51
-	setupLogger(adslib.GetConf().LogPath+"/ads.log", log.TraceLevel)
52
+	conf := adslib.GetConf()
53
+	logLevel, err := log.ParseLevel(conf.LogLevel)
54
+	if err != nil {
55
+		log.Errorf("parse log level failed, use info level, log str: %s, err: %s", conf.LogLevel, err)
56
+		logLevel = log.InfoLevel
57
+	}
58
+	setupLogger(conf.LogPath+"/ads.log", logLevel)
52
 
59
 
53
 	r := setupRouter()
60
 	r := setupRouter()
54
 	endless.ListenAndServe(":1111", r)
61
 	endless.ListenAndServe(":1111", r)