rack2aws 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6b4761ec5789bc29a4d5fc2d56799a32b149be32
4
- data.tar.gz: 63c2dadc08a92138f0e249732aa870d250c41636
3
+ metadata.gz: 72ae29bf646a70f2cc5731fbad6ba8a1c61f2115
4
+ data.tar.gz: 9464c44d339a1a1587795efde4b0d2f622aaebd8
5
5
  SHA512:
6
- metadata.gz: acb2647fd5e88e139bce7e1eff15aac44333ac6753b555ffa607702b90975a151f00e502301557bfc1a2596578416cdd15d6825286674cb0bbca545f550e7b5f
7
- data.tar.gz: c3d38eea9c6ab2591022869c828e791c63666c5e8d5d35a06ed46f04c7834c8f12026c2915113db4766425ab7bcd819365bab7f18e34bfa392700efdc5fd151b
6
+ metadata.gz: 621b2fbfd728276c06cf70e45c5b777b84b740c36cc7ea33ab789a3064c56f51b92562bc4a7017a481aed2565cd692544619f5a084bb40ce670284a2d0e2dfaf
7
+ data.tar.gz: 903d33fa596f8106bb4d5d2d6a6a1a1d0955135d4918119f078063ffd1450ff2cf68aeae8cb3a6e0d155b556201517d709dff772330e94f12c70957be2edbfe1
@@ -2,13 +2,14 @@ require 'fog'
2
2
  require 'commander'
3
3
  require 'rack2aws/config'
4
4
  require 'rack2aws/version'
5
+ require 'rack2aws/processor_count'
5
6
 
6
7
 
7
8
  module Rack2Aws
8
- class FileCopy
9
+ class FileManager
9
10
  include Rack2Aws::Configuration
10
11
 
11
- attr_reader :per_page, :rackspace, :aws, :rackspace_directory, :aws_directory, :verbose_mode, :files, :total
12
+ attr_reader :per_page, :rackspace, :aws, :rackspace_directory, :aws_directory, :nproc, :verbose_mode, :files, :total
12
13
 
13
14
  def initialize(options={})
14
15
  options = default_options.merge(options)
@@ -18,6 +19,7 @@ module Rack2Aws
18
19
 
19
20
  @rackspace_directory = rackspace.directories.get(options[:rackspace_container])
20
21
  @aws_directory = aws.directories.get(options[:aws_bucket])
22
+ @nproc = options[:nproc]
21
23
  @verbose_mode = options[:verbose]
22
24
  @files = []
23
25
  @total = 0
@@ -57,15 +59,15 @@ module Rack2Aws
57
59
  def copy_files(page, files)
58
60
  puts " [#{Process.pid}] Page #{page+1}: Copying #{files.size} files..." if verbose_mode
59
61
  total = files.size
60
- max_processes = 4
61
62
  process_pids = {}
62
63
  time = Time.now
63
64
 
64
65
  while !files.empty? or !process_pids.empty?
65
- while process_pids.size < max_processes and files.any? do
66
+ while process_pids.size < nproc and files.any? do
66
67
  file = files.pop
67
68
  pid = Process.fork do
68
69
  copy_file(file)
70
+ exit!(0)
69
71
  end
70
72
  process_pids[pid] = { :file => file }
71
73
  end
@@ -92,6 +94,7 @@ module Rack2Aws
92
94
 
93
95
  class CLI
94
96
  include Commander::Methods
97
+ include Rack2Aws::ProcessorCount
95
98
 
96
99
  def run
97
100
  program :name, 'rack2aws'
@@ -107,6 +110,7 @@ module Rack2Aws
107
110
 
108
111
  cmd.option '--container CONTAINER_NAME', String, 'Rackspace Cloud Files container name'
109
112
  cmd.option '--bucket BUCKET_NAME', String, 'AWS S3 bucket name'
113
+ cmd.option '--nproc NUM_PROC', Integer, 'Number of processes to fork'
110
114
  cmd.action do |args, options|
111
115
  if options.container.nil?
112
116
  options.container = ask('Rackspace Cloud Files container: ')
@@ -116,9 +120,14 @@ module Rack2Aws
116
120
  options.bucket = ask('AWS S3 bucket: ')
117
121
  end
118
122
 
119
- FileCopy.new({
123
+ if options.nproc.nil?
124
+ options.nproc = processor_count()
125
+ end
126
+
127
+ FileManager.new({
120
128
  :rackspace_container => options.container,
121
129
  :aws_bucket => options.bucket,
130
+ :nproc => options.nproc,
122
131
  :verbose => $verbose
123
132
  }).copy
124
133
  end
@@ -0,0 +1,88 @@
1
+ module Rack2Aws
2
+ # Taken from parallel lib on Github:
3
+ # https://github.com/grosser/parallel/blob/master/lib/parallel/processor_count.rb
4
+ module ProcessorCount
5
+ # Number of processors seen by the OS and used for process scheduling.
6
+ #
7
+ # * AIX: /usr/sbin/pmcycles (AIX 5+), /usr/sbin/lsdev
8
+ # * BSD: /sbin/sysctl
9
+ # * Cygwin: /proc/cpuinfo
10
+ # * Darwin: /usr/bin/hwprefs, /usr/sbin/sysctl
11
+ # * HP-UX: /usr/sbin/ioscan
12
+ # * IRIX: /usr/sbin/sysconf
13
+ # * Linux: /proc/cpuinfo
14
+ # * Minix 3+: /proc/cpuinfo
15
+ # * Solaris: /usr/sbin/psrinfo
16
+ # * Tru64 UNIX: /usr/sbin/psrinfo
17
+ # * UnixWare: /usr/sbin/psrinfo
18
+ #
19
+ def processor_count
20
+ @processor_count ||= begin
21
+ os_name = RbConfig::CONFIG["target_os"]
22
+ if os_name =~ /mingw|mswin/
23
+ require 'win32ole'
24
+ result = WIN32OLE.connect("winmgmts://").ExecQuery(
25
+ "select NumberOfLogicalProcessors from Win32_Processor")
26
+ result.to_enum.collect(&:NumberOfLogicalProcessors).reduce(:+)
27
+ elsif File.readable?("/proc/cpuinfo")
28
+ IO.read("/proc/cpuinfo").scan(/^processor/).size
29
+ elsif File.executable?("/usr/bin/hwprefs")
30
+ IO.popen("/usr/bin/hwprefs thread_count").read.to_i
31
+ elsif File.executable?("/usr/sbin/psrinfo")
32
+ IO.popen("/usr/sbin/psrinfo").read.scan(/^.*on-*line/).size
33
+ elsif File.executable?("/usr/sbin/ioscan")
34
+ IO.popen("/usr/sbin/ioscan -kC processor") do |out|
35
+ out.read.scan(/^.*processor/).size
36
+ end
37
+ elsif File.executable?("/usr/sbin/pmcycles")
38
+ IO.popen("/usr/sbin/pmcycles -m").read.count("\n")
39
+ elsif File.executable?("/usr/sbin/lsdev")
40
+ IO.popen("/usr/sbin/lsdev -Cc processor -S 1").read.count("\n")
41
+ elsif File.executable?("/usr/sbin/sysconf") and os_name =~ /irix/i
42
+ IO.popen("/usr/sbin/sysconf NPROC_ONLN").read.to_i
43
+ elsif File.executable?("/usr/sbin/sysctl")
44
+ IO.popen("/usr/sbin/sysctl -n hw.ncpu").read.to_i
45
+ elsif File.executable?("/sbin/sysctl")
46
+ IO.popen("/sbin/sysctl -n hw.ncpu").read.to_i
47
+ else
48
+ $stderr.puts "Unknown platform: " + RbConfig::CONFIG["target_os"]
49
+ $stderr.puts "Assuming 1 processor."
50
+ 1
51
+ end
52
+ end
53
+ end
54
+
55
+ #
56
+ # Number of physical processor cores on the current system.
57
+ #
58
+ def physical_processor_count
59
+ @physical_processor_count ||= begin
60
+ ppc = case RbConfig::CONFIG["target_os"]
61
+ when /darwin1/
62
+ IO.popen("/usr/sbin/sysctl -n hw.physicalcpu").read.to_i
63
+ when /linux/
64
+ cores = {} # unique physical ID / core ID combinations
65
+ phy = 0
66
+ IO.read("/proc/cpuinfo").scan(/^physical id.*|^core id.*/) do |ln|
67
+ if ln.start_with?("physical")
68
+ phy = ln[/\d+/]
69
+ elsif ln.start_with?("core")
70
+ cid = phy + ":" + ln[/\d+/]
71
+ cores[cid] = true if not cores[cid]
72
+ end
73
+ end
74
+ cores.count
75
+ when /mswin|mingw/
76
+ require 'win32ole'
77
+ result_set = WIN32OLE.connect("winmgmts://").ExecQuery(
78
+ "select NumberOfCores from Win32_Processor")
79
+ result_set.to_enum.collect(&:NumberOfCores).reduce(:+)
80
+ else
81
+ processor_count
82
+ end
83
+ # fall back to logical count if physical info is invalid
84
+ ppc > 0 ? ppc : processor_count
85
+ end
86
+ end
87
+ end
88
+ end
@@ -1,3 +1,3 @@
1
1
  module Rack2Aws
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack2aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Faissal Elamraoui
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-11 00:00:00.000000000 Z
11
+ date: 2016-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -78,6 +78,7 @@ files:
78
78
  - lib/rack2aws.rb
79
79
  - lib/rack2aws/config.rb
80
80
  - lib/rack2aws/errors.rb
81
+ - lib/rack2aws/processor_count.rb
81
82
  - lib/rack2aws/props_reader.rb
82
83
  - lib/rack2aws/version.rb
83
84
  homepage: https://amrfaissal.github.io/rack2aws