Commit 7cdc868d by 孙龙

init

parent 133cfdd8
Showing with 6 additions and 6 deletions
......@@ -45,10 +45,12 @@ func (logSink *LogSink) writeLoop() {
var (
log *DataParams
logBatch *LogBatch // 当前的批次
commitTimer *time.Timer
//commitTimer *time.Timer
//timeoutBatch *LogBatch // 超时批次
)
t := time.NewTimer(time.Second * 20)
defer t.Stop()
for {
select {
case log = <- logSink.logChan:
......@@ -59,17 +61,14 @@ func (logSink *LogSink) writeLoop() {
// 把新日志追加到批次中
logBatch.Logs = append(logBatch.Logs, log)
// 如果批次满了, 就立即发送
if len(logBatch.Logs) >= 10 {
if len(logBatch.Logs) >= 100 {
// 发送日志
logSink.saveLogs(logBatch)
// 清空logBatch
logBatch = nil
// 取消定时器
//commitTimer.Stop()
}
case <- time.NewTimer(1*time.Second).C:
case <- t.C:
if logBatch == nil {
logBatch = &LogBatch{}
}
......@@ -77,6 +76,7 @@ func (logSink *LogSink) writeLoop() {
fmt.Println(len(logBatch.Logs))
logSink.saveLogs(logBatch)
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