Skip to content

Commit

Permalink
address comments and fix the license
Browse files Browse the repository at this point in the history
  • Loading branch information
rainj-me committed Dec 13, 2023
1 parent bfc34e2 commit e814dba
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2023 ihciah, rainj-me and other Monolake Contributors
Copyright (c) 2023 Monolake Contributors

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Monolake is a Rust-based high performance Layer 4/7 proxy framework which is bui

## Quick Start

The following guide is using to try monolake with the basic proxy features.
The following guide is trying to use monolake with the basic proxy features.

### Preparation

Expand Down Expand Up @@ -57,7 +57,7 @@ curl -kvvv https://localhost:8082/

Monoio is a subproject of [CloudWeGo](https://www.cloudwego.io).

Due to the limit resource, any help to make the monolake more mature, reporting issues or requesting features are welcome. Refer the [Contributing](./CONTRIBUTING.md) documents for the guidelines.
Due to the limited resources, any help to make the monolake more mature, reporting issues or requesting features are welcome. Refer the [Contributing](./CONTRIBUTING.md) documents for the guidelines.

## Dependencies

Expand Down
27 changes: 15 additions & 12 deletions docs/monolake.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

Earlier 2023, Cloudflare released a blog to introduce their Oxy, a Rust-based modern proxy framework. We have the similar requirements at Volcano Engine (a public cloud from Bytedance Inc.), so we start Monolake project, a layer 4/7 proxy framework base on Rust and Iouring.

# Architecture of Monolake
## Architecture of Monolake

There are 3 major categories in monolake, the runtime & transport, the tls and the http. Monolake currently supoprt Iouring and epoll runtime which are benefit from monoio(a thread-per-core rust runtime). The layer 4 proxy is implemented in monolake. The tls category currently support both rustls and native-tls, user can switch between these two solutions in case there is critical security defect in one of them. For the http category, monolake support http/1.1 and h2, we are currently working on the thrift protocol support, the grpc and h3 protocol support is planned.

```
```plain
+-----------+ +-----------+ +-----------+ +-----------+ +------------+ +-----------+
| HTTP | | HTTP/1.1 | | H2 | |monoio-http| |monoio-codec| | monolake |
+-----------+ +-----------+ +-----------+ +-----------+ +------------+ +-----------+
Expand All @@ -20,11 +20,12 @@ There are 3 major categories in monolake, the runtime & transport, the tls and t
|Transport | | | | | | | | |
+-----------+ +-----------+ +-----------+ +-----------+ +-----------+
```

Figure 1, the layers and monolake architecture

Besides multi-protocols and proxy features, monolake provides the ability to update the handler chains at runtime. Combine with the linux SO_REUSEPORT socket option, users can upgrade monolake binary at runtime.
Besides multi-protocols and proxy features, monolake provides the ability to update the handler chains at runtime. Combine with the linux SO_REUSEPORT socket option, users can upgrade monolake binary at runtime.

# Why monoio runtime with Thread-per-Core and Iouring support
## Why monoio runtime with Thread-per-Core and Iouring support

As we known, performance is one of the main factor for layer 4 and layer 7 proxy framework. To achieve this goal during the design phases, we decide to choose thread-per-core with CPU binding and io_uring as our major features. With thread-per-core feature, monolake can avoid the the context switch and inter process communication. With io_uring feature, monolake can avoid copy the memory between kernel space and the userspace. With these in mind, we carefully compare the Rust runtime between tokio, glommio and monoio. Tokio is the most popular asynchronous Rust runtime which has the most mature communities, but its thread model is not thread-per-core, and the async task can schedule on any thread which may requires context switch and lots of cross threads communication. Glommio and monoio are similar, both support io_uring and thread-per-core, we finally choose monoio due to the supportive from monoio community.

Expand All @@ -36,10 +37,11 @@ Figure 2. http connection reuse between POC and nginx
![https connection reuse](./https_conn_reuse.png)
Figure 3. https connection reuse between POC and nginx

# Runtime handler chain update
## Runtime handler chain update

Monolake's handler chain is organized as onion model, same concept as tower.rs' layer. The service (handler) trait is defined with the async fn in trait feature (will be stable at rust toolchain 1.75), as below
```

```rust
pub trait Service<Request> {
/// Responses given by the service.
type Response;
Expand All @@ -50,9 +52,10 @@ pub trait Service<Request> {
fn call(&self, req: Request) -> impl Future<Output = Result<Self::Response, Self::Error>>;
}
```

Code Block 1. the service (handler) trait.

```
```plain
+---------------------------------+
| Service C |
| +----------------------+ |<---- Req
Expand All @@ -63,10 +66,12 @@ Code Block 1. the service (handler) trait.
| +----------------------+ |----> Resp
+---------------------------------+
```

Figure 4. monolake handler chain diagram

Since we build monolake as static compiling, it is hard to change the state of the handler at runtime. To tackle the problem, we proposal to rebuild the handlers chain at runtime.
```

```plain
+-------------------------------------+ +--------------------------------------------------------------+
| Main Thread | | Worker Thread |
| | | |
Expand Down Expand Up @@ -94,13 +99,11 @@ Since we build monolake as static compiling, it is hard to change the state of t
+--------------------------------------------------------------+
```

Figure 5. monolake handler chain runtime upgrade

Refer the [sample code](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=021cf8353df756eb39b578fe9e29e36b) for the runtime handler chain update proposal. This proposal is also working under tokio runtime, if we implement the handlers chain with tokio runtime.

# Next steps
## Next steps

For the next steps, we plan to support Quic and H3 as our highest priority. We also would like to re-implement the H2 instead of directly modifying the code from h2 crate. We also plan to support additional userspace event library like dpdk.



2 changes: 1 addition & 1 deletion examples/LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2023 ihciah, rainj-me and other Monolake Contributors
Copyright (c) 2023 Monolake Contributors

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
Expand Down
2 changes: 1 addition & 1 deletion monolake-core/LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2023 ihciah, rainj-me and other Monolake Contributors
Copyright (c) 2023 Monolake Contributors

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
Expand Down
2 changes: 1 addition & 1 deletion monolake-services/LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2023 ihciah, rainj-me and other Monolake Contributors
Copyright (c) 2023 Monolake Contributors

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
Expand Down
2 changes: 1 addition & 1 deletion monolake/LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2023 ihciah, rainj-me and other Monolake Contributors
Copyright (c) 2023 Monolake Contributors

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
Expand Down

0 comments on commit e814dba

Please sign in to comment.