Class: Pwrake::LocalityAwareQueue::Throughput
- Inherits:
-
Object
- Object
- Pwrake::LocalityAwareQueue::Throughput
- Defined in:
- lib/pwrake/locality_aware_queue.rb
Instance Method Summary collapse
-
#initialize(list = nil) ⇒ Throughput
constructor
A new instance of Throughput.
- #interdomain(x, y) ⇒ Object
- #interhost(x, y) ⇒ Object
- #parse_hostname(host) ⇒ Object
Constructor Details
#initialize(list = nil) ⇒ Throughput
Returns a new instance of Throughput.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/pwrake/locality_aware_queue.rb', line 78 def initialize(list=nil) @interdomain_list = {} @interhost_list = {} if list values = [] list.each do |x,y,v| hash_x = (@interdomain_list[x] ||= {}) hash_x[y] = n = v.to_f values << n end @min_value = values.min else @min_value = 1 end end |
Instance Method Details
#interdomain(x, y) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/pwrake/locality_aware_queue.rb', line 94 def interdomain(x,y) hash_x = (@interdomain_list[x] ||= {}) if v = hash_x[y] return v elsif v = (@interdomain_list[y] || {})[x] hash_x[y] = v else if x == y hash_x[y] = 1 else hash_x[y] = 0.1 end end hash_x[y] end |
#interhost(x, y) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/pwrake/locality_aware_queue.rb', line 110 def interhost(x,y) return @min_value if !x hash_x = (@interhost_list[x] ||= {}) if v = hash_x[y] return v elsif v = (@interhost_list[y] || {})[x] hash_x[y] = v else x_short, x_domain = parse_hostname(x) y_short, y_domain = parse_hostname(y) v = interdomain(x_domain,y_domain) hash_x[y] = v end hash_x[y] end |
#parse_hostname(host) ⇒ Object
126 127 128 129 |
# File 'lib/pwrake/locality_aware_queue.rb', line 126 def parse_hostname(host) /^([^.]*)\.?(.*)$/ =~ host [$1,$2] end |