Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 05afa54

Browse files
committed
edits
1 parent fea8632 commit 05afa54

File tree

3 files changed

+141
-126
lines changed

3 files changed

+141
-126
lines changed

src/nav.config.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ const buildingBlockLinks = [
7070
icon: ServerIcon,
7171
},
7272
{
73-
title: 'Jobs',
74-
href: '/jobs',
73+
title: 'AI & Batch',
74+
href: '/batch',
7575
icon: CpuChipIcon,
7676
},
7777
{
@@ -696,18 +696,18 @@ const fullNav: FullNav = {
696696
links: buildingBlockLinks.filter((link) => link.href !== '/http'),
697697
},
698698
],
699-
jobs: [
699+
batch: [
700700
{
701701
links: [
702702
{
703703
title: 'Overview',
704-
href: '/jobs',
704+
href: '/batch',
705705
},
706706
],
707707
},
708708
{
709709
title: 'More Building Blocks',
710-
links: buildingBlockLinks.filter((link) => link.href !== '/jobs'),
710+
links: buildingBlockLinks.filter((link) => link.href !== '/batch'),
711711
},
712712
],
713713
keyvalue: [

src/pages/batch.mdx

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
export const description = 'Running AI & Batch workloads with Nitric'
2+
3+
# Batch
4+
5+
Nitric provides functionality that allows you to run large-scale jobs in parallel across multiple virtual machines or compute resources. Unlike Nitric Services, which respond to real-time events (APIs, Schedules, etc.), Batch is intended to efficiently handle tasks that can be processed in batches, which means they don't need to run in real time but can be executed asynchronously. Batches can include tasks that require a lot of computing power, or access to GPU resources, such as machine learning model training, image processing, video transcoding, data processing, and data analysis.
6+
7+
Nitric Batch is designed to be used in conjunction with Nitric Services, allowing you to run long-running, computationally intensive tasks in parallel with your real-time services. This allows you to build complex applications that can handle both real-time and batch processing workloads.
8+
9+
Batches are deployed to cloud services such as [AWS Batch](https://aws.amazon.com/batch/), [Azure Batch](https://azure.microsoft.com/en-au/products/batch), and [Google Cloud Batch](https://cloud.google.com/batch/docs). Nitric abstracts the underlying cloud provider, allowing you to run your batch jobs on any of the supported cloud providers without having to worry about the specifics of each provider.
10+
11+
## Definitions
12+
13+
### Batch
14+
15+
A Batch is similar to a Nitric Service, but it's intended for work with a definitive start and a finish. Where a service is designed to be reactive, a batch is designed to be proactive and run a series of jobs in parallel.
16+
17+
### Job Definitions
18+
19+
A Job Definition describes a type of work to be done by a Nitric `Batch`
20+
21+
### Job
22+
23+
A Job is an instance of a Job Definition that is running within a `Batch`, Jobs can be started from other Nitric Services or Batches.
24+
25+
## Limitations of Batches
26+
27+
Jobs are designed to be long running HPC workloads and can take some time to spin up. They are not designed with reactivity in mind and are not suitable for responding to events from cloud resources.
28+
29+
Jobs are unable to run the following:
30+
31+
- Topic Subscriptions
32+
- Bucket Notifications
33+
- API & HTTP resources
34+
- Websocket message handlers
35+
36+
Jobs can be used to read and write to/from all nitric resources, for example they can publish new messages to a Topic, read and write to a Bucket, or read and write to a Database. They just can't respond to real-time events from these resources.
37+
38+
## Defining Batches
39+
40+
Batches are defined similarly to services in a project's `nitric.yaml` file. For example:
41+
42+
```yaml
43+
batches:
44+
- match: ./batches/*.ts
45+
start: yarn dev:batches $BATCH_PATH
46+
```
47+
48+
<Note>Batches can contain any number of Job Definitions.</Note>
49+
50+
## Defining a Job
51+
52+
Within a Batch we create Job Definitions, by creating a new Job with a unique name and defining a handler function that will be executed when the job is submitted.
53+
54+
<CodeGroup>
55+
56+
```typescript
57+
import { job, JobContext } from '@nitric/sdk'
58+
59+
const myJob = job('analyse')
60+
61+
// Use `handler` to register the callback function that will run when a job is submitted
62+
myJob.handler(
63+
async (ctx: JobContext) => {
64+
// Do some work
65+
},
66+
{ cpus: 1, memory: 1024, gpus: 0 }
67+
)
68+
```
69+
70+
```python
71+
from nitric.resources import job
72+
from nitric.application import Nitric
73+
from nitric.context import JobContext
74+
75+
analyze = job("analyze")
76+
77+
# Create the callback function that will run when a job is submitted
78+
@analyze(cpus=1, memory=1024, gpus=0)
79+
async def generate_image(ctx: None):
80+
# Do some work
81+
82+
83+
Nitric.run()
84+
```
85+
86+
</CodeGroup>
87+
88+
## Submitting Jobs for Execution
89+
90+
Jobs may be submitted from Nitric `services` or other `batches` using the `submit` method on the job reference. When submitting a job you can provide a payload that will be passed to the job handler function.
91+
92+
<Note>
93+
When submitting a job, you can optionally override the default resources
94+
allocated to the job.
95+
</Note>
96+
97+
<CodeGroup>
98+
99+
```javascript
100+
import * as nitric from '@nitric/sdk'
101+
102+
const api = nitric.api('public')
103+
const analyze = nitric.job('analyze').allow('submit')
104+
105+
api.post('/submit-job', async (ctx) => {
106+
await analyze.submit(
107+
{
108+
someKey: 'someValue',
109+
},
110+
// optional job resource overrides
111+
{ cpus: 1, memory: 1024, gpus: 0 }
112+
)
113+
})
114+
```
115+
116+
```python
117+
from nitric.resources import api, job
118+
from nitric.application import Nitric
119+
120+
analyze = job("analyze").allow("submit")
121+
public_api = api("public")
122+
123+
@public_api.post("/submit-job")
124+
async def submit_job(ctx):
125+
await analyze.submit(
126+
{
127+
"someKey": "someValue"
128+
},
129+
# optional job resource overrides
130+
{ cpus: 1, memory: 1024, gpus: 0 }
131+
)
132+
133+
Nitric.run()
134+
```
135+
136+
</CodeGroup>

src/pages/jobs.mdx

Lines changed: 0 additions & 121 deletions
This file was deleted.

0 commit comments

Comments
 (0)