From e814dba5cca5aca45009d406459b592b5209c546 Mon Sep 17 00:00:00 2001 From: Rain Jiang Date: Wed, 13 Dec 2023 18:22:10 +0000 Subject: [PATCH] address comments and fix the license --- LICENSE-MIT | 2 +- README.md | 4 ++-- docs/monolake.md | 27 +++++++++++++++------------ examples/LICENSE-MIT | 2 +- monolake-core/LICENSE-MIT | 2 +- monolake-services/LICENSE-MIT | 2 +- monolake/LICENSE-MIT | 2 +- 7 files changed, 22 insertions(+), 19 deletions(-) diff --git a/LICENSE-MIT b/LICENSE-MIT index 12911c9..e9efe9e 100644 --- a/LICENSE-MIT +++ b/LICENSE-MIT @@ -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 diff --git a/README.md b/README.md index 971e46c..c14b6a6 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/docs/monolake.md b/docs/monolake.md index dab6d08..ddba79e 100644 --- a/docs/monolake.md +++ b/docs/monolake.md @@ -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 | +-----------+ +-----------+ +-----------+ +-----------+ +------------+ +-----------+ @@ -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. @@ -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 { /// Responses given by the service. type Response; @@ -50,9 +52,10 @@ pub trait Service { fn call(&self, req: Request) -> impl Future>; } ``` + Code Block 1. the service (handler) trait. -``` +```plain +---------------------------------+ | Service C | | +----------------------+ |<---- Req @@ -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 | | | | | @@ -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. - - - diff --git a/examples/LICENSE-MIT b/examples/LICENSE-MIT index 12911c9..e9efe9e 100644 --- a/examples/LICENSE-MIT +++ b/examples/LICENSE-MIT @@ -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 diff --git a/monolake-core/LICENSE-MIT b/monolake-core/LICENSE-MIT index 12911c9..e9efe9e 100644 --- a/monolake-core/LICENSE-MIT +++ b/monolake-core/LICENSE-MIT @@ -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 diff --git a/monolake-services/LICENSE-MIT b/monolake-services/LICENSE-MIT index 12911c9..e9efe9e 100644 --- a/monolake-services/LICENSE-MIT +++ b/monolake-services/LICENSE-MIT @@ -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 diff --git a/monolake/LICENSE-MIT b/monolake/LICENSE-MIT index 12911c9..e9efe9e 100644 --- a/monolake/LICENSE-MIT +++ b/monolake/LICENSE-MIT @@ -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