Skip to content

Commit

Permalink
Add a minimal last idle time
Browse files Browse the repository at this point in the history
  • Loading branch information
wjsi committed Mar 24, 2022
1 parent 8d9f0c6 commit 3ed2e3c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion mars/services/session/supervisor/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import asyncio
import functools
import time
from typing import Dict, List, Optional

from .... import oscar as mo
Expand All @@ -28,9 +29,11 @@ def __init__(self, service_config: Optional[Dict] = None):
self._session_refs: Dict[str, mo.ActorRef] = dict()
self._cluster_api: Optional[ClusterAPI] = None
self._service_config = service_config or dict()
self._stored_last_idle_time = None

async def __post_create__(self):
self._cluster_api = await ClusterAPI.create(self.address)
self._stored_last_idle_time = time.time()

async def __pre_destroy__(self):
await asyncio.gather(
Expand Down Expand Up @@ -124,7 +127,10 @@ async def get_last_idle_time(self, session_id=None):
if any(last_idle_time is None for last_idle_time in all_last_idle_time):
raise mo.Return(None)
else:
raise mo.Return(max(all_last_idle_time))
self._stored_last_idle_time = max(
[self._stored_last_idle_time] + all_last_idle_time
)
raise mo.Return(self._stored_last_idle_time)


class SessionActor(mo.Actor):
Expand Down
4 changes: 4 additions & 0 deletions mars/services/session/tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import threading
import time

import pytest
import numpy as np
Expand Down Expand Up @@ -99,7 +100,10 @@ async def test_get_last_idle_time():
NodeRole.WORKER, config, address=worker_pool.external_address
)

start_time = time.time()
session_api = await SessionAPI.create(sv_pool.external_address)
assert await session_api.get_last_idle_time() < start_time

session_id = "test_session"
await session_api.create_session(session_id)
# check last idle time is not None
Expand Down

0 comments on commit 3ed2e3c

Please sign in to comment.