summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2024-09-23 23:59:07 -0700
committerGitHub <noreply@github.com>2024-09-23 23:59:07 -0700
commitc070ddac97546bf8f54ec78141e8ce374054513d (patch)
tree40201fa813000d0c4fcf0ee33c7b78d0dc36907e /lib
parent679770b02cf9505752b8da93026e8533bbf38651 (diff)
downloadspack-c070ddac97546bf8f54ec78141e8ce374054513d.tar.gz
spack-c070ddac97546bf8f54ec78141e8ce374054513d.tar.bz2
spack-c070ddac97546bf8f54ec78141e8ce374054513d.tar.xz
spack-c070ddac97546bf8f54ec78141e8ce374054513d.zip
database: don't call `socket.getfqdn()` on every write (#46554)
We've seen `getfqdn()` cause slowdowns on macOS in CI when added elsewhere. It's also called by database.py every time we write the DB file. - [x] replace the call with a memoized version so that it is only called once per process. Signed-off-by: Todd Gamblin <tgamblin@llnl.gov>
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/database.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/spack/spack/database.py b/lib/spack/spack/database.py
index 404288ff83..907b73c5db 100644
--- a/lib/spack/spack/database.py
+++ b/lib/spack/spack/database.py
@@ -50,6 +50,7 @@ except ImportError:
pass
import llnl.util.filesystem as fs
+import llnl.util.lang
import llnl.util.tty as tty
import spack.deptypes as dt
@@ -121,6 +122,17 @@ DEFAULT_INSTALL_RECORD_FIELDS = (
)
+@llnl.util.lang.memoized
+def _getfqdn():
+ """Memoized version of `getfqdn()`.
+
+ If we call `getfqdn()` too many times, DNS can be very slow. We only need to call it
+ one time per process, so we cache it here.
+
+ """
+ return socket.getfqdn()
+
+
def reader(version: vn.StandardVersion) -> Type["spack.spec.SpecfileReaderBase"]:
reader_cls = {
vn.Version("5"): spack.spec.SpecfileV1,
@@ -1084,7 +1096,7 @@ class Database:
self._state_is_inconsistent = True
return
- temp_file = self._index_path + (".%s.%s.temp" % (socket.getfqdn(), os.getpid()))
+ temp_file = self._index_path + (".%s.%s.temp" % (_getfqdn(), os.getpid()))
# Write a temporary database file them move it into place
try: