Writer 修改:压缩时后缀变为微秒级别 + 按大小切割时考虑缓冲区中未写入的数据 + appendInt 疑似为重复代码 #346
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
您好最近我正在学习您的框架,仔细阅读了zutils/writer.go中的代码,发现了一下几个可能可以被优化的地方:
Writer
写入大量数据的时候可能造成多次rotate
,即造成多次按照大小切割。而其中os.Create
创建压缩日志文件的方法会覆盖已经存在的文件,从而丢失写入的日志。我做了如下实验:将sizeMiB
改为1KB,然后如右图模拟短时间内大量日志写入。会出现明显的日志丢失问题。所以我考虑是否能将压缩日志的后缀增加到微秒级别,从而尽量避免覆盖,具体实现如下面第二张图。w.bw
缓冲区中未写入文件的数据大小,修改如下图:appendInt
函数是否可以被删除,因为下面这部分代码的实现逻辑和t.AppendFormat(nil, time.RFC33391)
的逻辑相同,而且w.creates
生成的时候也是调用的AppendFormat
方法。