Co-authored-by: Ara Adkins <me@ara.io>
3.7 KiB
layout | title | category | tags | order | |||
---|---|---|---|---|---|---|---|
developer-doc | Execution Server Flow | runtime |
|
6 |
Execution Server Flow
This document describes the API and workflow of the internal execution server.
Opening a Connection
The actionables for this section are:
- describe the
org.graalvm.polyglot.Context.Builder.serverTransport
workflow of connecting to the server.
API
The actionables for this section are:
- Document the server's API.
Internal Architecture
This section describes certain implementation details of the execution server, allowing it to perform its operations safely and interactively.
Job Queue
The execution server uses a job queue containing requests to be performed. An API method may queue multiple jobs.
Job Types
There are a number of job types used internally for handling different scenarios:
EnsureCompiled
Takes a set of module names that must be compiled and ensures that the
corresponding modules are compiled in the newest version.
It also performs cache invalidations on changes since the last batch.
Caches should be invalidated for all contexts affected by this recompilation.
This operation is idempotent and should be run before any Execute
action.
This operation is not currently interruptible, but may become so in the future.
Execute
Takes a context ID and an optional set of expression IDs that should be executed. and executes the Enso code corresponding to the context's stack. Updates caches and sends updates to the users.
This operation is interruptible through Thread.interrupt()
.
Scheduling Rules
EnsureCompiled
jobs must be run sequentially (i.e. no other state modifications or executions are allowed during this job's run).Execute
jobs may be run in parallel with each other (but not withEnsureCompiled
jobs).EnsureCompiled
jobs may be collapsed into one, by unifying their module sets.Execute
jobs with the samecontextId
may be collapsed into one, by merging theirexpression IDs
sets.- All enqueued
EnsureCompiled
jobs should run before anyExecute
jobs. - The order of
EnsureCompiled
jobs can be freely changed by the compiler.
API Methods to Jobs Translation
The following describes handling of API messages through job queue modifications.
- EditFile:
- Abort and/or dequeue all pending and running messages (if possible).
- Synchronously perform all code updates.
- Enqueue an
EnsureCompiled
with all affected files. - Enqueue an
Execute
for each existing context.
- Stack Modifications and Recomputes:
- Abort and/or dequeue all pending and running requests relevant to the affected context.
- Synchronously perform all state updates.
- Respond to the user.
- Enqueue EnsureCompiled for the file at the bottom of the affected context's stack.
- Enqueue Execute for the affected context.
- Visualization modifications:
- Synchronously perform all state updates.
- Respond to the user.
- Enqueue
EnsureCompiled
andExecute
for the affected context. Set the minimal set of expressions required to compute toSet(visualizedExpression)
in theExecute
command.
- Create/Destroy context:
- Abort any jobs concerning the affected context.
- Perform state updates / cleanups. No jobs to schedule.