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

added observation points to track performance/resource usage of filter #7

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

pkaeding
Copy link

  • ability to tell when collisions happen
  • get number of items in the filter
  • get memory usage of filter

We love this package, but we found ourselves want to track how it was performing. The plan is to hook our go-metrics code into these, adding a counter for collisions, and functional gauges on the sizes of the filter.

I realize that the number of items and memory usages are not totally atomic (ie, you can add an item to the set, and it could be reflected in the number of items, but not in the memory used), but over time, they should give the right trends, and every item should be counted.

- ability to tell when collisions happen
- get number of items in the filter
- get memory usage of filter
@pkaeding pkaeding force-pushed the pk/indicate-collision branch from 5a8e027 to bbc6efc Compare November 21, 2017 00:58
Copy link
Owner

@jmhodges jmhodges left a comment

Choose a reason for hiding this comment

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

Thanks so much! This needs a bit of work before I can accept it.

contains = bytes.Equal(oldId, id)
collision = len(oldId) != 0 && !contains
if !contains && !collision {
atomic.AddUint32(&f.numEntries, 1)
Copy link
Owner

@jmhodges jmhodges Nov 21, 2017

Choose a reason for hiding this comment

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

Hm, all this code from here and below seems like it could live on a struct that wraps around this one if the ContainsCollision method was added.

I'd be more inclined to add just that ContainsCollision method and skip the rest of this code. In part, for better separation of concerns, but also because I don't think the numEntries code is quite what a lot of people need. (It seems to count the number of times a new entry was put in, sure, but its name suggests the number of items in the map at any given time)

Copy link
Author

Choose a reason for hiding this comment

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

numEntries is actually meant to count the number of entries in the map-- it won't be incremented if there is a collision (in that case, there wouldn't be a new item added to the map, it would be replacing an item in the map).

Copy link
Author

Choose a reason for hiding this comment

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

Good idea on the wrapper struct. I just pushed this up, if you'd like to take another look.

@@ -17,8 +17,10 @@ import (
)

type Filter struct {
array []*[]byte
sizeMask uint32
array []*[]byte
Copy link
Owner

Choose a reason for hiding this comment

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

There's a bunch of gofmt changes in this code (it seems to predate my auto-gofmt set up!), so I've pushed up a gofmt change separately that now conflicts with this PR in parts.

Sorry but thanks for the heads up!

Copy link
Owner

@jmhodges jmhodges left a comment

Choose a reason for hiding this comment

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

This is much closer. Thank you for the work!

return contains, collision
}

func (f *StandardFilter) containsCollisionOldVal(id []byte) (contains bool, collision bool, oldId []byte) {
Copy link
Owner

Choose a reason for hiding this comment

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

Looks like this could be inlined to ContainsCollision, yeah?

@@ -16,7 +16,13 @@ import (
"unsafe"
)

type Filter struct {
type Filter interface {
Copy link
Owner

Choose a reason for hiding this comment

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

I think this is better defined in the code users of the library write.


// Like Filter, but has additional ability to expose the number of items currently
// in the filter, as well as the total size of the data held by the filter
type SizeTrackingFilter struct {
Copy link
Owner

Choose a reason for hiding this comment

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

Ah, I was trying to leave this lib as small as possible and have you keep this code in your codebase. I'm not sure that's as general was we'd assume.

}

func (f *Filter) Size() int {
func (f *StandardFilter) Size() int {
Copy link
Owner

Choose a reason for hiding this comment

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

Good new method. Thanks!

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