-
Notifications
You must be signed in to change notification settings - Fork 27
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
Improve IPFIX Set implementation #390
Improve IPFIX Set implementation #390
Conversation
Benchmark results without ResetSet improvements:
And with the improvements:
|
b7d06dd
to
4f56128
Compare
pkg/entities/set.go
Outdated
@@ -45,6 +46,8 @@ const ( | |||
|
|||
type Set interface { | |||
PrepareSet(setType ContentType, templateID uint16) error | |||
// Call ResetSet followd by a new call to PrepareSet in order to reuse an existing Set, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Call ResetSet followd by a new call to PrepareSet in order to reuse an existing Set, | |
// Call ResetSet followed by a new call to PrepareSet in order to reuse an existing Set, |
s.length = SetHeaderLen | ||
} | ||
s.setType = Undefined | ||
s.records = nil | ||
s.records = make([]Record, 0) | ||
// Clear before shrinking the slice so that existing elements are eligible for garbage collection. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to reset the s.length here? I'm not quite sure what's the case when it isDecoding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can reset it to 0, even though it's a change to the existing behavior. I agree that it would make more sense.
I am not a big fan of the isDecoding
flag everywhere. We should have Marhsal
/ Unmarshal
methods as appropriate, but that will have to be for a later time...
pkg/entities/set.go
Outdated
// Sanity check: we need to make sure that the record is allowed to be added. | ||
recordType := record.GetRecordType() | ||
if recordType != s.setType { | ||
return fmt.Errorf("Record and Set types don't match") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return fmt.Errorf("Record and Set types don't match") | |
return fmt.Errorf("record and Set types don't match") |
pkg/entities/set.go
Outdated
return fmt.Errorf("Record and Set types don't match") | ||
} | ||
if recordType == Data && record.GetTemplateID() != s.templateID { | ||
return fmt.Errorf("All Data Records in the same Data Set must have the same template ID") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return fmt.Errorf("All Data Records in the same Data Set must have the same template ID") | |
return fmt.Errorf("all Data Records in the same Data Set must have the same template ID") |
* Optimize ResetSet to avoid memory allocations * Add new interface method AddRecordV3 which takes a Record as a parameter (instead of a list of IEs). AddRecordV3 can avoid all memory allocations. We also add a new GetRecordType method to the Record interface. Signed-off-by: Antonin Bas <antonin.bas@broadcom.com>
Signed-off-by: Antonin Bas <antonin.bas@broadcom.com>
4f56128
to
e18a3d8
Compare
@yuntanghsu Thanks for the review, I addressed comments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
We also add a new GetRecordType method to the Record interface.