summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2019-12-21 00:21:59 -0800
committerTodd Gamblin <tgamblin@llnl.gov>2019-12-23 18:36:56 -0800
commit0fb32800118c2af0a12a3f3fdb999daf99c45d4d (patch)
tree5a3f6009eeb2c996ac837b7edfbb252489bba54b /lib
parent6c9467e8c6d5fffa6d9412d5d36ff2c91e33ea21 (diff)
downloadspack-0fb32800118c2af0a12a3f3fdb999daf99c45d4d.tar.gz
spack-0fb32800118c2af0a12a3f3fdb999daf99c45d4d.tar.bz2
spack-0fb32800118c2af0a12a3f3fdb999daf99c45d4d.tar.xz
spack-0fb32800118c2af0a12a3f3fdb999daf99c45d4d.zip
performance: add read transactions for `install_all()` and `install()`
Environments need to read the DB a lot when installing all specs. - [x] Put a read transaction around `install_all()` and `install()` to avoid repeated locking
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/environment.py66
1 files changed, 35 insertions, 31 deletions
diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py
index dd20bc3fda..60d6120cc8 100644
--- a/lib/spack/spack/environment.py
+++ b/lib/spack/spack/environment.py
@@ -995,19 +995,22 @@ class Environment(object):
spec = Spec(user_spec)
- if self.add(spec):
- concrete = concrete_spec if concrete_spec else spec.concretized()
- self._add_concrete_spec(spec, concrete)
- else:
- # spec might be in the user_specs, but not installed.
- # TODO: Redo name-based comparison for old style envs
- spec = next(s for s in self.user_specs if s.satisfies(user_spec))
- concrete = self.specs_by_hash.get(spec.build_hash())
- if not concrete:
- concrete = spec.concretized()
+ with spack.store.db.read_transaction():
+ if self.add(spec):
+ concrete = concrete_spec or spec.concretized()
self._add_concrete_spec(spec, concrete)
+ else:
+ # spec might be in the user_specs, but not installed.
+ # TODO: Redo name-based comparison for old style envs
+ spec = next(
+ s for s in self.user_specs if s.satisfies(user_spec)
+ )
+ concrete = self.specs_by_hash.get(spec.build_hash())
+ if not concrete:
+ concrete = spec.concretized()
+ self._add_concrete_spec(spec, concrete)
- self._install(concrete, **install_args)
+ self._install(concrete, **install_args)
def _install(self, spec, **install_args):
spec.package.do_install(**install_args)
@@ -1180,26 +1183,27 @@ class Environment(object):
def install_all(self, args=None):
"""Install all concretized specs in an environment."""
- for concretized_hash in self.concretized_order:
- spec = self.specs_by_hash[concretized_hash]
-
- # Parse cli arguments and construct a dictionary
- # that will be passed to Package.do_install API
- kwargs = dict()
- if args:
- spack.cmd.install.update_kwargs_from_args(args, kwargs)
-
- self._install(spec, **kwargs)
-
- if not spec.external:
- # Link the resulting log file into logs dir
- build_log_link = os.path.join(
- self.log_path, '%s-%s.log' % (spec.name, spec.dag_hash(7)))
- if os.path.lexists(build_log_link):
- os.remove(build_log_link)
- os.symlink(spec.package.build_log_path, build_log_link)
-
- self.regenerate_views()
+ with spack.store.db.read_transaction():
+ for concretized_hash in self.concretized_order:
+ spec = self.specs_by_hash[concretized_hash]
+
+ # Parse cli arguments and construct a dictionary
+ # that will be passed to Package.do_install API
+ kwargs = dict()
+ if args:
+ spack.cmd.install.update_kwargs_from_args(args, kwargs)
+
+ self._install(spec, **kwargs)
+
+ if not spec.external:
+ # Link the resulting log file into logs dir
+ log_name = '%s-%s' % (spec.name, spec.dag_hash(7))
+ build_log_link = os.path.join(self.log_path, log_name)
+ if os.path.lexists(build_log_link):
+ os.remove(build_log_link)
+ os.symlink(spec.package.build_log_path, build_log_link)
+
+ self.regenerate_views()
def all_specs_by_hash(self):
"""Map of hashes to spec for all specs in this environment."""