33
44
55import asyncio
6+ import gc
67
78from aiperf .common .base_component_service import BaseComponentService
89from aiperf .common .config import ServiceConfig , UserConfig
3435)
3536from aiperf .common .mixins import PullClientMixin
3637from aiperf .common .models import DatasetMetadata
37- from aiperf .common .protocols import (
38- PushClientProtocol ,
39- ServiceProtocol ,
40- )
41- from aiperf .timing .config import (
42- TimingManagerConfig ,
43- )
38+ from aiperf .common .protocols import PushClientProtocol , ServiceProtocol
39+ from aiperf .timing .config import TimingManagerConfig
4440from aiperf .timing .credit_issuing_strategy import (
4541 CreditIssuingStrategy ,
4642 CreditIssuingStrategyFactory ,
@@ -140,6 +136,11 @@ async def _on_start_profiling(self, message: CommandMessage) -> None:
140136 if not self ._credit_issuing_strategy :
141137 raise InvalidStateError ("No credit issuing strategy configured" )
142138
139+ # Disable garbage collection to prevent large pauses during profiling
140+ gc .collect ()
141+ gc .freeze ()
142+ gc .disable ()
143+
143144 self .execute_async (self ._credit_issuing_strategy .start ())
144145 self .info (
145146 f"Credit issuing strategy for { self .config .timing_mode .title ()} started"
@@ -160,6 +161,11 @@ async def _handle_profile_cancel_command(
160161 async def _timing_manager_stop (self ) -> None :
161162 """Stop the timing manager."""
162163 self .debug ("Stopping timing manager" )
164+
165+ # Re-enable garbage collection to allow the timing manager to clean up resources
166+ gc .unfreeze ()
167+ gc .enable ()
168+
163169 if self ._credit_issuing_strategy :
164170 await self ._credit_issuing_strategy .stop ()
165171 await self .cancel_all_tasks ()
0 commit comments