Commit 2d0ca2c5 authored by Iustin Pop's avatar Iustin Pop
Browse files

Loader functions: move from assoc lists to maps



When loading big clusters, the association lists become a bit slow, so
we'll replace this with a simple Map String Int; the change is trivial
and can be reverted easily, while it brings up a good speedup in the
data loading.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarBalazs Lecz <leczb@google.com>
parent 6ff78049
......@@ -40,6 +40,7 @@ module Ganeti.HTools.Loader
import Data.Function (on)
import Data.List
import Data.Maybe (fromJust)
import qualified Data.Map as M
import Text.Printf (printf)
import qualified Ganeti.HTools.Container as Container
......@@ -78,14 +79,14 @@ data Request = Request RqType Node.List Instance.List [String]
-- | Lookups a node into an assoc list.
lookupNode :: (Monad m) => NameAssoc -> String -> String -> m Ndx
lookupNode ktn inst node =
case lookup node ktn of
case M.lookup node ktn of
Nothing -> fail $ "Unknown node '" ++ node ++ "' for instance " ++ inst
Just idx -> return idx
-- | Lookups an instance into an assoc list.
lookupInstance :: (Monad m) => NameAssoc -> String -> m Idx
lookupInstance kti inst =
case lookup inst kti of
case M.lookup inst kti of
Nothing -> fail $ "Unknown instance '" ++ inst ++ "'"
Just idx -> return idx
......@@ -93,9 +94,11 @@ lookupInstance kti inst =
assignIndices :: (Element a) =>
[(String, a)]
-> (NameAssoc, [(Int, a)])
assignIndices =
unzip . map (\ (idx, (k, v)) -> ((k, idx), (idx, setIdx v idx)))
. zip [0..]
assignIndices nodes =
let (na, idx_node) =
unzip . map (\ (idx, (k, v)) -> ((k, idx), (idx, setIdx v idx)))
. zip [0..] $ nodes
in (M.fromList na, idx_node)
-- | Assoc element comparator
assocEqual :: (Eq a) => (a, b) -> (a, b) -> Bool
......
......@@ -55,6 +55,8 @@ module Ganeti.HTools.Types
, queryTimeout
) where
import qualified Data.Map as M
-- | The instance index type.
type Idx = Int
......@@ -62,7 +64,7 @@ type Idx = Int
type Ndx = Int
-- | The type used to hold name-to-idx mappings.
type NameAssoc = [(String, Int)]
type NameAssoc = M.Map String Int
-- | A separate name for the cluster score type.
type Score = Double
......
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