Skip to content

Commit

Permalink
database: don't call socket.getfqdn() on every write (spack#46554)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
tgamblin authored Sep 24, 2024
1 parent 679770b commit c070dda
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/spack/spack/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
pass

import llnl.util.filesystem as fs
import llnl.util.lang
import llnl.util.tty as tty

import spack.deptypes as dt
Expand Down Expand Up @@ -121,6 +122,17 @@
)


@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,
Expand Down Expand Up @@ -1084,7 +1096,7 @@ def _write(self, type, value, traceback):
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:
Expand Down

0 comments on commit c070dda

Please sign in to comment.