Run the load generator for the configured duration.
(self)
| 617 | pass |
| 618 | |
| 619 | async def run(self) -> BenchmarkResult: |
| 620 | """Run the load generator for the configured duration.""" |
| 621 | self.latencies = [] |
| 622 | self.errors = 0 |
| 623 | self.first_error = None |
| 624 | self.cpu_samples = [] |
| 625 | self.memory_samples = [] |
| 626 | |
| 627 | # Initialize CPU percent tracking |
| 628 | if self._process: |
| 629 | try: |
| 630 | self._process.cpu_percent(interval=None) |
| 631 | except Exception: |
| 632 | pass |
| 633 | |
| 634 | print(f" Running load for {self.config.duration_seconds}s...") |
| 635 | start_time = time.monotonic() |
| 636 | end_time = start_time + self.config.duration_seconds |
| 637 | last_sample_time = start_time |
| 638 | sample_interval = 0.5 |
| 639 | |
| 640 | while time.monotonic() < end_time: |
| 641 | latency = await self._run_operation() |
| 642 | if latency > 0: |
| 643 | self.latencies.append(latency) |
| 644 | |
| 645 | # Sample resources periodically |
| 646 | current_time = time.monotonic() |
| 647 | if current_time - last_sample_time >= sample_interval: |
| 648 | self._sample_resources() |
| 649 | last_sample_time = current_time |
| 650 | |
| 651 | # Final resource sample |
| 652 | self._sample_resources() |
| 653 | |
| 654 | actual_duration = time.monotonic() - start_time |
| 655 | return self._calculate_results(actual_duration) |
| 656 | |
| 657 | def _calculate_results(self, duration: float) -> BenchmarkResult: |
| 658 | """Calculate benchmark results from collected latencies.""" |
no test coverage detected