x2gobroker.loadchecker module¶
The X2Go Broker Load Checker is an auxiliary X2Go Session Broker service that checks the load on associated X2Go Servers in regular intervals.
The load of an X2Go Server gets checked by the Load Checker, if
an X2Go Server is part of a multi-server session profile
the remote X2Go Server can be queried via X2Go Broker Agent
the session profile (or the broker globally) is configured for background load checking (see global config parameter:
load-checker
in/etc/x2go/x2gobroker.conf
In non-load-checker setups, multi-server session profiles perform a check on all configured servers during the login phase of a user. On big server farms, this check-them-all call to all members of the X2Go Server farm can be really time consuming.
The solution is to run the X2Go Broker Load Checker service on the broker
host and let it query server availability and load in regular intervals.
It collects the server metrics and stores them in memory. If the broker
receives a select_session()
request from an
X2Go client application, it will then negotiate with the load checker to
work out, what X2Go Server is best for this incoming request.
On the X2Go Servers, the X2Go Broker Agent calculates a load_factor
that
gets passed back to the X2Go Broker Load Checker when queried:
( memAvail/1000 ) * numCPUs * typeCPUs
load-factor = -------------------------------------- + 1
loadavg*100 * numSessions
- class x2gobroker.loadchecker.LoadChecker(config_file=None, config_defaults=None, logger=None, **kwargs)[source]¶
Bases:
threading.Thread
The
LoadChecker
class provides the functionality of setting up a load checker service. It is the brain of thex2gobroker-loadchecker
executable.With it you can instantiate a new LoadChecker object for querying remote X2Go Broker Agent instances about server/system load, CPU usage, etc. in regular intervals.
- Parameters
config_file (a
configparser
compliant<obj>
) – globalx2gobroker
config fileconfig_defaults (
dict
) – default (hard-coded) configuration parameters for all parameters missing in theconfig_file
logger (
<obj>
) – alogging
instancekwargs (
dict
) – Any other parameter (for future features’ compatibility, all ignored for now)
- get_profile_load(backend, profile_id)[source]¶
Retrieve system load factors for all member servers of the given profile ID (and the given broker backend).
- Parameters
backend (
str
) – broker backend to query.profile_id (
str
) – profile ID of the session profile to query
- Returns
load factors of the given profile ID (or None if an error occurs)
- Return type
dict
- get_server_load(backend, profile_id, hostname)[source]¶
Retrieve system load factor for a given server (via broker backend, profile ID and hostname).
- Parameters
backend (
str
) – broker backend to query.profile_id (
str
) – profile ID of the session profile to queryhostname (
str
) – hostname of the X2Go Server
- Returns
load factor of the given server (or None if an error occurs)
- Return type
int
- loadchecker()[source]¶
This is the actual thread runner of the
LoadChecker`
class.It queries configured / available X2Go Broker Agents in regular intervals about system load, CPU types and usage.
- stop_thread()[source]¶
Induce a stop of the running
LoadChecker
’ thread.When stopped, no more queries to remote X2Go Servers will be made.
- x2gobroker.loadchecker.check_load(backend, profile_id, hostname=None)[source]¶
This function gets called from the broker daemon’s side whenever the broker needs information about associated X2Go Servers. It represents the client-side of the load checking process in X2Go Session Broker.
It either sends a one liner 3-tuple:
<backend>\r<profile_id>\r<hostname>\n
or a one liner 2-tuple:
<backend>\r<profile_id>\n
to the
X2GOBROKER_LOADCHECKER_SOCKET
(seex2gobroker.defaults
) and expects a number (if the hostname was included in the query) or a Python dictionary (if onlybackend
andprofile_id
had been given) as return value: the load factor(s)- Parameters
backend (
str
) – the broker backend in useprofile_id (
str
) – the session profile’s IDhostname (
str
) – the X2Go Server’s hostname as shown inx2golistsessions
’s output
- Returns
either the load factor of the asked for server (as
int
) or the load factors (asdict
) of all server members of the given session profile server- Return type
int
ordict