[Misc] Log time consumption of sleep and wake-up (#13115)

Signed-off-by: Jun Duan <jun.duan.phd@outlook.com>
This commit is contained in:
Jun Duan 2025-02-14 07:10:21 -05:00 committed by GitHub
parent 83481ceb49
commit 556ef7f714
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,6 +1,7 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import asyncio import asyncio
import time
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from typing import (Any, Awaitable, Callable, Dict, List, Optional, Set, Tuple, from typing import (Any, Awaitable, Callable, Dict, List, Optional, Set, Tuple,
Union) Union)
@ -200,15 +201,23 @@ class ExecutorBase(ABC):
if self.is_sleeping: if self.is_sleeping:
logger.warning("Executor is already sleeping.") logger.warning("Executor is already sleeping.")
return return
time_before_sleep = time.perf_counter()
self.collective_rpc("sleep", kwargs=dict(level=level)) self.collective_rpc("sleep", kwargs=dict(level=level))
time_after_sleep = time.perf_counter()
self.is_sleeping = True self.is_sleeping = True
logger.info("It took %.6f seconds to fall asleep.",
time_after_sleep - time_before_sleep)
def wake_up(self): def wake_up(self):
if not self.is_sleeping: if not self.is_sleeping:
logger.warning("Executor is not sleeping.") logger.warning("Executor is not sleeping.")
return return
time_before_wakeup = time.perf_counter()
self.collective_rpc("wake_up") self.collective_rpc("wake_up")
time_after_wakeup = time.perf_counter()
self.is_sleeping = False self.is_sleeping = False
logger.info("It took %.6f seconds to wake up.",
time_after_wakeup - time_before_wakeup)
def save_sharded_state( def save_sharded_state(
self, self,