Commit 80d7d8a1 authored by Iustin Pop's avatar Iustin Pop
Browse files

Switch over some hspace stats from RSpec to AllocInfo



This patch changes the allocation delta stats from RSpec to
AllocInfo. There's nothing interesting about it, but it should allow
more correct computations of Npus in hspace.

I also moved the AllocStats type alias from Cluster.hs to Types.hs
(just makes more sense).
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent 76a20994
......@@ -33,7 +33,6 @@ module Ganeti.HTools.Cluster
, EvacSolution(..)
, Table(..)
, CStats(..)
, AllocStats
, AllocResult
, AllocMethod
-- * Generic functions
......@@ -163,9 +162,6 @@ data CStats = CStats
, csNinst :: Int -- ^ The total number of instances
} deriving (Show, Read)
-- | Currently used, possibly to allocate, unallocable.
type AllocStats = (RSpec, RSpec, RSpec)
-- | A simple type for allocation functions.
type AllocMethod = Node.List -- ^ Node list
-> Instance.List -- ^ Instance list
......@@ -273,17 +269,26 @@ totalResources nl =
-- was left unallocated.
computeAllocationDelta :: CStats -> CStats -> AllocStats
computeAllocationDelta cini cfin =
let CStats {csImem = i_imem, csIdsk = i_idsk, csIcpu = i_icpu} = cini
let CStats {csImem = i_imem, csIdsk = i_idsk, csIcpu = i_icpu,
csNcpu = i_ncpu } = cini
CStats {csImem = f_imem, csIdsk = f_idsk, csIcpu = f_icpu,
csTmem = t_mem, csTdsk = t_dsk, csVcpu = v_cpu } = cfin
rini = RSpec (fromIntegral i_icpu) (fromIntegral i_imem)
(fromIntegral i_idsk)
rfin = RSpec (fromIntegral (f_icpu - i_icpu))
(fromIntegral (f_imem - i_imem))
(fromIntegral (f_idsk - i_idsk))
un_cpu = fromIntegral (v_cpu - f_icpu)::Int
runa = RSpec un_cpu (truncate t_mem - fromIntegral f_imem)
(truncate t_dsk - fromIntegral f_idsk)
csTmem = t_mem, csTdsk = t_dsk, csVcpu = f_vcpu,
csNcpu = f_ncpu, csTcpu = f_tcpu } = cfin
rini = AllocInfo { allocInfoVCpus = fromIntegral i_icpu
, allocInfoNCpus = i_ncpu
, allocInfoMem = fromIntegral i_imem
, allocInfoDisk = fromIntegral i_idsk
}
rfin = AllocInfo { allocInfoVCpus = fromIntegral (f_icpu - i_icpu)
, allocInfoNCpus = f_ncpu - i_ncpu
, allocInfoMem = fromIntegral (f_imem - i_imem)
, allocInfoDisk = fromIntegral (f_idsk - i_idsk)
}
runa = AllocInfo { allocInfoVCpus = fromIntegral (f_vcpu - f_icpu)
, allocInfoNCpus = f_tcpu - f_ncpu
, allocInfoMem = truncate t_mem - fromIntegral f_imem
, allocInfoDisk = truncate t_dsk - fromIntegral f_idsk
}
in (rini, rfin, runa)
-- | The names and weights of the individual elements in the CV list.
......
......@@ -219,12 +219,12 @@ formatSpecMap =
(rspecDsk spec) (rspecCpu spec) cnt)
-- | Formats \"key-metrics\" values.
formatRSpec :: Double -> String -> RSpec -> [(String, String)]
formatRSpec m_cpu s r =
[ ("KM_" ++ s ++ "_CPU", show $ rspecCpu r)
, ("KM_" ++ s ++ "_NPU", show $ fromIntegral (rspecCpu r) / m_cpu)
, ("KM_" ++ s ++ "_MEM", show $ rspecMem r)
, ("KM_" ++ s ++ "_DSK", show $ rspecDsk r)
formatRSpec :: String -> AllocInfo -> [(String, String)]
formatRSpec s r =
[ ("KM_" ++ s ++ "_CPU", show $ allocInfoVCpus r)
, ("KM_" ++ s ++ "_NPU", show $ allocInfoNCpus r)
, ("KM_" ++ s ++ "_MEM", show $ allocInfoMem r)
, ("KM_" ++ s ++ "_DSK", show $ allocInfoDisk r)
]
-- | Shows allocations stats.
......@@ -232,12 +232,10 @@ printAllocationStats :: Node.List -> Node.List -> IO ()
printAllocationStats ini_nl fin_nl = do
let ini_stats = Cluster.totalResources ini_nl
fin_stats = Cluster.totalResources fin_nl
avg_vcpu_ratio = fromIntegral (Cluster.csVcpu fin_stats) /
Cluster.csTcpu fin_stats
(rini, ralo, runa) = Cluster.computeAllocationDelta ini_stats fin_stats
printKeys $ formatRSpec avg_vcpu_ratio "USED" rini
printKeys $ formatRSpec avg_vcpu_ratio "POOL"ralo
printKeys $ formatRSpec avg_vcpu_ratio "UNAV" runa
printKeys $ formatRSpec "USED" rini
printKeys $ formatRSpec "POOL" ralo
printKeys $ formatRSpec "UNAV" runa
-- | Ensure a value is quoted if needed.
ensureQuoted :: String -> String
......
......@@ -42,6 +42,7 @@ module Ganeti.HTools.Types
, instanceStatusToRaw
, RSpec(..)
, AllocInfo(..)
, AllocStats
, DynUtil(..)
, zeroUtil
, baseUtil
......@@ -167,6 +168,9 @@ data AllocInfo = AllocInfo
, allocInfoDisk :: Int -- ^ Disk
} deriving (Show, Read, Eq)
-- | Currently used, possibly to allocate, unallocable.
type AllocStats = (AllocInfo, AllocInfo, AllocInfo)
-- | Instance specification type.
$(THH.buildObject "ISpec" "iSpec"
[ THH.renameField "MemorySize" $ THH.simpleField "memory-size" [t| Int |]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment