diff options
author | Patrick Cloke <clokep@users.noreply.github.com> | 2020-06-05 07:36:47 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-05 07:36:47 -0400 |
commit | 02f345d053db79b92e00c364a2276dfbd64cc9ff (patch) | |
tree | 65785dc18cb87eee4bfe2f40cff16657901f759a /synapse | |
parent | Support CS API v0.6.0 (#6585) (diff) | |
download | synapse-02f345d053db79b92e00c364a2276dfbd64cc9ff.tar.xz |
Attempt to fix PhoneHomeStatsTestCase.test_performance_100 being flaky. (#7634)
Diffstat (limited to 'synapse')
-rw-r--r-- | synapse/app/homeserver.py | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py index 730a2c015b..8454d74858 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. 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)) + 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 @@ -523,25 +546,6 @@ def phone_stats_home(hs, stats, stats_process=_stats_process): 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 # |