Compute modules(计算模块(Compute modules))¶
:::callout{theme="warning" title="Application access"}
To enable compute modules, contact your platform administrator to modify application access in Control Panel.
You can also view this documentation in the platform within the Compute Modules application for an efficient developer experience.
:::
Compute modules enable you to deploy interactive containers on the Palantir platform, allowing you to bring in your existing code base (regardless of language) and run this code inside the platform. Specifically, you can run serverless Docker images as compute modules in the Palantir platform and horizontally scale them up or down based on load in your frontend applications, such as Workshop and Slate.
Get started with compute modules¶
Start developing with our compute modules quick start guides:
- Call custom containers or models from Workshop modules or Slate applications: Write a container function that can be queried from Workshop or Slate. Review the documentation on building a compute module-backed function to get started using Palantir's TypeScript or Python SDKs.
- Sync data into Foundry using custom containers: Write a container that can be used to add data from custom sources into streams, datasets, or media sets. Review the documentation on building a compute module-backed pipeline to get started using Palantir's TypeScript or Python SDKs.
- [Advanced] Integrate with any language by writing a custom client: To integrate a container in a language without using the dedicated SDKs, you can write a custom client implementing the compute module client specification.
Use cases for compute modules¶
Compute modules give you new ways to interact with your own code or third-party code in the platform, enabling use cases such as:
- Container-backed functions: Author container functions that can be queried from applications such as Workshop or Slate.
- Container-based data integration: Connect to arbitrary data sources and ingest data into streams, datasets, or media sets.
- Host custom models: Host custom or open-source models and query them interactively from Foundry applications.
Why use compute modules?¶
There are several key advantages provided by compute modules:
- Integrate existing code bases: If you have business-critical code that would be risky or expensive to rewrite in Foundry, you can containerize the code into a Docker image and run it as a compute module.
- Use any programming language: Run any code that can be containerized, regardless of language. This means you are not limited by the languages Foundry supports natively.
- Dynamic and predictive horizontal scaling: If you expect to serve a varying number of requests, compute modules can ensure higher availability by scaling the number of available replicas up or down based on current and historic load.
- External and in-platform connections: Write custom logic leveraging Palantir products. For example, you can read and write data or media sets, or connect to external systems.
Note that compute modules may not be appropriate in all circumstances. We do not recommended using compute modules for the following:
- Dynamic vertical scaling: If you expect to have a single request vary dramatically in size, for instance from 1MB to 100GB, and want to support dynamic vertical scaling, compute modules may perform poorly "out of the box", as the amount of resources allocated is static and defined manually. It is possible to create differently provisioned tiers of the same compute module and multiplex between them, but that solution may be more complicated and cumbersome.
- Replacing existing features supported natively by Foundry: Compute modules can theoretically be used to build any desired feature. However, by virtue of being very generalized and powerful, this may come at the cost of having a more complicated solution.
Architecture¶
Each compute module consists of a number of replicas. The number of replicas changes as the request volume changes.
Each replica contains the same set of one or many isolated containers. One container serves as the entry point, and it must implement a client that forever polls for events to process. The other containers can contain anything.
By default, there are few guardrails for setting up a many-container compute module. One suggested method is to have them communicate using standard networking protocols; another suggestion is to use shared volume mounts. Containers in the same replica can communicate via those methods (and more), but containers cannot communicate across replicas, and you should not rely on any state they may accrue.
To get started, review the guide for building a compute module in the Palantir platform.
Next steps¶
Compute module security: Learn about compute module security and different execution modes.
Build a compute module-backed function: Create a compute module with functions to use natively across the platform.
Build a pipeline compute module: Create a pipeline compute module that takes input resources and produces output resources.
中文翻译¶
计算模块(Compute modules)¶
:::callout{theme="warning" title="应用访问权限"}
要启用计算模块,请联系您的平台管理员,在控制面板中修改应用访问权限。
您也可以在平台内的计算模块应用中查看本文档,以获得高效的开发者体验。
:::
计算模块使您能够在 Palantir 平台上部署交互式容器(interactive containers),从而将现有代码库(不限语言)引入并在平台内运行。具体而言,您可以将无服务器 Docker 镜像(serverless Docker images)作为计算模块在 Palantir 平台上运行,并根据前端应用(如 Workshop 和 Slate)的负载水平进行横向扩缩容。
计算模块入门¶
通过我们的计算模块快速入门指南开始开发:
- 从 Workshop 模块或 Slate 应用调用自定义容器或模型: 编写一个可从 Workshop 或 Slate 查询的容器函数(container function)。请查阅构建基于计算模块的函数文档,开始使用 Palantir 的 TypeScript 或 Python SDK。
- 使用自定义容器将数据同步到 Foundry: 编写一个容器,用于将自定义来源的数据添加到流(streams)、数据集(datasets)或媒体集(media sets)中。请查阅构建基于计算模块的管道文档,开始使用 Palantir 的 TypeScript 或 Python SDK。
- 【高级】通过编写自定义客户端集成任何语言: 要在不使用专用 SDK 的情况下集成某种语言的容器,您可以编写自定义客户端,实现计算模块客户端规范。
计算模块的使用场景¶
计算模块为您提供了在平台内与自有代码或第三方代码交互的新方式,支持以下使用场景:
- 基于容器的函数: 编写可从 Workshop 或 Slate 等应用查询的容器函数。
- 基于容器的数据集成: 连接到任意数据源,并将数据摄取到流、数据集或媒体集中。
- 托管自定义模型: 托管自定义或开源模型,并从 Foundry 应用进行交互式查询。
为什么使用计算模块?¶
计算模块具有以下几个关键优势:
- 集成现有代码库: 如果您拥有在 Foundry 中重写风险高或成本高的关键业务代码,可以将代码容器化为 Docker 镜像,并作为计算模块运行。
- 使用任何编程语言: 运行任何可容器化的代码,不受语言限制。这意味着您不受 Foundry 原生支持语言的限制。
- 动态且预测性的横向扩缩容: 如果您预计需要处理数量变化的请求,计算模块可以根据当前和历史负载动态调整可用副本(replicas)数量,从而确保更高的可用性。
- 外部与平台内连接: 编写利用 Palantir 产品的自定义逻辑。例如,您可以读写数据或媒体集,或连接到外部系统。
请注意,计算模块并非在所有情况下都适用。我们不建议在以下场景中使用计算模块:
- 动态垂直扩缩容: 如果您预计单个请求的大小会有剧烈变化(例如从 1MB 到 100GB),并希望支持动态垂直扩缩容,计算模块可能"开箱即用"表现不佳,因为分配的资源量是静态且手动定义的。虽然可以为同一计算模块创建不同配置的层级并在它们之间进行多路复用,但这种解决方案可能更加复杂和繁琐。
- 替换 Foundry 原生支持的现有功能: 理论上,计算模块可用于构建任何所需功能。然而,由于其高度通用和强大,这可能会以解决方案更加复杂为代价。
架构¶
每个计算模块由若干副本(replicas)组成。副本数量会随请求量的变化而变化。
每个副本包含一组相同的一个或多个隔离容器(isolated containers)。其中一个容器作为入口点(entry point),它必须实现一个客户端,该客户端持续轮询待处理的事件。其他容器可以包含任何内容。
默认情况下,设置多容器计算模块的防护措施较少。一种建议的方法是让它们使用标准网络协议进行通信;另一种建议是使用共享卷挂载(shared volume mounts)。同一副本中的容器可以通过这些方法(以及其他方法)进行通信,但容器不能跨副本通信,并且您不应依赖它们可能积累的任何状态。
要开始使用,请查阅在 Palantir 平台中构建计算模块的指南。
后续步骤¶
计算模块安全性: 了解计算模块安全性和不同执行模式。
构建基于计算模块的函数: 创建带有函数的计算模块,以便在平台中原生使用。
构建管道计算模块: 创建管道计算模块,用于接收输入资源并生成输出资源。