From 90b3d8ae3c15080887180ee21b2e13c7f402adec Mon Sep 17 00:00:00 2001 From: Shadaj Laddad Date: Fri, 24 Jan 2025 13:29:10 -0800 Subject: [PATCH] docs(hydro_lang): add docs for processes (#1671) --- docs/docs/hydro/locations/processes.md | 37 ++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/docs/docs/hydro/locations/processes.md b/docs/docs/hydro/locations/processes.md index 44359005905..99e7b3883ca 100644 --- a/docs/docs/hydro/locations/processes.md +++ b/docs/docs/hydro/locations/processes.md @@ -3,8 +3,41 @@ sidebar_position: 0 --- # Processes -:::caution +The simplest type of location in Hydro is a **process**. A process represents a **single thread** running a piece of a Hydro program (with no internal concurrency). When creating a process, you can pass in a type parameter that will be used as a marker to distinguish that process from others (and will also be used to mark logs originating at that process). For example, you can create a process with a marker of `Leader` to represent a leader in a distributed system: -The Hydro documentation is currently under active development! This page is a placeholder for future content. +```rust,no_run +# use hydro_lang::*; +struct Leader {} + +let flow = FlowBuilder::new(); +let leader: Process = flow.process::(); +``` + +:::note + +Currently, each Hydro process is deployed as a **separate** operating system process. In the future, we plan to support running multiple Hydro processes in a single operating system process for more efficient resource sharing. ::: + +Once we have a process, we can create live collections on that process (see [Live Collections](../live-collections/index.md) for more details). For example, we can create a stream of integers on the leader process: + +```rust,no_run +# use hydro_lang::*; +# struct Leader {} +# let flow = FlowBuilder::new(); +# let leader: Process = flow.process::(); +let numbers = leader.source_iter(q!(vec![1, 2, 3, 4])); +``` + +## Networking +Because a process represents a single machine, it is straightforward to send data to and from a process. For example, we can send a stream of integers from the leader process to another process using the `send_bincode` method (which uses [bincode](https://docs.rs/bincode/latest/bincode/) as a serialization format). This automatically sets up network senders and receivers on the two processes. + +```rust,no_run +# use hydro_lang::*; +# struct Leader {} +# let flow = FlowBuilder::new(); +# let leader: Process = flow.process::(); +let numbers = leader.source_iter(q!(vec![1, 2, 3, 4])); +let process2: Process<()> = flow.process::<()>(); +let on_p2: Stream<_, Process<()>, _> = numbers.send_bincode(&process2); +```