From 20679f74e8816f4b064cd5e5786ea81f342d8e87 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Thu, 4 Jun 2020 07:06:19 -0400 Subject: [PATCH 1/3] Attempt to fix PhoneHomeStatsTestCase.test_performance_100 being flaky. --- synapse/app/homeserver.py | 42 +++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py index 730a2c015b9e..327d5cd2889c 100644 --- a/synapse/app/homeserver.py +++ b/synapse/app/homeserver.py @@ -488,6 +488,29 @@ def phone_stats_home(hs, stats, stats_process=_stats_process): if uptime < 0: uptime = 0 + # + # Performance statistics + # + old = stats_process[0] + new = (now, resource.getrusage(resource.RUSAGE_SELF)) + stats_process[0] = new + + # Get RSS in bytes + stats["memory_rss"] = new[1].ru_maxrss + + # Get CPU time in % of a single core, not % of all cores + used_cpu_time = (new[1].ru_utime + new[1].ru_stime) - ( + old[1].ru_utime + old[1].ru_stime + ) + if used_cpu_time == 0 or new[0] == old[0]: + stats["cpu_average"] = 0 + else: + stats["cpu_average"] = math.floor(used_cpu_time / (new[0] - old[0]) * 100) + + # + # General statistics + # + stats["homeserver"] = hs.config.server_name stats["server_context"] = hs.config.server_context stats["timestamp"] = now @@ -522,25 +545,6 @@ def phone_stats_home(hs, stats, stats_process=_stats_process): stats["cache_factor"] = hs.config.caches.global_factor stats["event_cache_size"] = hs.config.caches.event_cache_size - # - # Performance statistics - # - old = stats_process[0] - new = (now, resource.getrusage(resource.RUSAGE_SELF)) - stats_process[0] = new - - # Get RSS in bytes - stats["memory_rss"] = new[1].ru_maxrss - - # Get CPU time in % of a single core, not % of all cores - used_cpu_time = (new[1].ru_utime + new[1].ru_stime) - ( - old[1].ru_utime + old[1].ru_stime - ) - if used_cpu_time == 0 or new[0] == old[0]: - stats["cpu_average"] = 0 - else: - stats["cpu_average"] = math.floor(used_cpu_time / (new[0] - old[0]) * 100) - # # Database version # From 2e8ee219241bf8393c438ae5a0a67938754a8033 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Thu, 4 Jun 2020 07:29:54 -0400 Subject: [PATCH 2/3] Add newsfragment. --- changelog.d/7634.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/7634.misc diff --git a/changelog.d/7634.misc b/changelog.d/7634.misc new file mode 100644 index 000000000000..50dc6df02ef0 --- /dev/null +++ b/changelog.d/7634.misc @@ -0,0 +1 @@ +Attempt to fix flaky test: `PhoneHomeStatsTestCase.test_performance_100`. From 2cda38a0e8307d6b18435df749e8274960cd40d9 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Fri, 5 Jun 2020 07:10:24 -0400 Subject: [PATCH 3/3] Add a comment to keep the perf stats early. Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> --- synapse/app/homeserver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py index 327d5cd2889c..8454d7485864 100644 --- a/synapse/app/homeserver.py +++ b/synapse/app/homeserver.py @@ -489,7 +489,7 @@ def phone_stats_home(hs, stats, stats_process=_stats_process): uptime = 0 # - # Performance statistics + # Performance statistics. Keep this early in the function to maintain reliability of `test_performance_100` test. # old = stats_process[0] new = (now, resource.getrusage(resource.RUSAGE_SELF))