summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2013-05-03 11:35:27 -0700
committerJohn Keiser <jkeiser@opscode.com>2013-06-07 13:12:32 -0700
commit001a01373ba9aed7ebec8794a31906ae21140fd6 (patch)
tree016c5532fe40cbc2dbe9e0c98bd443fb6f85d0a2
parentcf00c1587eadd3d0df5d73e132ce6084c0d35a71 (diff)
downloadchef-001a01373ba9aed7ebec8794a31906ae21140fd6.tar.gz
Add --concurrency argument to set # of threads
-rw-r--r--lib/chef/chef_fs/knife.rb8
-rw-r--r--lib/chef/chef_fs/parallelizer.rb9
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/chef/chef_fs/knife.rb b/lib/chef/chef_fs/knife.rb
index 270b6768f5..ec7403539e 100644
--- a/lib/chef/chef_fs/knife.rb
+++ b/lib/chef/chef_fs/knife.rb
@@ -20,6 +20,7 @@ require 'chef/chef_fs/file_system/chef_server_root_dir'
require 'chef/chef_fs/file_system/chef_repository_file_system_root_dir'
require 'chef/chef_fs/file_pattern'
require 'chef/chef_fs/path_utils'
+require 'chef/chef_fs/parallelizer'
require 'chef/config'
class Chef
@@ -33,11 +34,16 @@ class Chef
option :chef_repo_path,
:long => '--chef-repo-path PATH',
:description => 'Overrides the location of chef repo. Default is specified by chef_repo_path in the config'
+
+ option :concurrency,
+ :long => '--concurrency THREADS',
+ :description => 'Maximum number of simultaneous requests to send (default: 10)'
end
def configure_chef
super
Chef::Config[:repo_mode] = config[:repo_mode] if config[:repo_mode]
+ Chef::Config[:concurrency] = config[:concurrency].to_i if config[:concurrency]
# --chef-repo-path overrides all other paths
path_variables = %w(acl_path client_path cookbook_path container_path data_bag_path environment_path group_path node_path role_path user_path)
@@ -86,6 +92,8 @@ class Chef
end
end
end
+
+ Chef::ChefFS::Parallelizer.threads = (Chef::Config[:concurrency] || 10) - 1
end
def chef_fs
diff --git a/lib/chef/chef_fs/parallelizer.rb b/lib/chef/chef_fs/parallelizer.rb
index 25b03a153c..6aab14d7f5 100644
--- a/lib/chef/chef_fs/parallelizer.rb
+++ b/lib/chef/chef_fs/parallelizer.rb
@@ -1,8 +1,15 @@
class Chef
module ChefFS
class Parallelizer
+ @@parallelizer = nil
+
+ def self.threads=(value)
+ raise "Cannot set threads after parallelize has been called" if @@parallelizer
+ @@threads = value
+ end
+
def self.parallelize(enumerator, options = {}, &block)
- @@parallelizer ||= Parallelizer.new(10)
+ @@parallelizer ||= Parallelizer.new(@@threads)
@@parallelizer.parallelize(enumerator, options, &block)
end