-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
feat: Make compression encoder pool size controlled by MaxBufferedCompressionEncoders a configurable parameter #2968
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,23 +8,32 @@ import ( | |
|
||
// zstdMaxBufferedEncoders maximum number of not-in-use zstd encoders | ||
// If the pool of encoders is exhausted then new encoders will be created on the fly | ||
const zstdMaxBufferedEncoders = 1 | ||
var zstdMaxBufferedEncoders int | ||
|
||
type ZstdEncoderParams struct { | ||
Level int | ||
Level int | ||
MaxBufferedEncoders int | ||
} | ||
|
||
type ZstdDecoderParams struct { | ||
} | ||
|
||
var zstdDecMap sync.Map | ||
|
||
var zstdAvailableEncoders sync.Map | ||
|
||
func getZstdMaxBufferedEncoders(params ZstdEncoderParams) int { | ||
if params.MaxBufferedEncoders > 0 { | ||
return params.MaxBufferedEncoders | ||
} | ||
return 1 | ||
} | ||
|
||
func getZstdEncoderChannel(params ZstdEncoderParams) chan *zstd.Encoder { | ||
if c, ok := zstdAvailableEncoders.Load(params); ok { | ||
if c, ok := zstdAvailableEncoders.Load(params.Level); ok { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 Hm, not sure we want to clobber all Maybe, we could do something like:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I probably should move MaxBufferedEncoders out of the ZstdEncoderParams struct. The fields in ZstdEncoderParmszstdAvailableEncoders map was keyed on encoder parameters. Encoders with the same encoder parameters are created to be the same kind of objects. MaxBufferedEncoders are used to control the pool size, it's actually not part of the encoder parameter for creating an individual encoder object, use MaxBufferedEncoder as part of the map key would be confusing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, so the idea is that this would be set generically for all encoders in a process? And you just implemented that in a “stateless” sort of way, where everyone is expected to pass in the value? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the 'maxBufferedEncoders' needs to pass in explicitly through function call. ZstdEncoderParams is a struct for the parameters needed for creating an encoder. maxBufferedEncoders is not a parameter for an individual encoder, it should not be stored in that param struct. |
||
return c.(chan *zstd.Encoder) | ||
} | ||
c, _ := zstdAvailableEncoders.LoadOrStore(params, make(chan *zstd.Encoder, zstdMaxBufferedEncoders)) | ||
c, _ := zstdAvailableEncoders.LoadOrStore(params.Level, make(chan *zstd.Encoder, getZstdMaxBufferedEncoders(params))) | ||
return c.(chan *zstd.Encoder) | ||
} | ||
|
||
|
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.
Changing this from a
const
to avar
feels like a code smell.Ah, yep. This PR also removes the only use. I propose instead of this change, move
getZstdMaxBufferedEncoders
to here, and renaming it tozstdMaxBufferedEncoders
. That way we replace the functionality that the const was providing, and also we can reuse some of the godoc as well.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 do the movement and function rename, but getZstdMaxBufferedEncoders also takes in an argument so it won't be exactly the same as before.
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.
Yeah, it won’t be exactly the same, that’s ok.
There’s a kind of common Go style recommendation to avoid
Get
andget
prefixes. (example: https://google.github.io/styleguide/go/decisions#getters ) The idea is the verb is kind of so generic, that it doesn’t increase the information in the name.