在Jupyter Notebook服务器中使用远程内核

本文介绍了如何在Jupyter Notebook中使用远程内核,特别是在处理云中Apache Spark集群上的大型数据集时。通过Jupyter Kernel Gateway,可以实现Notebook与远程内核的通信。文章提供了一个名为nb2kg的服务器扩展示例,用于修改Notebook服务器以使用内核网关托管的远程内核,并提供了在conda环境中设置和运行的步骤。
摘要由CSDN通过智能技术生成

Jupyter Notebook uses kernels to execute code interactively. The Jupyter Notebook server runs kernels as separate processes on the same host by default. However, there are scenarios where it would be necessary or beneficial to have the Notebook server use kernels that run remotely.

Jupyter Notebook使用内核以交互方式执行代码。 默认情况下,Jupyter Notebook服务器在同一主机上将内核作为单独的进程运行。 但是,在某些情况下,让Notebook服务器使用远程运行的内核将是必要或有益的。

A good example is when you want to use notebooks to explore and analyze large data sets on an Apache Spark cluster that runs in the cloud. In this case, the notebook kernel becomes the Spark driver program, and the Spark architecture dictates that drivers run as close as possible to the cluster, preferably on the same local area network [1].

一个很好的例子是,当您想使用笔记本浏览和分析在云中运行的Apache Spark集群上的大数据集时。 在这种情况下,笔记本内核成为Spark驱动程序,Spark架构要求驱动程序尽可能靠近群集运行,最好在同一局域网上运行[1]。

To run Jupyter Notebook with remote kernels, first you need a kernel server that exposes an API to manage and communicate with kernels. Second, you need to modify the default behavior of the Notebook server, which is to spawn kernels as local processes on the same host.

要使用远程内核运行Jupyter Notebook,首先您需要一个内核服务器,该服务器公开API以管理内核并与之通信。 其次,您需要修改Notebook服务器的默认行为,即在同一主机上将内核作为本地进程生成。

The Jupyter Kernel Gateway satisifies the first need. It allows clients to provision and communicate with kernels using HTTP and web socket protocols.

Jupyter内核网关可以满足第一个需求。 它允许客户端使用HTTP和Web套接字协议配置内核并与内核通信。

Jupyter Notebook 4.2 introduced server extensions to make it possible to extend (or modify) the Notebook server behavior. I leveraged this new capabilitiy and created a demo server extension to modify the Notebook server to use remote kernels hosted by the Kernel Gateway. For lack of a better name, I called it nb2kg.

Jupyter Notebook 4.2引入了服务器扩展 ,从而可以扩展(或修改)Notebook服务器行为。 我利用了这一新功能,并创建了一个演示服务器扩展,以修改Notebook服务器以使用由内核网关托管的远程内核。 由于缺少更好的名称,我将其称为nb2kg

We can visualize the Jupyter Notebook components in the diagram below, which was taken from the Jupyter documentation.

我们可以在下图中可视化Jupyter Notebook组件,该组件取自Jupyter文档

The key points are:

关键点是:

  • The Notebook web UI (browser) and the Notebook server communicate using HTTP and web socket protocols.
  • By default, the Notebook server spawns kernels on the same host as the server.
  • The server and kernel processes communicate using ZeroMQ.
  • Notebook Web UI(浏览器)和Notebook服务器使用HTTP和Web套接字协议进行通信。
  • 默认情况下,Notebook服务器在与服务器相同的主机上生成内核。
  • 服务器和内核进程使用ZeroMQ进行通信。

The nb2kg extension essentially proxies all kernel requests and web socket communication from the notebook web UI to a Kernel Gateway. Using the extension, the browser to server to kernel communication looks like this:

nb2kg扩展实质上代理了从笔记本Web UI到内核网关的所有内核请求和Web套接字通信。 使用扩展名,浏览器到服务器到内核的通信如下所示:

试试吧 (Try It)

This section provides an example of running a Jupyter Kernel Gateway and the Jupyter Notebook server with the nb2kg extension in a conda environment. (The nb2kg Kernel Gateway demo also includes Dockerfiles and a docker-compose recipe if you care to try it using Docker).

本节提供了运行一个内核Jupyter网关并将其与以所述nb2kg扩展Jupyter笔记本服务器的示例康达环境。 (

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值