Skip to content

Commit da69dd4

Browse files
authored
[rqd] Rewrite rqnimby logic (#1680)
The previous pynput based implementation was more complex than needed due to the effort to keep backwards compatibility with the previously implementation based on Select. This change removes support to the Select based implementation in favor of a simplified logic using pynput. Given that the Select method was outdated and incompatible with modern versions of linux, supporting it is no longer necessary.
1 parent cd18049 commit da69dd4

File tree

8 files changed

+265
-497
lines changed

8 files changed

+265
-497
lines changed

rqd/rqd/rqconstants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@
107107
CHECK_INTERVAL_LOCKED = 60
108108
# Seconds of idle time required before nimby unlocks.
109109
MINIMUM_IDLE = 900
110+
# Default display configuration in case the environment variable DISPLAY is not set
111+
DEFAULT_DISPLAY = ":0"
110112
# If available memory drops below this amount, lock nimby (need to take into account cache).
111113
MINIMUM_MEM = 524288
112114
MINIMUM_SWAP = 1048576

rqd/rqd/rqcore.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
import rqd.rqexceptions
4646
import rqd.rqmachine
4747
import rqd.rqnetwork
48-
import rqd.rqnimby
48+
from rqd.rqnimby import Nimby
4949
import rqd.rqutil
5050
import rqd.rqlogging
5151

@@ -74,7 +74,7 @@ def __init__(self, optNimbyoff=False):
7474
reserved_cores=[],
7575
)
7676

77-
self.nimby = rqd.rqnimby.NimbyFactory.getNimby(self)
77+
self.nimby = Nimby(self)
7878

7979
self.machine = rqd.rqmachine.Machine(self, self.cores)
8080
self.network = rqd.rqnetwork.Network(self)
@@ -395,11 +395,6 @@ def launchFrame(self, runFrame):
395395
log.info(err)
396396
raise rqd.rqexceptions.CoreReservationFailureException(err)
397397

398-
if rqd.rqconstants.OVERRIDE_NIMBY and self.nimby.isNimbyActive():
399-
err = "Not launching, rqd is lockNimby and User is Active"
400-
log.info(err)
401-
raise rqd.rqexceptions.CoreReservationFailureException(err)
402-
403398
if runFrame.frame_id in self.__cache:
404399
err = "Not launching, frame is already running on this proc %s" % runFrame.frame_id
405400
log.critical(err)
@@ -506,22 +501,19 @@ def rebootIdle(self):
506501
def nimbyOn(self):
507502
"""Activates nimby, does not kill any running frames until next nimby
508503
event. Also does not unlock until sufficient idle time is reached."""
509-
if self.nimby and not self.nimby.active:
504+
if self.nimby and self.nimby.is_ready:
510505
try:
511-
self.nimby.run()
506+
self.nimby.start()
512507
log.warning("Nimby has been activated")
513508
# pylint: disable=broad-except
514509
except Exception:
515-
self.nimby.locked = False
516-
err = "Nimby is in the process of shutting down"
510+
err = "Nimby failed to start. Unexpected state"
517511
log.exception(err)
518-
raise rqd.rqexceptions.RqdException(err)
519512

520513
def nimbyOff(self):
521514
"""Deactivates nimby and unlocks any nimby lock"""
522-
if self.nimby.active:
523-
self.nimby.stop()
524-
log.info("Nimby has been deactivated")
515+
self.nimby.stop()
516+
log.info("Nimby has been deactivated")
525517

526518
def onNimbyLock(self):
527519
"""This is called by nimby when it locks the machine.

rqd/rqd/rqmachine.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,6 @@ def isNimbySafeToRunJobs(self):
126126
# pylint: enable=no-member
127127
return True
128128

129-
def isNimbySafeToUnlock(self):
130-
"""Returns False if nimby should not unlock due to resource limits"""
131-
if not self.isNimbySafeToRunJobs():
132-
return False
133-
if self.getLoadAvg() / self.__coreInfo.total_cores > rqd.rqconstants.MAXIMUM_LOAD:
134-
return False
135-
return True
136-
137129
@rqd.rqutil.Memoize
138130
def isDesktop(self):
139131
"""Returns True if machine starts in run level 5 (X11)
@@ -859,7 +851,7 @@ def updateMachineStats(self):
859851

860852
# Updates dynamic information
861853
self.__renderHost.load = self.getLoadAvg()
862-
self.__renderHost.nimby_enabled = self.__rqCore.nimby.active
854+
self.__renderHost.nimby_enabled = self.__rqCore.nimby.is_ready
863855
self.__renderHost.nimby_locked = self.__rqCore.nimby.locked
864856
self.__renderHost.state = self.state
865857

0 commit comments

Comments
 (0)