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

Move the go-ipfix tag after adding performance fixes #2574

Merged
merged 1 commit into from Aug 13, 2021

Conversation

srikartati
Copy link
Member

@srikartati srikartati commented Aug 11, 2021

Performance fixes for memory fragmentation issue in go-ipfix. Moving the release tag of go-ipfix.

@srikartati srikartati force-pushed the patch_flow_agg branch 4 times, most recently from 3ad510f to 39bd139 Compare August 11, 2021 16:34
@lgtm-com
Copy link

lgtm-com bot commented Aug 11, 2021

This pull request introduces 90 alerts when merging 39bd139 into fe4457f - view on LGTM.com

new alerts:

  • 90 for Useless assignment to field

@srikartati srikartati marked this pull request as draft August 11, 2021 17:13
@srikartati srikartati marked this pull request as ready for review August 11, 2021 20:45
@codecov-commenter
Copy link

codecov-commenter commented Aug 11, 2021

Codecov Report

Merging #2574 (7d758ef) into main (535b7a3) will increase coverage by 0.08%.
The diff coverage is 95.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2574      +/-   ##
==========================================
+ Coverage   60.10%   60.18%   +0.08%     
==========================================
  Files         282      282              
  Lines       22337    22345       +8     
==========================================
+ Hits        13426    13449      +23     
+ Misses       7491     7480      -11     
+ Partials     1420     1416       -4     
Flag Coverage Δ
e2e-tests ∅ <ø> (?)
kind-e2e-tests 47.09% <95.00%> (+0.15%) ⬆️
unit-tests 42.16% <30.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/flowaggregator/flowaggregator.go 64.72% <94.11%> (+0.78%) ⬆️
pkg/agent/flowexporter/exporter/exporter.go 80.23% <100.00%> (+0.09%) ⬆️
...g/agent/apiserver/handlers/featuregates/handler.go 0.00% <0.00%> (-82.36%) ⬇️
pkg/ipfix/ipfix_process.go 81.81% <0.00%> (-18.19%) ⬇️
pkg/ovs/ovsctl/appctl.go 32.60% <0.00%> (-11.96%) ⬇️
pkg/agent/client.go 77.41% <0.00%> (-3.23%) ⬇️
pkg/agent/agent.go 50.53% <0.00%> (+0.21%) ⬆️
pkg/agent/openflow/client.go 59.07% <0.00%> (+0.72%) ⬆️
pkg/apiserver/storage/ram/store.go 80.45% <0.00%> (+1.50%) ⬆️
... and 3 more

@srikartati srikartati force-pushed the patch_flow_agg branch 2 times, most recently from 8356d86 to 1323069 Compare August 11, 2021 22:41
@@ -548,13 +548,14 @@ func (exp *flowExporter) addRecordToSet(record flowexporter.FlowRecord) error {
case "flowType":
ie.Value = exp.findFlowType(record.Conn)
}
eL[i] = ie
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know if that makes a copy, but I image so and to be safe you should use:

for i := range eL {
      ie := &eL[i]
      // ...
}

same comment for other loop below

Copy link
Member Author

Choose a reason for hiding this comment

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

Any reference for this? Thanks.
I can confirm that all the e2e tests and unit tests covering this code are passing.

Copy link
Contributor

Choose a reason for hiding this comment

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

it's not about correctness, but you are copying the element back into the list so it's slower for no reason

see this benchmark:

package main

import (
	"testing"
)

// Without Big
// BenchmarkCopy-12    	 1000000	      1151 ns/op
// BenchmarkRef-12     	 1000000	      1027 ns/op

// With Big
// BenchmarkCopy-12    	   46578	     23557 ns/op
// BenchmarkRef-12     	  869930	      1425 ns/op

type Data struct {
	A   int64
	B   int64
	C   int64
	D   int64
	Big [32]int64
}

func makeList(N int) []Data {
	return make([]Data, N)
}

func iterCopy(l []Data) []Data {
	for i, e := range l {
		e.A += 1
		e.B += 1
		e.C += 1
		e.D += 1
		l[i] = e
	}
	return l
}

func iterRef(l []Data) []Data {
	for i := range l {
		e := &l[i]
		e.A += 1
		e.B += 1
		e.C += 1
		e.D += 1
	}
	return l
}

func BenchmarkCopy(b *testing.B) {
	l := makeList(1000)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		iterCopy(l)
	}
}

func BenchmarkRef(b *testing.B) {
	l := makeList(1000)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		iterRef(l)
	}
}

The performance difference can vary significantly based on element size.

Copy link
Member Author

Choose a reason for hiding this comment

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

I missed the performance reference in your comment.
Here the object is not big. It has a pointer and value of type interface. As you mentioned, better to be safe.
Thanks for the catch.

@@ -388,7 +388,7 @@ func (exp *flowExporter) sendTemplateSet(isIPv6 bool) (int, error) {
if err := exp.ipfixSet.PrepareSet(ipfixentities.Template, templateID); err != nil {
return 0, err
}
err := exp.ipfixSet.AddRecord(elements, templateID)
err := exp.ipfixSet.AddRecord(elements, 0, templateID)
Copy link
Contributor

Choose a reason for hiding this comment

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

it would have been good (or it would be good if it's not too late) to define 2 different methods in go-ipfix: AddRecord and AddRecordWithExtraElements. It would avoid these cryptic changes in Antrea and it's probably good to keep backward compatibility for your library when you can...

Copy link
Member Author

Choose a reason for hiding this comment

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

Good suggestion.

Copy link
Contributor

@antoninbas antoninbas left a comment

Choose a reason for hiding this comment

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

there are several CI failures that need to be addressed

@@ -341,7 +342,7 @@ func (fa *flowAggregator) initExportingProcess() error {
CollectorProtocol: fa.externalFlowCollectorProto,
ObservationDomainID: fa.observationDomainID,
TempRefTimeout: 1800,
PathMTU: 0,
PathMTU: 1400,
Copy link
Contributor

Choose a reason for hiding this comment

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

this needs a comment...
it also seems unrelated to the rest of the PR

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it was not meant to be added. Removed it.

@srikartati
Copy link
Member Author

Thanks for the review @antoninbas
There are some more fixes for perf improvement in go-ipfix. I will update the release tag further after they go in.

Identified and fixed performance fixes. Moving the tag.

Signed-off-by: Srikar Tati <stati@vmware.com>
@srikartati
Copy link
Member Author

/test-all

Copy link
Contributor

@antoninbas antoninbas left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -279,6 +279,7 @@ func (fa *flowAggregator) InitCollectingProcess() error {
IsEncrypted: false,
}
}
cpInput.NumExtraElements = len(antreaSourceStatsElementList) + len(antreaDestinationStatsElementList) + len(antreaLabelsElementList)
Copy link
Contributor

Choose a reason for hiding this comment

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

it's a bit strange that this doesn't match aggregationElements which is what I would expect. I guess I am not familiar enough with go-ipfix.

Copy link
Member Author

Choose a reason for hiding this comment

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

aggregationElements contains all elements that needs an update as we receive flow record. The numExtraElements are the elements that are added newly after receiving the flow records.

@srikartati
Copy link
Member Author

/test-conformance

@antoninbas antoninbas merged commit bdddc01 into antrea-io:main Aug 13, 2021
@srikartati srikartati deleted the patch_flow_agg branch August 13, 2021 05:17
annakhm pushed a commit to annakhm/antrea that referenced this pull request Aug 16, 2021
Identified and fixed performance fixes. Moving the tag.

Signed-off-by: Srikar Tati <stati@vmware.com>
zyiou pushed a commit to zyiou/antrea that referenced this pull request Aug 17, 2021
Identified and fixed performance fixes. Moving the tag.

Signed-off-by: Srikar Tati <stati@vmware.com>
zyiou pushed a commit to zyiou/antrea that referenced this pull request Aug 17, 2021
Identified and fixed performance fixes. Moving the tag.

Signed-off-by: Srikar Tati <stati@vmware.com>
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.

None yet

3 participants