Sobes.tech
Junior — Middle

What tools do you use for system performance monitoring and testing?

sobes.tech AI

Answer from AI

For monitoring and testing system performance in Python, the following tools are often used:

  • psutil — a library for obtaining information about CPU load, memory, disks, and network.
  • timeit — a module for measuring the execution time of small code snippets.
  • cProfile — a built-in profiler for analyzing the performance of the entire application.
  • locust — a tool for load testing web applications.
  • pytest-benchmark — a plugin for pytest to measure the performance of tested code.

Example of using psutil to monitor CPU load:

import psutil

cpu_percent = psutil.cpu_percent(interval=1)
print(f"CPU Load: {cpu_percent}%")

For load testing a web service, you can write a script in locust that simulates users and measures response time.