On 10/25/2011 04:01 PM, Martin Kosek wrote:
On Tue, 2011-10-25 at 15:29 +0200, Ondrej Hamada wrote:
https://fedorahosted.org/freeipa/ticket/1336

Lazy initialization of ipalib plugins is used under all contexts, not
only when context = cli. Every loaded plugin is pre-finalized - a flag
is set, which means, that the plugin needs to be finalized. Then every
call of plugin's __gettattr__ checks the flag and finalizes the plugin
if necessary. The code was implemented by jcholast. Time reduction of
commands execution is quite markable:

patch [s] |   normal [s]    |   command
-----------------------------------------------------------------------
1.468      |       2.287       |   ipa user-add jsmith --firt=john
--last=smith
1.658      |       2.235       |   ipa user-del jsmith
1.624      |       2.204       |   ipa dnsrecord-find example.com

Thanks for submitting the patch. Ondra, just please provide the patch in
proper format (exported via command `git format-patch -M -C --patience
--full-index -1' which I sent you earlier).

Martin


Sorry, correct version attached

--
Regards,

Ondrej Hamada
FreeIPA team
jabber: oh...@jabbim.cz
IRC: ohamada

From 798d8f8a624f8350974e54c328c1c58c06944b26 Mon Sep 17 00:00:00 2001
From: Ondrej Hamada <oham...@redhat.com>
Date: Tue, 25 Oct 2011 16:20:44 +0200
Subject: [PATCH] lazy initialization patch

---
 ipalib/plugable.py |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index b0e415656e0428eb164c35a2862fcfbf50883381..2aed1cdcda18840728558ed53435ab10ae28e802 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -173,6 +173,7 @@ class Plugin(ReadOnly):
     """
 
     label = None
+    __try_finalize = False
 
     def __init__(self):
         self.__api = None
@@ -208,6 +209,16 @@ class Plugin(ReadOnly):
                 )
             )
 
+    def __getattribute__(self, name):
+        if name.startswith('_Plugin__') or name.startswith('_ReadOnly__'):
+            return object.__getattribute__(self, name)
+        if self.__try_finalize:
+            self.__try_finalize = False
+            self.finalize()
+            if not is_production_mode(self.__api):
+                assert islocked(self) is True
+        return object.__getattribute__(self, name)
+
     def __get_api(self):
         """
         Return `API` instance passed to `finalize()`.
@@ -217,6 +228,9 @@ class Plugin(ReadOnly):
         return self.__api
     api = property(__get_api)
 
+    def prefinalize(self):
+        self.__try_finalize = True
+
     def finalize(self):
         """
         """
@@ -638,9 +652,7 @@ class API(DictProxy):
                 assert p.instance.api is self
 
         for p in plugins.itervalues():
-            p.instance.finalize()
-            if not production_mode:
-                assert islocked(p.instance) is True
+            p.instance.prefinalize()
         object.__setattr__(self, '_API__finalized', True)
         tuple(PluginInfo(p) for p in plugins.itervalues())
         object.__setattr__(self, 'plugins',
-- 
1.7.6.4

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to