-
Notifications
You must be signed in to change notification settings - Fork 555
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
fix: make number of concurrent downloads configurable #972
base: master
Are you sure you want to change the base?
Conversation
4210c93
to
34e656e
Compare
I'm converting to draft to apply the change to a few other changes where it's relevant before merging. It'll be ready soon. |
34e656e
to
555936b
Compare
I totally forgot about this. Now it's ready. |
I'm thinking of an improvement that could come later on, which is keeping around exactly the number of goroutines we need and sending tasks via channels. That should reduce both the (small) CPU overhead of setting the goroutine up and the (somewhat larger, 4kB per goroutine as a baseline) memory overhead of having too many goroutines lying around, even tho only a few are active at any given time. |
One thing I wanted to delve at some point is a background job system for shiori, were all these background task would be sent (download, import, export, etc) and being able to see the status of them easily rather than just firing goroutines and wait for them. Would be pretty useful for the UI/Integrations. |
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.
Thanks for the contribution @Oppen, just a question regarding the configuration.
@@ -86,6 +87,7 @@ type DatabaseConfig struct { | |||
|
|||
type StorageConfig struct { | |||
DataDir string `env:"DIR"` // Using DIR to be backwards compatible with the old config | |||
MaxParDl int `env:"MAX_PAR_DL"` |
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.
Hi.
thanks for PR. maybe i miss undrtand this part.
you handle if Max_PAR_DL be 0 but what exacly happen if user not set Max_PAR_DL at all (or empty) are you sure it define as 0 by default?
can have a unittest for this?
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.
My understanding is that it defaults to whatever zero-value the type has, in this case integer 0
:
noinit - do not initialize struct fields unless environment variables were provided. The default behavior is to deeply initialize all fields to their default (zero) value.
https://github.com/sethvargo/go-envconfig
Emphasis mine.
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.
can have a unittest for that?
Set different value with environment variable and be sure set expected configuration cfg.Storage.MaxParDl.
Specifically for Max_PAR_DL=""
Max_PAR_DL=-1 , unset Max_PAR_DL etc.
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.
Does Go support manipulation of env vars for unit tests?
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 think you can use this example
https://gobyexample.com/environment-variables
And
https://go-cloud-native.com/golang/test-environment-variables-in-go
And
https://beta.pkg.go.dev/testing@master#T.Setenv
Not forget to cleanup environment variable when the test done.
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'll try on the weekend. I'm a bit wary of races testing like this tho, doesn't tests run in parallel?
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.
What I had in mind was something that acted more like mocking at the runtime level or something like that.
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'll try on the weekend. I'm a bit wary of races testing like this tho, doesn't tests run in parallel?
Only if you mark them with t.Parallel()
, so it depends on the test.
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.
Hi
Thanks for this PR. i left one comment that not clear to me and not bad if we have a unit test for that.
to avoid something like #981 happen again.
Adds a new environment variable
SHIORI_MAX_PAR_DL
to limit the numberof concurrent downloads on the
update
command (and other, if necessary).It defaults to the number of logical CPUs reported by the Go runtime.
Fixes #966