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

opt: improve logx performance #3371

Merged
merged 3 commits into from
Jun 25, 2023
Merged

Conversation

kevwan
Copy link
Contributor

@kevwan kevwan commented Jun 25, 2023

No description provided.

@codecov
Copy link

codecov bot commented Jun 25, 2023

Codecov Report

Merging #3371 (3ef5707) into master (8d23ab1) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted Files Coverage Δ
core/logx/logs.go 98.91% <100.00%> (+0.13%) ⬆️

... and 1 file with indirect coverage changes

@kevwan kevwan force-pushed the feat/log-optimize branch from 98131b8 to b739331 Compare June 25, 2023 06:45
@kevwan
Copy link
Contributor Author

kevwan commented Jun 25, 2023

Benchmark code as below:

package main

import (
	"flag"
	"time"

	"github.com/kevwan/gobench"
	"github.com/zeromicro/go-zero/core/conf"
	"github.com/zeromicro/go-zero/core/logx"
)

const (
	config = `Name: bench
Mode: file
Level: error
Path: logs
`
	text = `The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.`
)

var (
	duration = flag.Duration("duration", time.Minute, "duration")
	qps      = flag.Int("qps", 10000, "qps")
)

func main() {
	flag.Parse()

	var c logx.LogConf
	logx.Must(conf.LoadFromYamlBytes([]byte(config), &c))
	logx.MustSetup(c)

	for i := 0; i < 100; i++ {
		logx.Info(text)
	}

	b := gobench.NewBenchWithConfig(gobench.Config{
		Duration: *duration,
	})
	b.Run(*qps, func() {
		for i := 0; i < 100; i++ {
			logx.Info(text)
		}
		logx.Error(text)
	})
}

Before optimization:
image

After optimization:
image

Copy link
Member

@chenquan chenquan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kevwan kevwan force-pushed the feat/log-optimize branch from b739331 to 3ef5707 Compare June 25, 2023 07:31
@kevwan kevwan merged commit 92e5819 into zeromicro:master Jun 25, 2023
@kevwan kevwan deleted the feat/log-optimize branch June 25, 2023 15:48
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