This repository was archived by the owner on Aug 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
feat: Add background-task for kernel-pull-progress #477
Open
youngjun0627
wants to merge
15
commits into
lablup:main
Choose a base branch
from
youngjun0627:feature/select-and-update-kernelpullprogress
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
35a207a
feat: Add progress columns to kernels table
youngjun0627 cee9b21
feat: select and update kernelpullprogress
youngjun0627 38c3f51
feat: Add bgtask for kernel-pull-progress
youngjun0627 b5deb3a
fix:change typos in session.py that do not match code style
youngjun0627 e150d63
fix: modify to maintain the existing API
youngjun0627 1f62cb4
Merge branch 'main' of https://github.com/lablup/backend.ai-manager i…
youngjun0627 0e62098
Merge branch 'main' into feature/select-and-update-kernelpullprogress
youngjun0627 b46869c
fix: extract the bgtask-function as callable class from _create
youngjun0627 b739171
Merge branch 'main' of https://github.com/lablup/backend.ai-manager i…
youngjun0627 3516ae2
merge branch 'main' into feature/select-and-update-kernelpullprogress
youngjun0627 c9400e5
Merge branch 'main' of https://github.com/lablup/backend.ai-manager i…
youngjun0627 7e40d86
Merge branch 'main' into feature/select-and-update-kernelpullprogress
youngjun0627 b4902d6
fix: bgtask(Callable class) is changed to function type
youngjun0627 60bfc69
fix: delete unnecessary files
youngjun0627 e2f01f4
fix: delete unnecessary codes
youngjun0627 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add background-task to update progress reporter with KernelPullProgressEvent, until kernel-pulling is done. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -72,6 +72,7 @@ | |||||
| SessionStartedEvent, | ||||||
| SessionSuccessEvent, | ||||||
| SessionTerminatedEvent, | ||||||
| KernelPullProgressEvent | ||||||
youngjun0627 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| ) | ||||||
| from ai.backend.common.logging import BraceStyleAdapter | ||||||
| from ai.backend.common.utils import cancel_tasks, str_to_timedelta | ||||||
|
|
@@ -85,6 +86,7 @@ | |||||
| ) | ||||||
| from ai.backend.common.plugin.monitor import GAUGE | ||||||
|
|
||||||
| from ..background import ProgressReporter | ||||||
youngjun0627 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| from ..config import DEFAULT_CHUNK_SIZE | ||||||
| from ..defs import DEFAULT_ROLE, REDIS_STREAM_DB | ||||||
| from ..models import ( | ||||||
|
|
@@ -481,7 +483,6 @@ async def _create(request: web.Request, params: Any) -> web.Response: | |||||
| params['bootstrap_script'] = script | ||||||
|
|
||||||
| try: | ||||||
|
|
||||||
| kernel_id = await asyncio.shield(root_ctx.registry.enqueue_session( | ||||||
| session_creation_id, | ||||||
| params['session_name'], owner_access_key, | ||||||
|
|
@@ -508,52 +509,70 @@ async def _create(request: web.Request, params: Any) -> web.Response: | |||||
| starts_at=starts_at, | ||||||
| )) | ||||||
| resp['sessionId'] = str(kernel_id) # changed since API v5 | ||||||
| resp['sessionName'] = str(params['session_name']) | ||||||
| resp['status'] = 'PENDING' | ||||||
| resp['servicePorts'] = [] | ||||||
| resp['created'] = True | ||||||
|
|
||||||
| if not params['enqueue_only']: | ||||||
| app_ctx.pending_waits.add(current_task) | ||||||
| max_wait = params['max_wait_seconds'] | ||||||
| try: | ||||||
| if max_wait > 0: | ||||||
| with timeout(max_wait): | ||||||
| await start_event.wait() | ||||||
| else: | ||||||
| await start_event.wait() | ||||||
| except asyncio.TimeoutError: | ||||||
| resp['status'] = 'TIMEOUT' | ||||||
| else: | ||||||
| await asyncio.sleep(0.5) | ||||||
| async with root_ctx.db.begin_readonly() as conn: | ||||||
| async def kernelpullprogress(reporter: ProgressReporter) -> None: | ||||||
youngjun0627 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| progress = [0, 0] | ||||||
|
|
||||||
| async def _get_status(kernel_id): | ||||||
| async with root_ctx.db.begin() as conn: | ||||||
youngjun0627 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| query = ( | ||||||
| sa.select([ | ||||||
| kernels.c.id, | ||||||
| kernels.c.status, | ||||||
| kernels.c.service_ports, | ||||||
| ]) | ||||||
| .select_from(kernels) | ||||||
| .where(kernels.c.id == kernel_id) | ||||||
| ) | ||||||
| result = await conn.execute(query) | ||||||
| row = result.first() | ||||||
| if row['status'] == KernelStatus.RUNNING: | ||||||
| resp['status'] = 'RUNNING' | ||||||
| for item in row['service_ports']: | ||||||
| response_dict = { | ||||||
| 'name': item['name'], | ||||||
| 'protocol': item['protocol'], | ||||||
| 'ports': item['container_ports'], | ||||||
| } | ||||||
| if 'url_template' in item.keys(): | ||||||
| response_dict['url_template'] = item['url_template'] | ||||||
| if 'allowed_arguments' in item.keys(): | ||||||
| response_dict['allowed_arguments'] = item['allowed_arguments'] | ||||||
| if 'allowed_envs' in item.keys(): | ||||||
| response_dict['allowed_envs'] = item['allowed_envs'] | ||||||
| resp['servicePorts'].append(response_dict) | ||||||
| else: | ||||||
| resp['status'] = row['status'].name | ||||||
|
|
||||||
| return result.first() | ||||||
|
|
||||||
| async def _update_progress( | ||||||
| app: web.Application, | ||||||
| source: AgentId, | ||||||
| event: KernelPullProgressEvent, | ||||||
| ) -> None: | ||||||
| # update both current and total | ||||||
| progress[0] = int(event.current_progress) | ||||||
| progress[1] = int(event.total_progress) | ||||||
|
|
||||||
| root_ctx.event_dispatcher.subscribe(KernelPullProgressEvent, request.app, _update_progress) | ||||||
| kernel_id = resp['sessionId'] | ||||||
| while True: | ||||||
| result = await _get_status(kernel_id) | ||||||
| if result is None: | ||||||
| continue | ||||||
| if result['status'] == KernelStatus.PREPARING: | ||||||
| await reporter.update(0) | ||||||
| if result['status'] == KernelStatus.RUNNING: | ||||||
| break | ||||||
| reporter.current_progress = progress[0] | ||||||
| reporter.total_progress = progress[1] | ||||||
| await reporter.update(0) | ||||||
| await asyncio.sleep(0.5) | ||||||
youngjun0627 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| task_id = await root_ctx.background_task_manager.start( | ||||||
| kernelpullprogress, | ||||||
| name='kernel-pull-progress' | ||||||
|
||||||
| name='kernel-pull-progress' | |
| name='kernel-pull-progress', |
youngjun0627 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
youngjun0627 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
youngjun0627 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
youngjun0627 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.