This patch skips some self-testing and locking done by the framework
when in production mode. The assumption is that all development is done
in mode != production so no inconsistencies can sneak in.
While this patch doesn't seem to do much it improved command-line
performance for me somewhere between 30 and 50% (so between 3-4 seconds
per command to 1.5-3, on average, often much better).
I explicitly set mode to production in the installation config files. I
also explicitly set developer mode when running makeapi --validate so we
can know at build time that the framework is consistent.
ticket 751
rob
>From 920029a8b5f43b11291b076c670a21f02d932f27 Mon Sep 17 00:00:00 2001
From: Rob Crittenden
Date: Wed, 19 Jan 2011 11:24:31 -0500
Subject: [PATCH] Don't perform some API self-tests in production mode for performance reasons
The API does a fair number of self tests and locking to assure that the
registered commands are consistent and will work. This does not need
to be done on a production system and adds additional overhead causing
somewhere between a 30 and 50% decrease in performance.
Because makeapi is executed when a build is done ensure that it is
executed in developer mode to ensure that the framework is ok.
ticket 751
---
install/tools/ipa-replica-install |1 +
install/tools/ipa-server-install |1 +
ipalib/config.py |3 +++
ipalib/frontend.py|7 ---
ipalib/plugable.py| 15 ++-
makeapi |1 +
6 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/install/tools/ipa-replica-install b/install/tools/ipa-replica-install
index 3c912a7..01e5d38 100755
--- a/install/tools/ipa-replica-install
+++ b/install/tools/ipa-replica-install
@@ -358,6 +358,7 @@ def main():
if ipautil.file_exists(config.dir + "/cacert.p12"):
fd.write("enable_ra=True\n")
fd.write("ra_plugin=dogtag\n")
+fd.write("mode=production\n")
fd.close()
api.bootstrap(in_server=True)
diff --git a/install/tools/ipa-server-install b/install/tools/ipa-server-install
index 173f5c2..754568c 100755
--- a/install/tools/ipa-server-install
+++ b/install/tools/ipa-server-install
@@ -680,6 +680,7 @@ def main():
fd.write("enable_ra=True\n")
if not options.selfsign:
fd.write("ra_plugin=dogtag\n")
+fd.write("mode=production\n")
fd.close()
api.bootstrap(**cfg)
diff --git a/ipalib/config.py b/ipalib/config.py
index ec86d9e..888785a 100644
--- a/ipalib/config.py
+++ b/ipalib/config.py
@@ -467,6 +467,9 @@ class Env(object):
else:
self.in_tree = False
+if self.in_tree and 'mode' not in self:
+self.mode = 'developer'
+
# Set dot_ipa:
if 'dot_ipa' not in self:
self.dot_ipa = self._join('home', '.ipa')
diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index eeed398..51fa524 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -351,9 +351,10 @@ class HasParam(Plugin):
self._filter_param_by_context(name, env),
sort=False
)
-check = getattr(self, 'check_' + name, None)
-if callable(check):
-check(namespace)
+if self.env.mode != 'production':
+check = getattr(self, 'check_' + name, None)
+if callable(check):
+check(namespace)
setattr(self, name, namespace)
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index 264bb68..82bd522 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -207,6 +207,8 @@ class Plugin(ReadOnly):
def finalize(self):
"""
"""
+if self.env.mode == 'production':
+return
lock(self)
def set_api(self, api):
@@ -601,19 +603,22 @@ class API(DictProxy):
namespace = NameSpace(
plugin_iter(base, (magic[k] for k in magic))
)
-assert not (
-name in self.__d or hasattr(self, name)
-)
+ if self.env.mode != 'production':
+assert not (
+name in self.__d or hasattr(self, name)
+)
self.__d[name] = namespace
object.__setattr__(self, name, namespace)
for p in plugins.itervalues():
p.instance.set_api(self)
-assert p.instance.api is self
+if self.env.mode != 'production':
+assert p.instance.api is self
for p in plugins.itervalues():
p.instance.finalize()
-assert islocked(p.instance) is True
+if self.env.mode != 'production':
+assert islocked(p.instance) is True
object.__setattr__(self, '_API__finalized', True)
tuple(PluginInfo(p) for p in plugins.itervalues())
object.__setattr__(self, 'plugins',
diff --git a/makeapi b/makeapi
index 2c7680f..90f3678 100755
--- a/makeapi
+++