[Ovirt-devel] Re: [Patch] Experimental Graphs Backend Code

Scott Seago sseago at redhat.com
Thu May 29 19:53:50 UTC 2008


Mohammed Morsi wrote:
> Scott Seago wrote:
>> Hugh O. Brock wrote:
>>>
>>>> +    elsif target == 'memory'
>>>> +        if (@total[:memory] > @used[:memory])
>>>> +            color = 'red' if (@used[:memory].to_f / 
>>>> @total[:memory].to_f) > 0.75
>>>> +            data_sets.push ({ :name => 'memory_used', :values => 
>>>> [@used[:memory]],
>>>> +                                :fill => color, :stroke => 
>>>> 'lightgray', :strokeWidth => 1 },
>>>> +                            { :name => 'memory_available', 
>>>> +                                :values => [@available[:memory]], 
>>>> :fill => 'white',
>>>> +                                :stroke => 'lightgray', 
>>>> :strokeWidth => 1})
>>>> +        else
>>>> +            data_sets.push ({ :name => 'memory_available', :values 
>>>> => [@available[:memory]],
>>>> +                                :fill => 'white', :stroke => 
>>>> 'lightgray', :strokeWidth => 1 },
>>>> +                            { :name => 'memory_used', 
>>>> +                                :values => [@used[:memory]], :fill 
>>>> => 'red',
>>>> +                                :stroke => 'lightgray', 
>>>> :strokeWidth => 1})
>>>> +        end
>>>> +
>>>>     
>>>
>>> Right now we *can't* overcommit RAM, so I don't know if we want the
>>> same logic for this graph as for the cpu graph. Also, I assume that
>>> memory_available is "the sum of all memory on all machines in the
>>> pool," where "memory used" is "the sum of all memory currently in use
>>> by active VMs?" (Scott, you can probably comment on this too I'm sure)
>>>
>>>   
>> That's how I would interpret this. also, "active VMs" refers to all 
>> VMs that are either running or suspended. We don't care about stopped 
>> VMs.
>
> So for memory (and cpu?) available, I take a hardware pool and:
>
>   used = 0
>  @selected_pool.all_sub_vm_resource_pools { |pool|
>     pool.vms.each { |vm|
>           if (vm.state == running || vm.state == suspended)
>               used += vm.memory_used   // or num_vcpus_used
>     }
>  }
>
> correct?
>
Yes, although for in-use resources, you can actually use 
VmResourcePool.allocated_resources, which essentially does the above. 
allocated_resources is "what's now in use", total_resources is "what's 
the quota" and available_resources is the difference between the two 
(with allowances for unlimited quota values). So for the HW page, what 
you really want is the sum of the allocated_resources values for the VM 
resource pools.

> Also when you say "memory_available is "the sum of all memory on all 
> machines in the pool,"".
>  1. By this definition it sounds like you mean "total memory". I've 
> been using "available" as how much can be used at the given point, eg 
> total  = used + available
That's right. I may have said it wrong before. With quotas, at least, we 
have total=allocated+available, where allocated==used
for HW pools, it will be the same thing, but total will be based on 
hosts rather than VM pools.
>  2. is the definition of machine == host? If so do "all machines" only 
> encompass the hosts in the current pool? Or do they include all hosts 
> in all subpools? I think the latter case would look like:
>
> total = 0
> @selected_pool.hosts.each { |host|
>     total += host.memory  // or cpus
> }
>
> @selected_pool.all_sub_hardware_pools { |pool|
>    pool.hosts.each { |host|
>        total += host.memory // or cpus
>    }
> }
>
As I mentioned in IRC, we probably need both numbers. But the most 
important will be for just the current hardware pool. For one thing, if 
you traverse subpools for hosts, you've also got to traverse subpools 
for vm pools (and vms). And, from the point of view of managing load 
within a given HW pool, subpools don't matter a bit.

Also, if you look at the definition of the hosts association in hardware 
pools.rb:
  has_many :hosts, :include => :nics, :dependent => :nullify, :order => 
"hosts.id ASC" do
    def total_cpus
      find(:all).inject(0){ |sum, host| sum + host.num_cpus }
    end
  end

We already have a defintiion for total CPUs. just add another for memory.

Then you can do @selected_pool.hosts.total_cpus and 
@selected_pool.hosts.memory.

Scott





More information about the ovirt-devel mailing list