On Thu, Mar 10, 2016 at 05:35:41PM +0000, 'Brian Foley' via ganeti-devel wrote: > Do this by implementing and using getInstanceByName on hot paths. > > This is much faster than the more generic but extremely inefficient > getInstance which can match by UUID, exact name, or name prefixes. > instances are stored in a Map keyed by UUID, and if that lookup fails, > getInstance creates a temporary Map of names to instances, and > does a linear scan of it. > > On a large test cluster (80 nodes, 1000 instances), getInstance used > ~65% of the total CPU time and 80% of the heap allocations for a luxid > that started, handled 2 QueryInstance calls, and shut down. > > This patch reduces the time to respond to the client for each of these > calls from ~18s to ~2.5s, and the total luxid heap allocations from > ~11.5GB to ~2.4GB. > > Signed-off-by: Brian Foley <[email protected]> > --- > src/Ganeti/Config.hs | 16 ++++++++++++++-- > 1 file changed, 14 insertions(+), 2 deletions(-) > > diff --git a/src/Ganeti/Config.hs b/src/Ganeti/Config.hs > index b902a32..917f160 100644 > --- a/src/Ganeti/Config.hs > +++ b/src/Ganeti/Config.hs > @@ -285,6 +285,17 @@ getInstance cfg name = > $ instances > in getItem "Instance" name by_name > > +-- | Looks up an instance by exact name match > +getInstanceByName :: ConfigData -> String -> ErrorResult Instance > +getInstanceByName cfg name = > + let instances = M.elems $ fromContainer $ configInstances cfg
As per our style guide, http://docs.ganeti.org/ganeti/master/html/dev-codestyle.html#parentheses-point-free-style, write as M.elems . fromContainer $ configInstances cfg > + matching = F.find (\i -> maybe False (==name) (instName i)) instances Usually we separate binary operators by spaces, so (== name) instead of (==name). Rest LGTM and thanks for the improvement! -- Klaus Aehlig Google Germany GmbH, Erika-Mann-Str. 33, 80636 Muenchen Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschaeftsfuehrer: Matthew Scott Sucherman, Paul Terence Manicle
