-
Notifications
You must be signed in to change notification settings - Fork 60
Reset concurrency to the initial default #336
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
Conversation
Rakefile
Outdated
@@ -1,5 +1,8 @@ | |||
require "bundler/gem_tasks" | |||
|
|||
# Disable stderr warning output | |||
ENV["VIPS_WARNING"] = "1" | |||
|
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.
We purposefully test behaviors that warn, so disable stderr output.
attach_function :vips_concurrency_get, [], :int | ||
|
||
# Track the original default concurrency so we can reset to it. | ||
DEFAULT_CONCURRENCY = vips_concurrency_get |
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.
Read the default right away so we can reset to it. (Note Vips.vips_init
just above which sets the initial vips__concurrency
to VIPS_CONCURRENCY
or CPU count.)
# Get the default size of libvips worker pools. | ||
def self.concurrency_default | ||
DEFAULT_CONCURRENCY | ||
end |
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.
Useful to expose VIPS_CONCURRENCY or CPU count.
# var or the number of hardware threads on your computer. | ||
def self.concurrency | ||
vips_concurrency_get | ||
end |
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.
For inspection, logging, metrics, and the like.
def self.concurrency_set n | ||
n = DEFAULT_CONCURRENCY if n.to_i == 0 |
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.
Assign 0 or nil to restore the initial default.
vips_concurrency_set n | ||
concurrency |
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.
Nice to return the value that was set.
# before Vips.init sets concurrency to the default. | ||
DEFAULT_VIPS_CONCURRENCY = 5 | ||
ENV["VIPS_CONCURRENCY"] = DEFAULT_VIPS_CONCURRENCY.to_s | ||
|
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.
For predictable testing. Set our own VIPS_CONCURRENCY rather than let it default to CPU count.
`Vips.concurrency_set(0)` suggests it'll set concurrency back to the default value, but it does nothing if concurrency is already set, which is always true because Vips.init has already configured thread pools. The result is that if you set concurrency to any value, setting it to zero will leave that value in place. This reads the default concurrency immediately after Vips.init so we can make good on having `concurrency_set 0` reset to default. Also allows setting `nil` to reset to default. Note that setting concurrency does not reconfigure existing thread pools. It affects thread pools spawned for future operations.
68e261f
to
3e6cd18
Compare
What a nice clean PR. Good job! |
... I updated the CHANGELOG. |
Vips.concurrency_set(0)
suggests it'll set concurrency back to thedefault value, but it does nothing if concurrency is already set, which
is always true because Vips.init has already configured thread pools.
The result is that if you set concurrency to any value, setting it to
zero will leave that value in place.
This reads the default concurrency immediately after Vips.init so we
can make good on having
concurrency_set 0
reset to default. Alsoallows setting
nil
to reset to default.Note that setting concurrency does not reconfigure existing thread
pools. It affects thread pools spawned for future operations.
References #335