Skip to content

Commit 8d2e183

Browse files
committed
Update docs
Signed-off-by: Andrew Carbonetto <[email protected]>
1 parent 6a41dfc commit 8d2e183

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

docs/design-raw-ffi.md

+21-22
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,22 @@
22

33
## Summary
44

5-
The Babushka client enables Redis users connect to Redis using a variety of languages and supported commands. The client
6-
uses a performant core to establish and manage connections, and a thin wrapper layer written in various languages, to
7-
communicate
5+
The Babushka client allows Redis users to connect to Redis using a variety of commands through a thin-client optimized for
6+
various languages. The client uses a performant core to establish and manage connections and communicate with Redis. The thin-client
7+
wrapper talks to the core using an FFI (foreign function interface) to Rust.
88

9-
The following document discusses two primary communication protocol architectures for wrapping the babushka clients, and
10-
how Java-Babushka and Go-Babushka use each of those protocols differently by taking advantage of language-specific attributes.
11-
12-
### References
13-
14-
* Babushka - communication protocol architecture: describes high-level approaches to communication protocols.
9+
The following document discusses two primary communication protocol architectures for wrapping the Babushka clients. Specifically,
10+
it details how Java-Babushka and Go-Babushka each use a different protocol and describes the advantages of each language-specific approach.
1511

1612
# Unix Domain Socket Manager Connector
1713

1814
## High-Level Design
1915

2016
**Summary**: The Babushka "UDS" solution uses a socket listener to manage rust-to-wrapper worker threads, and unix domain sockets
21-
to deliver package between the wrapper and redis-client threads. This works well because we allow the unix sockets to pass messages
22-
through the OS and is very performant. This results in simple/fast communication. But the concern is that the unix sockets can
23-
become a bottleneck for data-intensive communication; ie read/write buffer operations.
17+
to deliver command requests between the wrapper and redis-client threads. This works well because we allow the unix sockets to pass messages and manage threads
18+
through the OS, and unix sockets are very performant. This results in simple/fast communication. The risk to avoid is that
19+
unix sockets can become a bottleneck for data-intensive commands, and the library can spend too much time waiting on I/O
20+
blocking operations.
2421

2522
```mermaid
2623
stateDiagram-v2
@@ -40,7 +37,7 @@ stateDiagram-v2
4037

4138
## Decision to use UDS Sockets for a Java-Babushka Wrapper
4239

43-
The decision to use Unix Domain Sockets (UDS) to manage the Java-wrapper to Babushka Redis-client communication was two-fold, as opposed to a raw-FFI solution:
40+
The decision to use Unix Domain Sockets (UDS) to manage the Java-wrapper to Babushka Redis-client communication was two-fold, vs a raw-FFI solution:
4441
1. Java contains an efficient socket protocol library (netty.io) that provides a highly configurable environment to manage sockets.
4542
2. Java objects serialization/de-serialization is an expensive operation, and a performing multiple io operations between raw-ffi calls would be inefficient.
4643

@@ -50,7 +47,7 @@ The decision to use Unix Domain Sockets (UDS) to manage the Java-wrapper to Babu
5047
|----------------------------------------------|---------------------------------------------------------|-----------------------------|----------------------------------------------------|
5148
| Unix Domain Sockets (jni/netty) | JNI to submit commands; netty.io for message passing | netty.io standard lib; | complex configuration; limited by socket interface |
5249
| Raw-FFI (JNA, uniffi-rs, j4rs, interoptopus) | JNA to submit commands; protobuf for message processing | reusable in other languages | Slow performance and uses JNI under the hood; |
53-
| Panama/jextract | Performance similar to a raw-ffi using JNI | | lacks early Java support (JDK 18+); prototype |
50+
| Panama/jextract | Performance similar to a raw-ffi using JNI | modern | lacks early Java support (JDK 18+); prototype |
5451

5552
### Sequence Diagram
5653

@@ -119,10 +116,10 @@ Wrapper ->> SocketListener: shutdown
119116

120117
## Wrapper-to-Core Connector with raw-FFI calls
121118

122-
**Summary**: Foreign Function Calls are simple to implement inter-language calls. The setup between Golang and the Rust-core
119+
**Summary**: Foreign Function Interface (FFI) calls are simple to implement, cross-language calls. The setup between Golang and the Rust-core
123120
is fairly simple using the well-supported CGO library. While sending language calls is easy, setting it up in an async manner
124-
is more complex because of the requirement to handle async callbacks. Golang as a simple, light-weight solution, using goroutines
125-
and channels, to pass callbacks and execution between langugages.
121+
requires that we handle async callbacks. Golang has a simple, light-weight solution to that, using goroutines and channels,
122+
to pass callbacks and execution between the languages.
126123

127124
```mermaid
128125
stateDiagram-v2
@@ -144,12 +141,14 @@ stateDiagram-v2
144141

145142
### Decision Log
146143

147-
***TODO***
144+
The decision to use raw FFI request from Golang to Rust-core was straight forward:
145+
1. Golang contains goroutines as an alternative, lightweight, and performant solution serves as an obvious solution to pass request, even at scale.
146+
148147

149-
| Protocol | Details | Pros | Cons |
150-
|----------------------------------------------|---------|------|------|
151-
| Unix Domain Sockets (jni/netty) | | | |
152-
| Raw-FFI (JNA, uniffi-rs, j4rs, interoptopus) | | | |
148+
| Protocol | Details | Pros | Cons |
149+
|--------------------------|---------|--------------------------------------------------------|--------------------------------------|
150+
| Unix Domain Sockets | | UDS performance; consistent protocol between languages | complex configuration |
151+
| Raw-FFI (CGO/goroutines) | | simplified and light-weight interface | separate management for each request |
153152

154153
## Sequence Diagram - Raw-FFI Client
155154

0 commit comments

Comments
 (0)