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

refactor to optimize dnsmessage function #632

Merged
merged 5 commits into from
Mar 3, 2024
Merged

Conversation

dmachard
Copy link
Owner

@dmachard dmachard commented Mar 2, 2024

Optimize the Flatten function of the DNSMessage to reduce CPU usage.

Before

./dnsutils$ go test -bench=.
goos: linux
goarch: amd64
pkg: github.com/dmachard/go-dnscollector/dnsutils
cpu: Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
BenchmarkDnsMessage_ToDNSTap-4                    836766              1229 ns/op
BenchmarkDnsMessage_ToExtendedDNSTap-4            520940              2116 ns/op
BenchmarkDnsMessage_ToJSON-4              167796              6910 ns/op
BenchmarkDnsMessage_ToFlatJSON-4            6794            172489 ns/op
BenchmarkDnsMessage_ToTextFormat-4                732069              1457 ns/op
BenchmarkDnsMessage_ToPacketLayer-4              1171467               969.5 ns/op
PASS
ok      github.com/dmachard/go-dnscollector/dnsutils    2.056s

After refactor with default configuration:

./dnsutils$ go test -bench=.
goos: linux
goarch: amd64
pkg: github.com/dmachard/go-dnscollector/dnsutils
cpu: Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
BenchmarkDnsMessage_ToDNSTap-4                    993242              1130 ns/op
BenchmarkDnsMessage_ToExtendedDNSTap-4            618400              1951 ns/op
BenchmarkDnsMessage_ToJSON-4                      190939              6584 ns/op
BenchmarkDnsMessage_ToFlatJSON-4                   19868             55533 ns/op
BenchmarkDnsMessage_ToTextFormat-4               2600718               460.7 ns/op
BenchmarkDnsMessage_ToPacketLayer-4              1171467               969.5 ns/op
PASS
ok      github.com/dmachard/go-dnscollector/dnsutils    1.810s

@dmachard dmachard changed the title refactor dnsmessage flatten function refactor to optimize dnsmessage flatten function Mar 2, 2024
@dmachard dmachard changed the title refactor to optimize dnsmessage flatten function refactor to optimize dnsmessage function Mar 2, 2024
@dmachard dmachard merged commit 30790c2 into main Mar 3, 2024
61 checks passed
@dmachard dmachard deleted the dnsmessage-flatten branch March 4, 2024 07:49
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.

1 participant