Skip to content

Commit

Permalink
sweep: DIRACGrid#7692 Drop stalled Mysql connection reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
chaen authored and web-flow committed Jun 25, 2024
1 parent 5f268bd commit 54a225e
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ DIRAC_M2CRYPTO_SSL_CIPHERS
DIRAC_M2CRYPTO_SSL_METHODS
If set, overwrites the default SSL methods accepted. It should be a colon separated list. See :py:mod:`DIRAC.Core.DISET`

DIRAC_MYSQL_CONNECTION_GRACE_TIME
If set to an integer, default of the grace time before the connection is reused. See :py:class:`DIRAC.Core.Utilities.MySQL.ConnectionPool`

DIRAC_MYSQL_OPTIMIZER_TRACES_PATH
If set, it should point to an existing directory, where MySQL Optimizer traces will be stored. See :py:func:`DIRAC.Core.Utilities.MySQL.captureOptimizerTraces`

Expand Down
23 changes: 1 addition & 22 deletions src/DIRAC/Core/Utilities/MySQL.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,26 +327,11 @@ class ConnectionPool:
Management of connections per thread
"""

# The idea of the grace time is that a given thread should not keep a connection object for too long
# However, in case of long running queries, this is unavoidable.
# If the DISET/HTTPs connection timeout is longer than the MySQL grace time,
# the connection will be reallocated to another thread, and that does not go down well
# From the mysqlclient doc ("threadsafety" of https://mysqlclient.readthedocs.io/user_guide.html#mysqldb)
# "The general upshot of this is: Don’t share connections between threads."
# The best thing to do, if we don't want to have a lock, is to set this value to 0
# so it is not used. LHCb will run in prod with the value 0 for a while, and if no issue arrises,
# it will become the default
try:
MYSQL_CONNECTION_GRACE_TIME = int(os.environ.get("DIRAC_MYSQL_CONNECTION_GRACE_TIME"))
except Exception:
MYSQL_CONNECTION_GRACE_TIME = 600

def __init__(self, host, user, passwd, port=3306, graceTime=MYSQL_CONNECTION_GRACE_TIME):
def __init__(self, host, user, passwd, port=3306):
self.__host = host
self.__user = user
self.__passwd = passwd
self.__port = port
self.__graceTime = graceTime
self.__spares = collections.deque()
self.__maxSpares = 10
self.__lastClean = 0
Expand Down Expand Up @@ -456,12 +441,6 @@ def clean(self, now=False):
for thid in list(self.__assigned):
if not thid.is_alive():
self.__pop(thid)
try:
data = self.__assigned[thid]
except KeyError:
continue
if self.__graceTime and now - data[2] > self.__graceTime:
self.__pop(thid)

def transactionStart(self, dbName):
result = self.get(dbName)
Expand Down

0 comments on commit 54a225e

Please sign in to comment.