Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve stability of benchmark-based CPU throttle scaling #644

Merged
merged 1 commit into from
Apr 17, 2024
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
24 changes: 23 additions & 1 deletion internal/webpagetest.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,32 @@ def benchmark_cpu(self):
hash_val.update(hash_data)
iteration += 1
elapsed = monotonic() - start
self.cpu_scale_multiplier = 1.0 / elapsed
self.cpu_scale_multiplier = min(1.0 / elapsed, float(self.options.maxcpuscale))
logging.debug('CPU Benchmark elapsed time: %0.3f, multiplier: %0.3f',
elapsed, self.cpu_scale_multiplier)

# Get the median scale value from the last 9 benchmarks on this machine
try:
cpu_scale = []
scale_file = os.path.join(self.persistent_dir, 'cpu_scale.json')
if os.path.isfile(scale_file):
with open(scale_file, 'r') as f_in:
cpu_scale = json.load(f_in)
if type(cpu_scale) is list:
if len(cpu_scale) >= 9:
cpu_scale.pop(0)
cpu_scale.append(self.cpu_scale_multiplier)
if not os.path.isdir(self.persistent_dir):
os.makedirs(self.persistent_dir)
with open(scale_file, 'w') as f_out:
json.dump(cpu_scale, f_out)
cpu_scale.sort()
median_index = int((len(cpu_scale) - 1) / 2)
self.cpu_scale_multiplier = cpu_scale[median_index]
logging.debug('CPU Benchmark selected multiplier: %0.3f at index %d of %d values', self.cpu_scale_multiplier, median_index, len(cpu_scale))
except Exception:
logging.exception('Error processing benchmark history')

def get_persistent_dir(self):
"""Return the path to the persistent cache directory"""
return self.persistent_dir
Expand Down
2 changes: 2 additions & 0 deletions wptagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,8 @@ def main():
parser.add_argument('--healthcheckport', type=int, default=8889, help='Run a HTTP health check server on the given port.')
parser.add_argument('--har', action='store_true', default=False,
help="Generate a per-run HAR file as part of the test result (defaults to False).")
parser.add_argument('--maxcpuscale', type=int, default=2,
help='Maximum scaling to apply to CPU throttle based on host benchmark (defaults to 2).')

# Video capture/display settings
parser.add_argument('--xvfb', action='store_true', default=False,
Expand Down
Loading