databricks-serverless
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDeploying Databricks jobs and pipelines on serverless
在 Serverless 上部署 Databricks 作业和管道
FIRST: Use the parent skill for CLI basics, authentication and profile selection.
databricks-coreThis skill decides compute. Where another skill or example (for example ) shows
cluster configuration, follow this skill instead.
databricks-jobsServerless is the default compute for every job, pipeline and bundle you create. If the user
explicitly asks for a cluster, do what they ask and mention the serverless option in one line.
When editing an existing job, keep its compute unless the user asks to change it; tasks you add
follow this skill.
首先:使用父级 skill 了解 CLI 基础、身份验证和 profile 选择。
databricks-core此 skill 负责决定计算资源。当其他 skill 或示例(例如 )显示集群配置时,应遵循此 skill。
databricks-jobsServerless 是你创建的每个作业、管道和 bundle 的默认计算资源。如果用户明确要求使用集群,则照做,并在一行内提及 Serverless 选项。编辑现有作业时,保留其计算资源,除非用户要求更改;新增任务遵循此 skill。
1. Serverless or classic
1. Serverless 还是 classic
Use classic compute only for:
- R code, or Scala in notebook cells (): serverless notebooks run Python and SQL only;
%scala - custom Docker images;
- OS packages () or native libraries with no pip equivalent;
apt-get - custom Spark data source JARs;
- a stated hard requirement for an instance type or Databricks Runtime version;
- an explicit user request;
- existing code over the budget in section 5;
- a workspace without serverless: if creating or running the job fails because serverless is not available there, put the whole job on classic and say so.
Then give only the blocked task a cluster (one small entry with the latest LTS
runtime and ), keep every other task serverless, and
state the blocker in one line. For a blocked pipeline, give the pipeline a block instead
of .
job_clustersautoscale: {min_workers: 1, max_workers: 4}clustersserverless: trueNot reasons for classic: Scala or Java in a JAR task (JAR tasks run on serverless), GPUs (serverless
GPU), large data, long runtimes, Kafka, cost (serverless STANDARD is on par with or cheaper than
on-demand classic in most cases), or habit.
仅在以下情况下使用 classic 计算资源:
- R 代码,或 notebook 单元格中的 Scala():Serverless notebook 仅运行 Python 和 SQL;
%scala - 自定义 Docker 镜像;
- 操作系统包()或没有 pip 等价物的 native library;
apt-get - 自定义 Spark data source JAR;
- 明确要求使用特定 instance type 或 Databricks Runtime 版本;
- 用户明确要求使用 classic;
- 现有代码超出第 5 节中的预算;
- 工作区不支持 Serverless:如果创建或运行作业时因该工作区无法使用 Serverless 而失败,则将整个作业放在 classic 上,并明确说明。
然后,只为受阻任务配置集群(一个小型 条目,使用最新 LTS runtime 和 ),让其他所有任务继续使用 Serverless,并在一行内说明阻碍原因。对于受阻管道,配置 块,而不是 。
job_clustersautoscale: {min_workers: 1, max_workers: 4}clustersserverless: true以下情况不是使用 classic 的理由:JAR 任务中的 Scala 或 Java(JAR 任务可运行在 Serverless 上)、GPU(可使用 Serverless GPU)、大数据量、长时间运行、Kafka、成本(在大多数情况下,Serverless STANDARD 的成本与按需 classic 相当或更低),以及习惯性选择 classic。
2. Put every task on serverless
2. 将所有任务放在 Serverless 上
- New jobs: leave out ,
new_cluster,job_clusters,job_cluster_key,existing_cluster_id,instance_pool_id,node_type_id,num_workers,autoscale. A task without a cluster runs on serverless. In an existing job, keep the cluster settings it has.spark_version - Notebook tasks need nothing else. Python script, wheel and JAR tasks take their libraries
from a job-level environment. Use the latest environment version the workspace offers, as a
quoted string:
yaml
environments: - environment_key: default spec: environment_version: "4" # example; use the latest dependencies: ["requests==2.32.3"] # pin versions; JARs go in java_dependencies tasks: - task_key: main spark_python_task: {python_file: /Workspace/.../main.py} environment_key: default - SQL tasks: a serverless SQL warehouse. Pipelines: , no
serverless: trueblock.clusters - Streaming: , the trigger serverless supports (no
.trigger(availableNow=True)orprocessingTimetriggers). For always-on processing, run that stream in a continuous job (continuous), which starts the next run as soon as one finishes, or use a continuous pipeline.continuous: {pause_status: UNPAUSED} - Tag every job you create for resource tracking, as other Databricks skills do: job-level
. Keep tags the user already has.
tags: {"aidevkit_project": "ai-dev-kit"}
- 新作业: 省略 、
new_cluster、job_clusters、job_cluster_key、existing_cluster_id、instance_pool_id、node_type_id、num_workers和autoscale。未配置集群的任务将在 Serverless 上运行。对于现有作业,保留其已有的集群设置。spark_version - Notebook 任务无需其他配置。Python 脚本、wheel 和 JAR 任务从作业级 environment 获取依赖库。使用 workspace 提供的最新 environment 版本,并将其写成带引号的字符串:
yaml
environments: - environment_key: default spec: environment_version: "4" # example; use the latest dependencies: ["requests==2.32.3"] # pin versions; JARs go in java_dependencies tasks: - task_key: main spark_python_task: {python_file: /Workspace/.../main.py} environment_key: default - SQL 任务: 使用 Serverless SQL warehouse。管道: 使用 ,不要配置
serverless: true块。clusters - 流处理: 使用 ,这是 Serverless 支持的触发方式(不支持
.trigger(availableNow=True)或processingTimetrigger)。如需持续运行,请使用 continuous job 运行该流(continuous),这样上一轮结束后会立即启动下一轮;也可以使用 continuous pipeline。continuous: {pause_status: UNPAUSED} - 按照其他 Databricks skill 的做法,为创建的每个作业添加标签以进行资源跟踪:作业级 。保留用户已有的标签。
tags: {"aidevkit_project": "ai-dev-kit"}
3. Choose the performance mode
3. 选择性能模式
Set the job-level :
performance_target- when nothing is time-critical and cost matters more than speed: scheduled batch and ETL, nightly or weekly runs, or any job where the user states no latency need. Runs start within minutes instead of seconds and cost less. This is the default choice.
STANDARD - only when the user names an SLA or a deadline that is tight relative to the runtime, a person waits on the result, or the job runs every 30 minutes or more often.
PERFORMANCE_OPTIMIZED
performance_targetperformance_targetPipelines have no of their own. To schedule a pipeline, trigger it from a job
with a and set the mode on that job; the job's mode applies to the pipeline update.
A continuous pipeline runs in STANDARD only when a continuous job runs it.
performance_targetpipeline_task设置作业级 :
performance_target- 当任务没有时间敏感性且成本比速度更重要时,使用 :包括定时批处理和 ETL、每夜或每周运行,以及用户明确表示没有延迟要求的任何作业。作业会在数分钟内启动,而不是数秒,并且成本更低。这是默认选择。
STANDARD - 仅当用户指定了相对于运行时间较为紧迫的 SLA 或截止时间、有人正在等待结果,或作业每 30 分钟或更频繁地运行时,才使用 。
PERFORMANCE_OPTIMIZED
performance_targetServerless GPU 任务会忽略 。
performance_target管道本身没有 。要调度管道,请使用包含 的作业触发管道,并在该作业上设置模式;作业的模式将应用于管道更新。只有当 continuous job 运行 continuous pipeline 时,管道才以 STANDARD 模式运行。
performance_targetpipeline_task4. Code you write runs on serverless from the start
4. 从一开始,你编写的代码就在 Serverless 上运行
Serverless reads Unity Catalog tables, paths, cloud paths behind a Unity Catalog
external location, and the sample data under . It cannot read DBFS
mounts () or other DBFS root paths; only those count as a DBFS blocker.
/Volumes/...dbfs:/databricks-datasets/dbfs:/mnt/...DataFrame and SQL APIs only (no RDDs, , ); Unity Catalog three-part table
names; paths instead of DBFS mounts (); streaming
triggers; no or ; no for executor, driver or memory
settings; pinned dependencies in the environment, never init scripts.
sc.*spark.sparkContext/Volumes/...dbfs:/mnt/...availableNow.cache().persist()spark.conf.setServerless 可以读取 Unity Catalog 表、 路径、Unity Catalog external location 后面的云路径,以及 下的示例数据。它无法读取 DBFS mount()或其他 DBFS root path;只有这些情况才构成 DBFS blocker。
/Volumes/...dbfs:/databricks-datasets/dbfs:/mnt/...仅使用 DataFrame 和 SQL API(不得使用 RDD、、);使用 Unity Catalog 三段式表名;使用 路径而不是 DBFS mount();使用 streaming trigger;不得使用 或 ;不得使用 设置 executor、driver 或内存;在 environment 中固定依赖版本,绝不使用 init script。
sc.*spark.sparkContext/Volumes/...dbfs:/mnt/...availableNow.cache().persist()spark.conf.set5. Existing code: a quick check, not a migration
5. 现有代码:快速检查,而非迁移
The user is waiting for the deployment. Spend one short pass, then deploy.
-
Scan only the files the job runs (a text search such asor
grep; do not read the whole repo) for:rg,sc.,sparkContext,.rdd,parallelize,mapPartitions,reduceByKey,groupByKey,dbfs:/,/dbfs/,dbutils.fs.mount,.cache(,.persist(,spark.conf.set,processingTime,continuous=,writeStream,hive_metastore.,GLOBAL TEMP,hivevar,init_scripts,apt-get, and other languages:dockeror%scalaas the whole magic (%r, not# MAGIC %r),%runfiles and R notebooks,.randSparkR. R and Scala cells go to classic (section 1).sparklyr -
Minor blockers: fix them and deploy on serverless if every fix is mechanical and local, keeps the logic, needs no new infrastructure, and there are about 5 small edits or fewer in total:
- delete ,
.cache(),.persist(),.unpersist(), executor/driver/AQEsetLogLevellinesspark.conf.set - move s or
pip installinto the environment, pinnedrequirements.txt - add to a stream that sets no trigger, in a job that runs on a schedule anyway (a stream with a
.trigger(availableNow=True)orprocessingTimetrigger is a step 4 blocker)continuous - replace a path with a
dbfs:/mnt/...path only when that volume's storage location is the mount's source, so the job reads the same data; a volume with a similar name is not enough. Otherwise the mount is a step 4 blocker./Volumes/... - becomes
CREATE GLOBAL TEMP VIEW, and itsCREATE TEMP VIEWreads becomeglobal_temp.<view>, when the same file creates and reads the view (serverless has no global temp views); a global temp view that another task or notebook reads is a step 4 blocker<view> - add the catalog to a two-part table name only when you know which Unity Catalog catalog holds the
table (for example the job's default catalog); a table in is a step 4 blocker
hive_metastore
List every edit you made in your reply. - delete
-
RDD or SparkContext code: translate it to DataFrames and deploy on serverless only if all of these hold:
- it is one file of about 200 lines or fewer;
- the change is a pure API translation: the same logic, expressed with DataFrame or SQL;
- every input path, table, output table and parameter stays exactly as it was. Never swap in another dataset, even a sample one;
- every input is already readable on serverless (section 4: a Unity Catalog table, an existing
path, a cloud path behind an external location, or
/Volumes/...), so nothing new has to be set up.dbfs:/databricks-datasets/
Save the original next to it asand point the job at the translated file. Tell the user that the translation has not been run yet and suggest one test run that compares the output with the classic version.<name>.classic.py -
Anything bigger: do not rewrite. Put that task on classic now (section 1), keep the other tasks serverless, and end with: "Kept <task> on classic because <blocker>. To move it to serverless, use the databricks-serverless-migration skill." Bigger means: RDD code that fails any condition in step 3 (for example it reads a DBFS mount), mounts with no volume on the same storage, Hive Metastore to Unity Catalog, recompiling a JAR, networking changes, changing what a stream does (an always-onor
processingTimestream), or more than about 5 edits besides a step 3 translation.continuous
Do not stop to ask whether to migrate. Deploy, then report what you did.
用户正在等待部署。花一次简短检查的时间,然后完成部署。
-
仅扫描作业实际运行的文件(使用或
grep等文本搜索;不要读取整个 repo),查找:rg、sc.、sparkContext、.rdd、parallelize、mapPartitions、reduceByKey、groupByKey、dbfs:/、/dbfs/、dbutils.fs.mount、.cache(、.persist(、spark.conf.set、processingTime、continuous=、writeStream、hive_metastore.、GLOBAL TEMP、hivevar、init_scripts、apt-get,以及其他语言的使用方式:将docker或%scala作为完整的 magic(%r,而不是# MAGIC %r)、%run文件和 R notebook、.r和SparkR。R 和 Scala 单元格应转到 classic(第 1 节)。sparklyr -
轻微阻碍:如果每项修复都只是机械式且局部的修改、不改变逻辑、不需要新基础设施,并且总共约不超过 5 处小改动,则修复后部署到 Serverless:
- 删除 、
.cache()、.persist()、.unpersist(),以及 executor、driver 和 AQE 的setLogLevel配置行spark.conf.set - 将 命令或
pip install移入 environment,并固定依赖版本requirements.txt - 对于按计划运行的作业,如果某个流未设置 trigger,则添加 (使用
.trigger(availableNow=True)或processingTimetrigger 的流属于第 4 步的 blocker)continuous - 仅当某个 volume 的存储位置与 mount 的源存储位置相同时,才将 路径替换为
dbfs:/mnt/...路径,以确保作业读取相同的数据;仅名称相似的 volume 不足以满足条件。否则,该 mount 属于第 4 步的 blocker/Volumes/... - 当同一个文件负责创建和读取 view 时,将 改为
CREATE GLOBAL TEMP VIEW,并将CREATE TEMP VIEW读取改为global_temp.<view>(Serverless 不支持 global temp view);如果其他任务或 notebook 会读取该 global temp view,则它属于第 4 步的 blocker<view> - 仅当明确知道哪个 Unity Catalog catalog 包含目标表时,才为两段式表名添加 catalog;例如,可以使用作业的默认 catalog。位于 中的表属于第 4 步的 blocker
hive_metastore
在回复中列出所做的每项修改。 - 删除
-
RDD 或 SparkContext 代码:仅在满足以下所有条件时,才将其转换为 DataFrame 并部署到 Serverless:
- 只有一个文件,长度约不超过 200 行;
- 转换仅涉及 API,将相同逻辑改写为 DataFrame 或 SQL;
- 每个输入路径、表、输出表和参数都保持原样。绝不替换成其他数据集,即使使用示例数据集也不允许;
- 每个输入都已可在 Serverless 上读取(第 4 节:Unity Catalog 表、现有的 路径、external location 后面的云路径,或
/Volumes/...),因此不需要设置任何新基础设施。dbfs:/databricks-datasets/
将原文件保存在转换后的文件旁边,并命名为,然后让作业指向转换后的文件。 告知用户该转换尚未运行,并建议进行一次测试运行,将输出与 classic 版本进行比较。<name>.classic.py -
任何规模更大的改动:不要重写。 立即将该任务放在 classic 上(第 1 节),让其他任务继续使用 Serverless,并以这句话结束:“已将 <task> 保留在 classic 上,因为 <blocker>。要将其迁移到 Serverless,请使用 databricks-serverless-migration skill。” 较大改动包括:不符合第 3 步任一条件的 RDD 代码(例如读取 DBFS mount)、同一存储上没有对应 volume 的 mount、从 Hive Metastore 迁移到 Unity Catalog、重新编译 JAR、网络变更、更改流的处理方式(始终运行的或
processingTime流),或者除第 3 步转换外还有约 5 处以上的改动。continuous
不要停下来询问是否迁移。完成部署,然后报告所做的工作。
Common Issues
常见问题
| Issue | Solution |
|---|---|
| Move libraries into |
| Serverless job starts too slowly | |
| RDD/SparkContext code: section 5, step 3 or 4 |
| DBFS mounts do not work on serverless: use a volume on the same storage (section 5, step 2), otherwise step 4 |
| Serverless is not enabled or not available in the workspace | Put the job on classic and tell the user (section 1) |
A sibling skill's example uses | Leave the cluster block out; this skill decides compute. Existing jobs keep their compute |
| 问题 | 解决方案 |
|---|---|
| 将依赖库移入 |
| Serverless 作业启动过慢 | 使用 |
| RDD/SparkContext 代码:第 5 节第 3 步或第 4 步 |
| DBFS mount 不支持 Serverless:使用同一存储上的 volume(第 5 节第 2 步),否则按第 4 步处理 |
| 工作区未启用或无法使用 Serverless | 将作业放在 classic 上并告知用户(第 1 节) |
兄弟 skill 的示例为新作业使用 | 省略集群块;由本 skill 决定计算资源。现有作业保留其计算资源 |
Related Skills
相关 Skill
- databricks-core - CLI basics, authentication, profiles
- databricks-jobs - job structure, task types, triggers, notifications
- databricks-pipelines - Lakeflow Spark Declarative Pipelines
- databricks-serverless-migration - migrating existing classic workloads to serverless
- databricks-core - CLI 基础、身份验证、profile
- databricks-jobs - 作业结构、任务类型、trigger、通知
- databricks-pipelines - Lakeflow Spark Declarative Pipelines
- databricks-serverless-migration - 将现有 classic 工作负载迁移到 Serverless