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>
This commit is contained in:
parent
679770b02c
commit
c070ddac97
@ -50,6 +50,7 @@
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
import llnl.util.filesystem as fs
|
import llnl.util.filesystem as fs
|
||||||
|
import llnl.util.lang
|
||||||
import llnl.util.tty as tty
|
import llnl.util.tty as tty
|
||||||
|
|
||||||
import spack.deptypes as dt
|
import spack.deptypes as dt
|
||||||
@ -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"]:
|
def reader(version: vn.StandardVersion) -> Type["spack.spec.SpecfileReaderBase"]:
|
||||||
reader_cls = {
|
reader_cls = {
|
||||||
vn.Version("5"): spack.spec.SpecfileV1,
|
vn.Version("5"): spack.spec.SpecfileV1,
|
||||||
@ -1084,7 +1096,7 @@ def _write(self, type, value, traceback):
|
|||||||
self._state_is_inconsistent = True
|
self._state_is_inconsistent = True
|
||||||
return
|
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
|
# Write a temporary database file them move it into place
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user