Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writer 修改:压缩时后缀变为微秒级别 + 按大小切割时考虑缓冲区中未写入的数据 + appendInt 疑似为重复代码 #346

Merged
merged 1 commit into from
Dec 9, 2024

Conversation

yuyuyu258963
Copy link
Contributor

您好最近我正在学习您的框架,仔细阅读了zutils/writer.go中的代码,发现了一下几个可能可以被优化的地方:

  • 当1s内通过Writer写入大量数据的时候可能造成多次rotate,即造成多次按照大小切割。而其中os.Create创建压缩日志文件的方法会覆盖已经存在的文件,从而丢失写入的日志。我做了如下实验:将sizeMiB改为1KB,然后如右图模拟短时间内大量日志写入。会出现明显的日志丢失问题。所以我考虑是否能将压缩日志的后缀增加到微秒级别,从而尽量避免覆盖,具体实现如下面第二张图。
    1731683295050
    2
  • 在按照大小切割的时候是否需要考虑w.bw缓冲区中未写入文件的数据大小,修改如下图:
    3
  • appendInt函数是否可以被删除,因为下面这部分代码的实现逻辑和t.AppendFormat(nil, time.RFC33391)的逻辑相同,而且w.creates生成的时候也是调用的AppendFormat方法。
    4

@aceld
Copy link
Owner

aceld commented Nov 18, 2024

@yuyuyu258963 感谢提交PR,以及提供的建议和修改办法~

@aceld
Copy link
Owner

aceld commented Nov 18, 2024

@xxl6097 这块协助review下

@aceld
Copy link
Owner

aceld commented Dec 9, 2024

@yuyuyu258963 感谢提交PR!

@aceld aceld merged commit c24917b into aceld:master Dec 9, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants