Commit 7cdc868d by 孙龙

init

parent 133cfdd8
Showing with 6 additions and 6 deletions
...@@ -45,10 +45,12 @@ func (logSink *LogSink) writeLoop() { ...@@ -45,10 +45,12 @@ func (logSink *LogSink) writeLoop() {
var ( var (
log *DataParams log *DataParams
logBatch *LogBatch // 当前的批次 logBatch *LogBatch // 当前的批次
commitTimer *time.Timer //commitTimer *time.Timer
//timeoutBatch *LogBatch // 超时批次 //timeoutBatch *LogBatch // 超时批次
) )
t := time.NewTimer(time.Second * 20)
defer t.Stop()
for { for {
select { select {
case log = <- logSink.logChan: case log = <- logSink.logChan:
...@@ -59,17 +61,14 @@ func (logSink *LogSink) writeLoop() { ...@@ -59,17 +61,14 @@ func (logSink *LogSink) writeLoop() {
// 把新日志追加到批次中 // 把新日志追加到批次中
logBatch.Logs = append(logBatch.Logs, log) logBatch.Logs = append(logBatch.Logs, log)
// 如果批次满了, 就立即发送 // 如果批次满了, 就立即发送
if len(logBatch.Logs) >= 10 { if len(logBatch.Logs) >= 100 {
// 发送日志 // 发送日志
logSink.saveLogs(logBatch) logSink.saveLogs(logBatch)
// 清空logBatch // 清空logBatch
logBatch = nil logBatch = nil
// 取消定时器
//commitTimer.Stop()
} }
case <- time.NewTimer(1*time.Second).C: case <- t.C:
if logBatch == nil { if logBatch == nil {
logBatch = &LogBatch{} logBatch = &LogBatch{}
} }
...@@ -77,6 +76,7 @@ func (logSink *LogSink) writeLoop() { ...@@ -77,6 +76,7 @@ func (logSink *LogSink) writeLoop() {
fmt.Println(len(logBatch.Logs)) fmt.Println(len(logBatch.Logs))
logSink.saveLogs(logBatch) logSink.saveLogs(logBatch)
logBatch = nil logBatch = nil
t.Reset(time.Second * 20)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment