Skip to content

Commit 3a91f36

Browse files
Add Session workflows documentation (#808)
* Add Session workflows documentation * Changes after review * Changes for Kernel Shutdown * Update docs/source/developers/architecture.rst Co-authored-by: Steven Silvester <[email protected]> * Update docs/source/developers/architecture.rst Co-authored-by: Steven Silvester <[email protected]> * Update docs/source/developers/architecture.rst Co-authored-by: Steven Silvester <[email protected]> Co-authored-by: Steven Silvester <[email protected]>
1 parent 0309034 commit 3a91f36

File tree

3 files changed

+123
-16
lines changed

3 files changed

+123
-16
lines changed

docs/source/developers/architecture.rst

Lines changed: 123 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ open source tool to edit the png file.
1414
Jupyter Server Architecture
1515
---------------------------
1616

17-
The Jupyter Server system can be seen in figure below:
17+
The Jupyter Server system can be seen in the figure below:
1818

1919
.. image:: ../images/jupyter-server-architecture.drawio.png
2020
:alt: Jupyter Server Architecture
@@ -36,38 +36,145 @@ Jupyter Server contains the following components:
3636
ServerApp with extra request handlers.
3737

3838
- **Gateway Server** is a web server that, when configured, provides access to
39-
Jupyter Kernels running on other hosts. There are different ways to create a
40-
gateway server. If your ServerApp needs to communicate with remote Kernels
39+
Jupyter kernels running on other hosts. There are different ways to create a
40+
gateway server. If your ServerApp needs to communicate with remote kernels
4141
residing within resource-managed clusters, you can use
4242
`Enterprise Gateway <https://github.com/jupyter-server/enterprise_gateway>`_,
4343
otherwise, you can use
4444
`Kernel Gateway <https://github.com/jupyter-server/kernel_gateway>`_, where
45-
Kernels run locally to the gateway server.
45+
kernels run locally to the gateway server.
4646

4747
- **Contents Manager and File Contents Manager** are responsible for serving
4848
Notebook on the file system. Session Manager uses Contents Manager to receive
49-
Kernel path. Follow :ref:`the Contents API guide <contents_api>` to learn
49+
kernel path. Follow :ref:`the Contents API guide <contents_api>` to learn
5050
about Contents Manager.
5151

52-
- **Session Manager** processes users' Sessions. When a user starts a new Kernel,
53-
Session Manager starts a process to provision Kernel for the user and generates
52+
- **Session Manager** processes users' Sessions. When a user starts a new kernel,
53+
Session Manager starts a process to provision kernel for the user and generates
5454
a new Session ID. Each opened Notebook has a separate Session, but different
55-
Notebook Kernels can use the same Session. That is useful if the user wants to
55+
Notebook kernels can use the same Session. That is useful if the user wants to
5656
share data across various opened Notebooks. Session Manager uses SQLite3
57-
DataBase to store the Session information. The database is stored in memory by
57+
database to store the Session information. The database is stored in memory by
5858
default, but can be configured to save to disk.
5959

6060
- **Mapping Kernel Manager** is responsible for managing the lifecycles of the
61-
Kernels running within the ServerApp. It starts a new Kernel for a user's Session
62-
and facilitates interrupt, restart, and shutdown operations against the Kernel.
61+
kernels running within the ServerApp. It starts a new kernel for a user's Session
62+
and facilitates interrupt, restart, and shutdown operations against the kernel.
6363

6464
- **Jupyter Client** library is used by Jupyter Server to work with the Notebook
65-
Kernels.
65+
kernels.
6666

67-
- **Kernel Manager** manages a single Kernel for the Notebook. To know more about
67+
- **Kernel Manager** manages a single kernel for the Notebook. To know more about
6868
Kernel Manager, follow
6969
`the Jupyter Client APIs documentation <https://jupyter-client.readthedocs.io/en/latest/api/manager.html#jupyter_client.KernelManager>`_.
7070

71-
- **Kernel Spec Manager** parses files with JSON specification for a Kernels,
72-
and provides a list of available Kernel configurations. To learn about
73-
Kernel Spec, check `the Jupyter Client guide <https://jupyter-client.readthedocs.io/en/stable/kernels.html#kernel-specs>`_.
71+
- **Kernel Spec Manager** parses files with JSON specification for a kernels,
72+
and provides a list of available kernel configurations. To learn about
73+
Kernel Spec Manager, check `the Jupyter Client guide <https://jupyter-client.readthedocs.io/en/stable/kernels.html#kernel-specs>`_.
74+
75+
Create Session Workflow
76+
-----------------------
77+
78+
The create Session workflow can be seen in the figure below:
79+
80+
.. image:: ../images/session-create.drawio.png
81+
:alt: Create Session Workflow
82+
:width: 90%
83+
:align: center
84+
85+
When a user starts a new kernel, the following steps occur:
86+
87+
#. The Notebook client sends |create_session|_ request to Jupyter Server. This
88+
request has all necessary data, such as Notebook name, type, path, and kernel
89+
name.
90+
91+
#. **Session Manager** asks **Contents Manager** for the kernel file system path
92+
based on the input data.
93+
94+
#. **Session Manager** sends kernel path to **Mapping Kernel Manager**.
95+
96+
#. **Mapping Kernel Manager** starts the kernel create process by using
97+
**Multi Kernel Manager** and **Kernel Manager**. You can learn more about
98+
**Multi Kernel Manager** in
99+
`the Jupyter Client APIs <https://jupyter-client.readthedocs.io/en/latest/api/manager.html#multikernelmanager-controlling-multiple-kernels>`_.
100+
101+
#. **Kernel Manager** uses the provisioner layer to launch a new kernel.
102+
103+
#. **Kernel Provisioner** is responsible for launching kernels based on the
104+
kernel specification. If the kernel specification doesn't define a provisioner,
105+
it uses `Local Provisioner <https://jupyter-client.readthedocs.io/en/latest/api/provisioners.html#jupyter_client.provisioning.local_provisioner.LocalProvisioner>`_
106+
to launch the kernel. You can use
107+
`Kernel Provisioner Base <https://jupyter-client.readthedocs.io/en/latest/api/provisioners.html#jupyter_client.provisioning.provisioner_base.KernelProvisionerBase>`_
108+
and
109+
`Kernel Provisioner Factory <https://jupyter-client.readthedocs.io/en/latest/api/provisioners.html#jupyter_client.provisioning.factory.KernelProvisionerFactory>`_
110+
to create custom provisioners.
111+
112+
#. **Kernel Spec Manager** gets the kernel specification from the JSON file.
113+
The specification is located in ``kernel.json`` file.
114+
115+
#. Once **Kernel Provisioner** launches the kernel,
116+
**Kernel Manager** generates the new kernel ID for **Session Manager**.
117+
118+
#. **Session Manager** saves the new Session data to the SQLite3 database
119+
(Session ID, Notebook path, Notebook name, Notebook type, and kernel ID).
120+
121+
#. Notebook client receives the created Session data.
122+
123+
.. _create_session: https://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/jupyter_server/master/jupyter_server/services/api/api.yaml#/sessions/post_api_sessions
124+
125+
.. |create_session| replace:: the *POST /api/sessions*
126+
127+
Delete Session Workflow
128+
-----------------------
129+
130+
The delete Session workflow can be seen in the figure below:
131+
132+
.. image:: ../images/session-delete.drawio.png
133+
:alt: Delete Session Workflow
134+
:width: 80%
135+
:align: center
136+
137+
When a user stops a kernel, the following steps occur:
138+
139+
#. The Notebook client sends |delete_session|_ request to Jupyter Server. This
140+
request has the Session ID that kernel is currently using.
141+
142+
#. **Session Manager** gets the Session data from the SQLite3 database and sends
143+
the kernel ID to **Mapping Kernel Manager**.
144+
145+
#. **Mapping Kernel Manager** starts the kernel shutdown process by using
146+
**Multi Kernel Manager** and **Kernel Manager**.
147+
148+
#. **Kernel Manager** determines the mode of interrupt from the
149+
**Kernel Spec Manager**. It supports ``Signal`` and ``Message``
150+
interrupt modes. By default, the ``Signal`` interrupt mode is being used.
151+
152+
- When the interrupt mode is ``Signal``, the **Kernel Provisioner**
153+
interrupts the kernel with the ``SIGINT`` operating system signal
154+
(although other provisioner implementations may use a different approach).
155+
156+
- When interrupt mode is ``Message``, Session sends
157+
the `"interrupt_request" <https://jupyter-client.readthedocs.io/en/latest/messaging.html#msging-interrupt>`_
158+
message on the control channel.
159+
160+
#. After interrupting kernel, Session sends the `"shutdown_request" <https://jupyter-client.readthedocs.io/en/latest/messaging.html#kernel-shutdown>`_
161+
message on the control channel.
162+
163+
#. **Kernel Manager** waits for the kernel shutdown. After the timeout, and if
164+
it detects the kernel process is still running, the **Kernel Manager**
165+
terminates the kernel sending a ``SIGTERM`` operating system signal
166+
(or provisioner equivalent). If it finds the kernel process has
167+
not terminated, the **Kernel Manager** will follow up with a ``SIGKILL``
168+
operating system signal (or provisioner equivalent) to ensure the kernel's
169+
termination.
170+
171+
#. **Kernel Manager** cleans up the kernel resources. It removes kernel's interprocess
172+
communication ports, closes control socket, and releases Shell, IOPub, StdIn,
173+
Control, and Heartbeat ports.
174+
175+
#. When shutdown is finished, **Session Manager** deletes the Session data from
176+
the SQLite3 database and responses 204 status code to the Notebook client.
177+
178+
.. _delete_session: https://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/jupyter_server/master/jupyter_server/services/api/api.yaml#/sessions/delete_api_sessions__session_
179+
180+
.. |delete_session| replace:: the *DELETE /api/sessions/{session_id}*
88.4 KB
Loading
86.3 KB
Loading

0 commit comments

Comments
 (0)