克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

Periodic Go Report Card Slack

Nuclio - 用于实时事件和数据处理的 "serverless" 框架

访问 nuclio.io 获取更多产品信息和新闻,以及一个体验友好的 Web 版 Nuclio 文档.

翻译:

关于本文

概览

Nuclio 是一个高性能的 "serverless" 框架,专注于数据、I/O和计算密集型的工作负载. 它与流行的数据科学工具集成地很好,例如 JupyterKubeflow; 支持多种类型的数据和流式数据源; 并且支持在CPU和GPU上执行任务。Nuclio 项目于 2017 年启动,并处于持续不断的快速发展中;现如今,许多初创企业已将 Nuclio 应用于生产。

你可以将 Nuclio 以一个独立的 Docker 容器运行或者运行在一个已有的 Kubernetes 集群中; 在 Nuclio 文档中查看具体的部署指南。 也可以通过 Iguazio 数据科学平台 中的全权托管应用服务平台(云上或者本地)来使用 Nuclio,它提供免费的试用.

如果想通过编码的方式创建或者管理 Nuclio 函数(functions)- 例如, 使用 Jupyter Notebook - 请参阅 Nuclio Jupyter 项目, 它包含一个完整的 Python 包和软件开发工具包(SDK)用于通过 Jupyter Notebook 创建和部署 Nuclio 函数。 Nuclio 作为新开源项目 MLRun library,以及开源项目 Kubeflow Pipelines 中不可或缺的部分,分别提供数据科学自动化及追踪能力,以及构建和部署弹性可迁移机器学习(ML)工作流的能力。

Nuclio 的运行速度非常快: 单个函数实例每秒钟可以处理成十万的 HTTP 请求或者数据记录。这比其他的框架快了10-100倍。了解更多 Nuclio 的设计和运行原理,请查看 Nuclio 架构 文档, 阅读这篇文章 Nuclio vs. AWS Lambda, 或观看这个视频 Nuclio serverless and AI webinar.你也可以在 Nuclio 官方网站 获取到更多其他文章和指南的链接。

Nuclio 是很安全的: Nuclio 与 Kaniko 集成在运行时以一种安全且生产可用的方式构建 Docker 镜像。

更多疑问或支持, 点击加入 Nuclio Slack 工作空间.

为什么需要另一个 "serverless" 项目?

目前云厂商和开源 Serverless 解决方案都没有真正解决一个 Serverless 框架所必须的所有能力:

  • 以最小的 CPU/GPU 及 I/O 负载和最大的并行度进行实时处理
  • 原生的与各种数据源、触发器、处理模型和机器学习框架集成
  • 能够提供数据路径加速的有状态函数
  • 具有跨这种设备的可移植性包括,低功耗设备、笔记本电脑、边缘节点、本地集群以及公有云
  • 开源同时专注于企业级应用场景(包括日志记录、监控、安全性和可用性)

Nuclio 项目就是为满足这些需求而启动的。它的设计哲学就是作为一个可扩展的开源框架,基于模块化和分层的理念使得可以不断的添加各类触发器和运行时,希望越来越多的人能够参与到 Nuclio 项目,为 Nuclio 生态开发新的模块、工具和平台。

快速开始

All you need to run the dashboard is Docker:

探索尝试 Nuclio 的最简单方式是通过运行项目提供的图形用户界面(Nuclio 仪表盘。你可以很轻松的通过 Docker 将它运行起来:

docker run -p 8070:8070 \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v /tmp:/tmp \
  --name nuclio-dashboard \
  quay.io/nuclio/dashboard:stable-amd64

dashboard

在浏览器中访问 http://localhost:8070, 新建一个项目,并在其中添加一个函数。 当你在一些编排平台(例如,Kubernetes)之外运行时,仪表盘将会被直接运行在本地的 Docker 进程中。

假设你已经在 Docker 中运行了 Nuclio,作为一个简单的例子,新建一个项目,并部署预先已经存在的模板"dates (nodejs)"。执行 docker ps 命令, 你将能看到这个函数已经被部署到他自己的容器中。然后,你可以通过 curl 工具调用你的函数;(请示用 docker ps 指令或者 Nuclio 的仪表盘来检查端口号是否正确):

curl -X POST \
  -H "Content-Type: application/text" \
  -d '{"value":2,"unit":"hours"}' \
  http://localhost:37975

关于如何在 Kubernetes 集群、或者是 Nuclio 的 UI或和命令行工具(nuctl)中正确使用 Nuclio 的完整步骤,请参阅一下学习路径:

架构设计

“当发生这种事情时,请这样做”。Nuclio 试图抽象所有围绕事件已经发生的脚手架工具(例如,将消息记录写入 Kafka,发起一个 HTTP 请求,计时器到期等)并将此信息发送给一段代码逻辑来处理。为了实现这个目标,Nuclio 希望用户可以提供(至少)关于什么可以触发一个事件并且在发生此类事件时应该由哪一段代码逻辑来进行处理的详细信息。用户可以通过命令行工具(nuctl)、REST API或者一个可视化的 Web 端应用程序。

architecture

Nuclio 获取这些信息(通常称为函数处理程序 handler 和函数配置 configuration)并发送给构建器。构建器将会制作函数的容器镜像,其中包含用户提供的函数处理程序以及一个可以在接收到事件后执行该函数处理程序的软件工具(稍后有更详细的介绍)。然后,构建器将该该容器镜像发布到容器镜像注册表中。

一旦发布完成,这个函数的容器镜像就可以被部署了。部署器将从函数的配置中生成编排平台所需的特定配置文件。例如,如果是部署在 Kubernetes 集群中,部署器将会读取配置文件中的副本数量、自动扩缩容时间、函数需要的 GPU 数量等参数,并将它们转化为 Kubernetes 的资源配置(例如, Deployment, Service, Ingress 等)。

注意: 部署器不会直接创建 Kubernetes 的原生资源,而是会创建一个叫作 “NuclioFunction” 的自定义资源(CRD)。一个被称为”控制器“的 Nuclio 服务将会监听到 NuclioFunction 这个 CRD 的变化,并创建、修改或者删除可变更的 Kubernetes 原生资源((Deployment, Service等),这符合标准的 Kubernetes 控制器模式。

编排器将会从已经发布的容器镜像中启动容器并执行它们,并将函数的配置文件传递到容器中。这些容器的入口点(entrypoint)就是”处理器“,负责读取配置文件、监听事件触发器(例如,连接到 Kafka、监听 HTTP 端口等),当事件发生时,读取事件并调用用户的函数处理程序。处理器还负责很多其他的事情,包括处理指标、编码响应以及优雅地处理崩溃等。 The entrypoint of these containers is the "processor", responsible for reading the configuration, listening to event triggers (e.g. connecting to Kafka, listening for HTTP), reading events when they happen and calling the user's handler. The processor is responsible for many, many other things including handling metrics, marshaling responses, gracefully handling crashes, etc.

缩容至零

一旦构建并部署到 Kubernetes 这样的编排平台中,Nuclio 函数(即处理器)就可以处理事件,并根据性能指标、发送日志和指标等进行扩缩容——所有这些都不需要任何外部实体的帮助。部署完成后,就可以关闭 Nuclio 的仪表盘和控制器,Nuclio 函数依然可以完成的运行和扩缩容。

但是,缩容到零的能力,单单依靠函数自身是无法完成的。相反地——一旦缩容到零,当一个新的事件到达时,Nuclio 函数无法完成自己的扩容操作。为此, Nuclio 有一个扩缩器服务。它解决了将函数缩容到零,以及从零开始扩容的问题。

函数示例

如下示例函数实现了使用 EventContext 接口来处理输入和日志,并返回结构化的 HTTP 响应;(也可以使用简单字符串作为返回值)。

以 Go 语言为例:

package handler

import (
    "github.com/nuclio/nuclio-sdk-go"
)

func Handler(context *nuclio.Context, event nuclio.Event) (interface{}, error) {
    context.Logger.Info("Request received: %s", event.GetPath())

    return nuclio.Response{
        StatusCode:  200,
        ContentType: "application/text",
        Body: []byte("Response from handler"),
    }, nil
}

以 Python 语言为例:

def handler(context, event):
    response_body = f'Got {event.method} to {event.path} with "{event.body}"'

    # log with debug severity
    context.logger.debug('This is a debug level message')

    # just return a response instance
    return context.Response(body=response_body,
                            headers=None,
                            content_type='text/plain',
                            status_code=201)

更多的示例请访问 Nuclio 项目中的 hack/examples 目录。

推荐阅读

加入 活跃的 Nuclio Slack 空间,以获取支持或更多产品信息。

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright {yyyy} {name of copyright owner} Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

nuclio 展开 收起
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化