Skip to content

Commit 4db73a2

Browse files
Merge pull request #6779 from cylc/8.4.x-sync
🤖 Merge 8.4.x-sync into master
2 parents 49ce906 + c55ea42 commit 4db73a2

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

changes.d/6727.fix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed a memory leak affecting both scheduler and UI server.

cylc/flow/cfgspec/globalcfg.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,10 @@ def default_for(
907907
908908
This should be a multiline string containing Python expressions
909909
to rank and/or filter hosts. All `psutil`_ attributes are
910-
available for use in these expressions.
910+
available for use in these expressions, e.g, ``cpu_percent``.
911+
You can supply these with positional arguments e.g,
912+
``cpu_percent(1)``, however, keyword arguments will not work
913+
e.g, ``cpu_percent(interval=1)``.
911914
912915
.. rubric:: Ranking
913916

cylc/flow/data_store_mgr.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,15 @@ def runtime_from_config(rtconfig):
295295
)
296296

297297

298+
def reset_protobuf_object(msg_class, msg_orig):
299+
"""Reset object to clear memory build-up."""
300+
# See: https://github.com/protocolbuffers/protobuf/issues/19674
301+
# The new message instantiation needs happen on a separate line.
302+
new_msg = msg_class()
303+
new_msg.CopyFrom(msg_orig)
304+
return new_msg
305+
306+
298307
def apply_delta(key, delta, data):
299308
"""Apply delta to specific data-store workflow and type."""
300309
# Assimilate new data
@@ -322,6 +331,12 @@ def apply_delta(key, delta, data):
322331
if field.name in CLEAR_FIELD_MAP[key]:
323332
data_element.ClearField(field.name)
324333
data_element.MergeFrom(element)
334+
# Clear memory accumulation
335+
if key in (TASKS, FAMILIES):
336+
data[key][element.id] = reset_protobuf_object(
337+
MESSAGE_MAP[key],
338+
data_element
339+
)
325340
except KeyError as exc:
326341
# Ensure data-sync doesn't fail with
327342
# network issues, sync reconcile/validate will catch.
@@ -330,6 +345,9 @@ def apply_delta(key, delta, data):
330345
'on update application: %s' % str(exc)
331346
)
332347
continue
348+
# Clear memory accumulation
349+
if key == WORKFLOW:
350+
data[key] = reset_protobuf_object(PbWorkflow, data[key])
333351
# Prune data elements
334352
if hasattr(delta, 'pruned'):
335353
# UIS flag to prune workflow, set externally.

0 commit comments

Comments
 (0)