-
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
Changes from all commits
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 |
---|---|---|
|
@@ -626,6 +626,10 @@ def to_s | |
attach_function :vips_leak_set, [:int], :void | ||
attach_function :vips_vector_set_enabled, [:int], :void | ||
attach_function :vips_concurrency_set, [:int], :void | ||
attach_function :vips_concurrency_get, [], :int | ||
|
||
# Track the original default concurrency so we can reset to it. | ||
DEFAULT_CONCURRENCY = vips_concurrency_get | ||
|
||
# vips_foreign_get_suffixes was added in libvips 8.8 | ||
begin | ||
|
@@ -663,10 +667,23 @@ def self.cache_set_max_files size | |
vips_cache_set_max_files size | ||
end | ||
|
||
# Set the size of the libvips worker pool. This defaults to the number of | ||
# hardware threads on your computer. Set to 1 to disable threading. | ||
# Get the size of libvips worker pools. Defaults to the VIPS_CONCURRENCY env | ||
# 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 commentThe reason will be displayed to describe this comment to others. Learn more. For inspection, logging, metrics, and the like. |
||
|
||
# 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 commentThe reason will be displayed to describe this comment to others. Learn more. Useful to expose VIPS_CONCURRENCY or CPU count. |
||
|
||
# Set the size of each libvips worker pool. Max 1024 threads. Set to 1 to | ||
# disable threading. Set to 0 or nil to reset to default. | ||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Nice to return the value that was set. |
||
end | ||
|
||
# Enable or disable SIMD and the run-time compiler. This can give a nice | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
# Set default concurrency so we can check against it later. Must be 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 commentThe 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. |
||
# Disable stderr output since we purposefully trigger warn-able behavior. | ||
ENV["VIPS_WARNING"] = "1" | ||
|
||
require "vips" | ||
|
||
require "tempfile" | ||
|
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 initialvips__concurrency
toVIPS_CONCURRENCY
or CPU count.)