Skip to content

Commit a628269

Browse files
committed
Add config option to set threads for saving images
In testing i've found that using around 1.5 times the CPU cores available on a machine yields the best performance with saving images. This is really important on machines with a lot of cores, we use 32 core machines in our tests and using up all the cores cuts down wraith time in half. 8 seems like a good default, this PR adds the ability to change the value.
1 parent 936e24a commit a628269

File tree

8 files changed

+28
-1
lines changed

8 files changed

+28
-1
lines changed

lib/wraith/save_images.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def run_command(command)
7373
end
7474

7575
def parallel_task(jobs)
76-
Parallel.each(jobs, :in_threads => 8) do |_label, _path, width, url, filename, selector, global_before_capture, path_before_capture|
76+
Parallel.each(jobs, :in_threads => wraith.save_image_threads) do |_label, _path, width, url, filename, selector, global_before_capture, path_before_capture|
7777
begin
7878
command = construct_command(width, url, filename, selector, global_before_capture, path_before_capture)
7979
attempt_image_capture(command, filename)

lib/wraith/wraith.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,8 @@ def verbose
171171
# @TODO - also add a `--verbose` CLI flag which overrides whatever you have set in the config
172172
@config["verbose"] || false
173173
end
174+
175+
def save_image_threads
176+
(@config["save_image_threads"] || 8).to_i
177+
end
174178
end

spec/config_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@
6666
it "include compare label" do
6767
expect(wraith.paths).to eq("home" => "/", "uk_index" => "/uk")
6868
end
69+
70+
it "include save image threads" do
71+
expect(wraith.save_image_threads).to eq(7)
72+
end
6973
end
7074

7175
describe "different ways of initialising browser engine" do

spec/configs/test_config--casper.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ paths:
2828

2929
#Amount of fuzz ImageMagick will use
3030
fuzz: '20%'
31+
32+
# Number of threads used when saving images
33+
save_image_threads: 7

spec/configs/test_config--phantom.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ paths:
3232

3333
#Amount of fuzz ImageMagick will use
3434
fuzz: '20%'
35+
36+
37+
# Number of threads used when saving images
38+
save_image_threads: 7

templates/configs/capture.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,7 @@ gallery:
5959
# diffs_only - only paths with a difference are shown, sorted by difference size (largest first)
6060
# Note: different screen widths are always grouped together.
6161
mode: diffs_first
62+
63+
# (optional) Set the number of threads to use when saving images. Raising this value can improve performance, but very high
64+
# values can lead to server connection issues. Set to around 1.5 the available CPU cores for best performance. Default: 8
65+
save_image_threads: 8

templates/configs/history.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,7 @@ highlight_color: red
7979

8080
# (optional) Parameters to pass to Phantom/Casper command line. Default: '--ignore-ssl-errors=true --ssl-protocol=tlsv1'
8181
phantomjs_options: ''
82+
83+
# (optional) Set the number of threads to use when saving images. Raising this value can improve performance, but very high
84+
# values can lead to server connection issues. Set to around 1.5 the available CPU cores for best performance. Default: 8
85+
save_image_threads: 8

templates/configs/spider.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,7 @@ directory: 'shots'
5858
# diffs_first - all paths (with or without a difference) are shown, sorted by difference size (largest first)
5959
# diffs_only - only paths with a difference are shown, sorted by difference size (largest first)
6060
mode: diffs_first
61+
62+
# (optional) Set the number of threads to use when saving images. Raising this value can improve performance, but very high
63+
# values can lead to server connection issues. Set to around 1.5 the available CPU cores for best performance. Default: 8
64+
save_image_threads: 8

0 commit comments

Comments
 (0)