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

Cache client partition results to save the repeated sort() calls #287

Merged
merged 1 commit into from
Feb 23, 2015
Merged

Cache client partition results to save the repeated sort() calls #287

merged 1 commit into from
Feb 23, 2015

Conversation

cep21
Copy link

@cep21 cep21 commented Feb 20, 2015

For more information, see #286


// If the number of partitions is large, we can get some churn calling cachedPartitions,
// so the result is cached. It is important to update this value whenever metadata is changed
cachedPartitionsResults map[string]map[int][]int32
Copy link
Contributor

Choose a reason for hiding this comment

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

Given there are only two possible values I'm not sure using a nested map is really necessary

@cep21
Copy link
Author

cep21 commented Feb 21, 2015

I pushed a new change that uses an array rather than a map. I think not returning a copy does not let people modify the result, but it also saves on memory allocations. I think this behavior should be ok(?) Not sure why someone would depend upon that.


// If the number of partitions is large, we can get some churn calling cachedPartitions,
// so the result is cached. It is important to update this value whenever metadata is changed
cachedPartitionsResults map[string][][]int32
Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking two separate maps (or even a fixed array [2]int32) but I guess a slice is just as good

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer to use a static array here, because it makes it more clear that this is not a list but a tuple.

@eapache
Copy link
Contributor

eapache commented Feb 22, 2015

also saves on memory allocations

Yes it does, which is a good point.

Not sure why someone would depend upon that.

Neither am I (we don't, as far as I am aware) but I've learned to expect to be surprised :)


I've mentioned a few style nits, but I don't think there's anything really wrong with this as it stands.

@Shopify/kafka for an additional review please?

return client.cachedPartitionsResults[topic][partitionSet]
}

func (client *Client) cachedPartitionsNoLock(topic string, partitionSet partitionType) []int32 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I find this function name slightly confusing; based on the name I expect cachedPartitions to simply call grab the lock and call this function.

Maybe setPartitionCache or updatePartitionCache?

@wvanbergen
Copy link
Contributor

This looks good to me; just some comments about naming to make the intent clearer.

@cep21
Copy link
Author

cep21 commented Feb 23, 2015

I've pushed one more version based upon the comments. If there are more thoughts on names, it's ok if you want to pull my branch and make them before pushing upstream.

@wvanbergen
Copy link
Contributor

This looks great now. Thanks for your contribution!

wvanbergen added a commit that referenced this pull request Feb 23, 2015
Cache client partition results to save the repeated sort() calls
@wvanbergen wvanbergen merged commit b90ee9d into IBM:master Feb 23, 2015
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.

3 participants