Repository navigation
csv,grok,json,ngnix parser添加多线程 - #709
Conversation
7fe4d33 to
cec6521
Compare
f1ff457 to
706b030
Compare
| } | ||
| if conf.MaxProcs == 0 { | ||
| conf.MaxProcs = runtime.NumCPU() | ||
| conf.MaxProcs = NumCpu |
| allmoreStartNUmber int | ||
| allowNotMatch bool | ||
| ignoreInvalid bool | ||
| routineNumber int |
There was a problem hiding this comment.
routineNumber 听起来像某个任务号,建议改叫 numRoutines,其它地方也是
|
|
||
| "sync" | ||
|
|
||
| "sort" |
2f2d5a6 to
8911b8b
Compare
| ) | ||
|
|
||
| var ( | ||
| MaxProcs = 0 |
| return err == nil || os.IsExist(err) | ||
| } | ||
|
|
||
| func GetTestData(line string) []string { |
There was a problem hiding this comment.
这个方法本身的含义是复制数据到默认的maxBatchSize,应该以函数本身的含义命名函数。然后这个函数主要用于测试,这一点可以写在注释上。
| allmoreStartNumber, _ := c.GetIntOr(parser.KeyCSVAllowMoreStartNum, 0) | ||
| ignoreInvalid, _ := c.GetBoolOr(parser.KeyCSVIgnoreInvalidField, false) | ||
| numRoutine := MaxProcs | ||
| if numRoutine == 0 { |
There was a problem hiding this comment.
理论上MaxProcs不可能是0,如果是0,那么代表哪里出bug了,那我建议这里的numRoutine也不用跑飞,只要设置为1保持稳妥就好了
| return newData | ||
| } | ||
|
|
||
| func (p *Parser) RenameData(data Data) Data { |
There was a problem hiding this comment.
上面的Rename应该调用你这个RenameData方法。另外这个方法不用挂到(p *Parser)下面,还能方便一下测试
| return dataSlice, nil | ||
| } | ||
|
|
||
| func (p *Parser) parseLine(sendChan chan parser.ParseInfo, resultChan chan parser.ParseResult, wg *sync.WaitGroup) { |
There was a problem hiding this comment.
你这个sendChan 应该叫 dataPipeline,那一头是send,这一头实际上是receive,另外channel类型也可以设置为receive only : <-chan
There was a problem hiding this comment.
另外这里为什么要单独写一个,我看parser包里有一个
There was a problem hiding this comment.
这个和别的parse不一样,这边返回的是数组,别的不是,json会返回数组
|
LGTM |
| // label 不覆盖数据,其他parser不需要这么一步检验,因为Schema固定,json的Schema不固定 | ||
| if _, ok := data[l.Name]; ok { | ||
| continue | ||
| func (p *Parser) parse(line string) (dataSlice []Data, err error) { |
5cde0ce to
1f0b5d4
Compare
|
Unbuntu Parse Test GROK, data: 1GB ParseTime(ns) CSV, data: 1GB ParseTime(ns) NGNIX data: 1GB ParseTime(ns) JSON data: 1GB ParseTime(ns) |
93eadfd to
8939a44
Compare
| for resultInfo := range resultChan { | ||
| parseResultSlice = append(parseResultSlice, resultInfo) | ||
| } | ||
| sort.Stable(parseResultSlice) |
There was a problem hiding this comment.
所有sort的地方加个判断,如果 routine==1,不做这个sort
8752cdb to
5cb09b8
Compare
| for resultInfo := range resultChan { | ||
| parseResultSlice = append(parseResultSlice, resultInfo) | ||
| } | ||
| if len(parseResultSlice) > 1 { |
There was a problem hiding this comment.
应该是判断Routine而不是slice,slice表达的是解析的这批数据量大小,单个Routine出来的slice可以很长,但是已经有序
| if err != nil { | ||
|
|
||
| if parseResult.Err != nil { | ||
| log.Debug(parseResult.Err) |
| se.AddSuccess() | ||
|
|
||
| if parseResult.Err != nil { | ||
| log.Debug(parseResult.Err) |
| Line: parseInfo.Line, | ||
| Index: parseInfo.Index, | ||
| } | ||
| continue |
There was a problem hiding this comment.
对, DatasourceSkipIndex 需要记录
|
LGTM |
@wonderflow
@unknwon