Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Attempt to fix PhoneHomeStatsTestCase.test_performance_100 being flaky. #7634

Merged
merged 3 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/7634.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Attempt to fix flaky test: `PhoneHomeStatsTestCase.test_performance_100`.
42 changes: 23 additions & 19 deletions synapse/app/homeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
#
Expand Down