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

Use dynamic channel selection to reduce server code duplication #413

Closed
snowp opened this issue Apr 7, 2021 · 1 comment
Closed

Use dynamic channel selection to reduce server code duplication #413

snowp opened this issue Apr 7, 2021 · 1 comment

Comments

@snowp
Copy link
Contributor

snowp commented Apr 7, 2021

Currently the server code manages a set of typed channels/cancelations/etc. and an untyped aggregation goroutine that allows for handling generic types. This is done because of how select only supports a static number of channels. As a result of this, there is a lot of duplicated code between the typed branches and a different set of logic handling the unknown types.

We might consider using reflect.Select here in order to treat all the channels the same: this would not only reduce the amount of code duplication, but also reduce the number of goroutines used when unknown types are subscribed to.

https://github.com/envoyproxy/go-control-plane/compare/main...snowp:dynamic-select?expand=1 shows a prototype of reflect.Select in action: we manage a list of channels to subscribe from based on, and use reflect.Select to pick between the watch channels, the request channel and ctx.Done.

Putting this up for thoughts in case I'm missing any cons with the reflection approach here.

@alecholmez
Copy link
Contributor

I just opened this: #438

It's not as elegant as the dynamic channel selection but it reduces the code duplication we have in SOTW.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants