From 6bf3fa32e66c4b40f352c8a4cab126241a995e4e Mon Sep 17 00:00:00 2001 From: ihciah Date: Tue, 23 Nov 2021 17:41:50 +0800 Subject: [PATCH] impl basic client and server(monoio, tokio, glommio) --- .gitignore | 1 + Cargo.lock | 1049 ++++++++++++++++++++++++++++++++++++ Cargo.toml | 11 + LICENSE-APACHE | 202 +++++++ LICENSE-MIT | 25 + README.md | 15 + client/Cargo.toml | 10 + client/src/main.rs | 139 +++++ config/Cargo.toml | 7 + config/src/lib.rs | 105 ++++ glommio-server/Cargo.toml | 10 + glommio-server/src/main.rs | 52 ++ monoio-server/Cargo.toml | 9 + monoio-server/src/main.rs | 54 ++ tokio-server/Cargo.toml | 9 + tokio-server/src/main.rs | 53 ++ 16 files changed, 1751 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 LICENSE-APACHE create mode 100644 LICENSE-MIT create mode 100644 README.md create mode 100644 client/Cargo.toml create mode 100644 client/src/main.rs create mode 100644 config/Cargo.toml create mode 100644 config/src/lib.rs create mode 100644 glommio-server/Cargo.toml create mode 100644 glommio-server/src/main.rs create mode 100644 monoio-server/Cargo.toml create mode 100644 monoio-server/src/main.rs create mode 100644 tokio-server/Cargo.toml create mode 100644 tokio-server/src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..b7d3008 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,1049 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19fac972e53443ba111b1ff866e9d3b6484df5c05030e13bc7c6a1ebc802e983" +dependencies = [ + "getrandom", + "lazy_static", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi 0.3.9", +] + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitmaps" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "031043d04099746d8db04daf1fa424b2bc8bd69d92b25962dcde24da39ab64a2" +dependencies = [ + "typenum", +] + +[[package]] +name = "buddy-alloc" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ff9f338986406db85e2b5deb40a9255b796ca03a194c7457403d215173f3fd5" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "bytes" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" + +[[package]] +name = "cache-padded" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba" + +[[package]] +name = "cc" +version = "1.0.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clap" +version = "3.0.0-beta.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "feff3878564edb93745d58cf63e17b63f24142506e7a20c87a5521ed7bfb1d63" +dependencies = [ + "atty", + "bitflags", + "clap_derive", + "indexmap", + "lazy_static", + "os_str_bytes", + "strsim", + "termcolor", + "textwrap", + "unicase", +] + +[[package]] +name = "clap_derive" +version = "3.0.0-beta.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b15c6b4f786ffb6192ffe65a36855bc1fc2444bcd0945ae16748dcd6ed7d0d3" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "client" +version = "0.1.0" +dependencies = [ + "config", + "local-sync", + "monoio", +] + +[[package]] +name = "concurrent-queue" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30ed07550be01594c6026cff2a1d7fe9c8f683caa798e12b68694ac9e88286a3" +dependencies = [ + "cache-padded", +] + +[[package]] +name = "config" +version = "0.1.0" +dependencies = [ + "clap", +] + +[[package]] +name = "crossbeam" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae5588f6b3c3cb05239e90bd110f257254aecd01e4635400391aeae07497845" +dependencies = [ + "cfg-if", + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-epoch", + "crossbeam-queue", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd" +dependencies = [ + "cfg-if", + "crossbeam-utils", + "lazy_static", + "memoffset 0.6.4", + "scopeguard", +] + +[[package]] +name = "crossbeam-queue" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b10ddc024425c88c2ad148c1b0fd53f4c6d38db9697c9f1588381212fa657c9" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" +dependencies = [ + "cfg-if", + "lazy_static", +] + +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + +[[package]] +name = "enclose" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1056f553da426e9c025a662efa48b52e62e0a3a7648aa2d15aeaaf7f0d329357" + +[[package]] +name = "fastrand" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b394ed3d285a429378d3b384b9eb1285267e7df4b166df24b7a6939a04dc392e" +dependencies = [ + "instant", +] + +[[package]] +name = "futures" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cd0210d8c325c245ff06fd95a3b13689a1a276ac8cfa8e8720cb840bfb84b9e" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fc8cd39e3dbf865f7340dce6a2d401d24fd37c6fe6c4f0ee0de8bfca2252d27" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "629316e42fe7c2a0b9a65b47d159ceaa5453ab14e8f0a3c5eedbb8cd55b4a445" + +[[package]] +name = "futures-executor" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b808bf53348a36cab739d7e04755909b9fcaaa69b7d7e588b37b6ec62704c97" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e481354db6b5c353246ccf6a728b0c5511d752c08da7260546fc0933869daa11" + +[[package]] +name = "futures-lite" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite", + "waker-fn", +] + +[[package]] +name = "futures-macro" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89f17b21645bc4ed773c69af9c9a0effd4a3f1a3876eadd453469f8854e7fdd" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "996c6442437b62d21a32cd9906f9c41e7dc1e19a9579843fad948696769305af" + +[[package]] +name = "futures-task" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dabf1872aaab32c886832f2276d2f5399887e2bd613698a02359e4ea83f8de12" + +[[package]] +name = "futures-util" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d22213122356472061ac0f1ab2cee28d2bac8491410fd68c2af53d1cedb83e" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "getrandom" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "glommio" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de78464c368ab4ae8ab235b82b019317b2c82475aecbbd8c8d8100cd15831b31" +dependencies = [ + "ahash", + "bitflags", + "bitmaps", + "buddy-alloc", + "cc", + "concurrent-queue", + "crossbeam", + "enclose", + "futures-lite", + "intrusive-collections", + "itertools", + "lazy_static", + "libc", + "lockfree", + "log", + "membarrier", + "nix 0.22.0", + "pin-project-lite", + "rlimit", + "scoped-tls", + "scopeguard", + "smallvec", + "socket2 0.3.19", + "tracing", + "typenum", +] + +[[package]] +name = "glommio-server" +version = "0.1.0" +dependencies = [ + "config", + "futures-lite", + "glommio", +] + +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" + +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "indexmap" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "intrusive-collections" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb4ed164b4cf1c6bd6e18c097490331a0e58fbb0f39e8f6b5ac7f168006511cd" +dependencies = [ + "memoffset 0.5.6", +] + +[[package]] +name = "io-uring" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d75829ed9377bab6c90039fe47b9d84caceb4b5063266142e21bcce6550cda8" +dependencies = [ + "bitflags", + "libc", +] + +[[package]] +name = "itertools" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69ddb889f9d0d08a67338271fa9b62996bc788c7796a5c18cf057420aaed5eaf" +dependencies = [ + "either", +] + +[[package]] +name = "kernel32-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +dependencies = [ + "winapi 0.2.8", + "winapi-build", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119" + +[[package]] +name = "local-sync" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8809aae5cffb08df37e31c4b5311ab868d58f82fa4af7fbf9d87c7a3f4ba34d" +dependencies = [ + "futures-core", + "futures-sink", + "futures-util", +] + +[[package]] +name = "lock_api" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712a4d093c9976e24e7dbca41db895dabcbac38eb5f4045393d17a95bdfb1109" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "lockfree" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74ee94b5ad113c7cb98c5a040f783d0952ee4fe100993881d1673c2cb002dd23" +dependencies = [ + "owned-alloc", +] + +[[package]] +name = "log" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "membarrier" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925b0811d7e5fb2b666b5906c5047b7ec23aab78edc4d51b7b0f82dc5c955b1c" +dependencies = [ + "cfg-if", + "kernel32-sys", + "lazy_static", + "libc", +] + +[[package]] +name = "memchr" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" + +[[package]] +name = "memoffset" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "043175f069eda7b85febe4a74abbaeff828d9f8b448515d3151a14a3542811aa" +dependencies = [ + "autocfg", +] + +[[package]] +name = "memoffset" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9" +dependencies = [ + "autocfg", +] + +[[package]] +name = "mio" +version = "0.7.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc" +dependencies = [ + "libc", + "log", + "miow", + "ntapi", + "winapi 0.3.9", +] + +[[package]] +name = "miow" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" +dependencies = [ + "winapi 0.3.9", +] + +[[package]] +name = "monoio" +version = "0.0.2" +dependencies = [ + "bytes", + "futures", + "fxhash", + "io-uring", + "libc", + "monoio-macros", + "nix 0.23.0", + "os_socketaddr", + "pin-project-lite", + "pin-utils", + "scoped-tls", + "socket2 0.4.2", +] + +[[package]] +name = "monoio-macros" +version = "0.0.2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "monoio-server" +version = "0.1.0" +dependencies = [ + "config", + "monoio", +] + +[[package]] +name = "nix" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1e25ee6b412c2a1e3fcb6a4499a5c1bfe7f43e014bdce9a6b6666e5aa2d187" +dependencies = [ + "bitflags", + "cc", + "cfg-if", + "libc", + "memoffset 0.6.4", +] + +[[package]] +name = "nix" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f305c2c2e4c39a82f7bf0bf65fb557f9070ce06781d4f2454295cc34b1c43188" +dependencies = [ + "bitflags", + "cc", + "cfg-if", + "libc", + "memoffset 0.6.4", +] + +[[package]] +name = "ntapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" +dependencies = [ + "winapi 0.3.9", +] + +[[package]] +name = "num_cpus" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" + +[[package]] +name = "os_socketaddr" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ff86dee67903f9ffcc3f09712b934761ace77cd34021848a474e7ed7199bd2" +dependencies = [ + "libc", + "winapi 0.3.9", +] + +[[package]] +name = "os_str_bytes" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "addaa943333a514159c80c97ff4a93306530d965d27e139188283cd13e06a799" +dependencies = [ + "memchr", +] + +[[package]] +name = "owned-alloc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30fceb411f9a12ff9222c5f824026be368ff15dc2f13468d850c7d3f502205d6" + +[[package]] +name = "parking" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" + +[[package]] +name = "parking_lot" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" +dependencies = [ + "cfg-if", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi 0.3.9", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rlimit" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81a9ed03edbed449d6897c2092c71ab5f7b5fb80f6f0b1a3ed6d40a6f9fc0720" +dependencies = [ + "libc", +] + +[[package]] +name = "scoped-tls" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "signal-hook-registry" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" + +[[package]] +name = "smallvec" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309" + +[[package]] +name = "socket2" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" +dependencies = [ + "cfg-if", + "libc", + "winapi 0.3.9", +] + +[[package]] +name = "socket2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dc90fe6c7be1a323296982db1836d1ea9e47b6839496dde9a541bc496df3516" +dependencies = [ + "libc", + "winapi 0.3.9", +] + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "syn" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2afee18b8beb5a596ecb4a2dce128c719b4ba399d34126b9e4396e3f9860966" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "termcolor" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "textwrap" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "tokio" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70e992e41e0d2fb9f755b37446f20900f64446ef54874f40a60c78f021ac6144" +dependencies = [ + "autocfg", + "bytes", + "libc", + "memchr", + "mio", + "num_cpus", + "once_cell", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "tokio-macros", + "winapi 0.3.9", +] + +[[package]] +name = "tokio-macros" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9efc1aba077437943f7515666aa2b882dfabfbfdf89c819ea75a8d6e9eaba5e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-server" +version = "0.1.0" +dependencies = [ + "config", + "tokio", +] + +[[package]] +name = "tracing" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" +dependencies = [ + "cfg-if", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "typenum" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec" + +[[package]] +name = "unicase" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +dependencies = [ + "version_check", +] + +[[package]] +name = "unicode-segmentation" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" + +[[package]] +name = "unicode-width" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "version_check" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" + +[[package]] +name = "waker-fn" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" + +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + +[[package]] +name = "winapi" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-build" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi 0.3.9", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..6e1b86d --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,11 @@ +[workspace] + +members = [ + "monoio-server", + "tokio-server", + "glommio-server", + + "client", + + "config" +] \ No newline at end of file diff --git a/LICENSE-APACHE b/LICENSE-APACHE new file mode 100644 index 0000000..1a24dc0 --- /dev/null +++ b/LICENSE-APACHE @@ -0,0 +1,202 @@ +Copyright (c) 2021 ihciah and Monoio Contributors + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. \ No newline at end of file diff --git a/LICENSE-MIT b/LICENSE-MIT new file mode 100644 index 0000000..5c2a387 --- /dev/null +++ b/LICENSE-MIT @@ -0,0 +1,25 @@ +Copyright (c) 2021 ihciah and Monoio Contributors + +Permission is hereby granted, free of charge, to any +person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the +Software without restriction, including without +limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice +shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..d64cecc --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# Monoio Benchmark + +TCP ping-pong(not echo) is a common benchmark for network applications. + +We will use 1K ping-pong to test performance of different runtimes. Server will receive 1K data(and parse it in real applications) and reply 1K data. + +## Max throughput +With given connections(enough for fully utilize CPU cores which latency is not important), we can measure the maximum throughput. + +TODO: 1C/4C with 3 runtimes, different connections, watch the throughput. + +## Fixed QPS +We can measure the latency and CPU utilization of different runtimes. + +TODO: 1C/4C with 3 runtimes, different QPS, watch latency and CPU utilization. \ No newline at end of file diff --git a/client/Cargo.toml b/client/Cargo.toml new file mode 100644 index 0000000..1590b1d --- /dev/null +++ b/client/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "client" +version = "0.1.0" +edition = "2021" + +[dependencies] +config = {path="../config"} + +monoio = {path="../../monoio/monoio"} +local-sync = "0.0.2" diff --git a/client/src/main.rs b/client/src/main.rs new file mode 100644 index 0000000..24c1c99 --- /dev/null +++ b/client/src/main.rs @@ -0,0 +1,139 @@ +use std::{ + cell::UnsafeCell, + rc::Rc, + sync::{atomic::{AtomicUsize, AtomicU64}, Arc}, + time::Duration, +}; + +use config::{ClientConfig, COUNT_GRAIN_PRE_SEC, PACKET_SIZE}; +use local_sync::semaphore::Semaphore; +use monoio::{ + io::{AsyncReadRentExt, AsyncWriteRentExt}, + net::TcpStream, + RuntimeBuilder, +}; + +fn main() { + let cfg = Arc::new(ClientConfig::parse()); + println!( + r"Running ping pong client. +Packet size: {} +Connection count per core: {}; Global connection count: {} +QPS limit per core: {}; Global QPS limit: {} +Target: {} +CPU slot: {}", + PACKET_SIZE, + cfg.conns_per_core, + cfg.conns_per_core * cfg.cores.len(), + cfg.qps_per_core.unwrap_or(0), + cfg.qps_per_core.unwrap_or(0) * cfg.cores.len(), + cfg.target, + config::format_cores(&cfg.cores) + ); + assert!( + cfg.qps_per_core.unwrap_or(COUNT_GRAIN_PRE_SEC as _) >= COUNT_GRAIN_PRE_SEC as _, + "QPS limit should be more than COUNT_GRAIN_PRE_SEC" + ); + + // count will be shared across threads + let count = Arc::new(AtomicUsize::new(0)); + let eps = Arc::new(AtomicU64::new(0)); + + for cpu in cfg.cores.iter() { + let cfg_ = cfg.clone(); + let cpu_ = *cpu as _; + let count_ = count.clone(); + let eps_ = eps.clone(); + std::thread::spawn(move || { + monoio::utils::bind_to_cpu_set(Some(cpu_)).unwrap(); + let mut rt = RuntimeBuilder::new().with_entries(2560).enable_timer().build().unwrap(); + rt.block_on(run_thread(count_, eps_, cfg_)); + }); + } + + // every second(not precise), we will print the status + let mut count_last = 0; + let instant = std::time::Instant::now(); + loop { + std::thread::sleep(Duration::from_secs(1)); + let count_now = count.load(std::sync::atomic::Ordering::Relaxed); + let eps_now = eps.load(std::sync::atomic::Ordering::Relaxed); + let eps_sec = instant.elapsed().as_secs_f32(); + println!( + "{:.3}: NAdd: {}; NSum: {}; NAverage: {:.3}, LatencyAverage: {:.3} us", + eps_sec, + count_now - count_last, + count_now, + count_now as f32 / eps_sec, + eps_now as f32 / count_now as f32, + ); + count_last = count_now; + } +} + +// start new tasks for each connection on the same thread +async fn run_thread(count: Arc, eps: Arc, cfg: Arc) { + let mut hdrs = Vec::with_capacity(cfg.conns_per_core); + + // count_tls and sem will be shared across tasks. + let count_tls = Rc::new(UnsafeCell::new(0)); + let eps_tls = Rc::new(UnsafeCell::new(0)); + let grain_n = cfg.qps_per_core.unwrap_or(0) / COUNT_GRAIN_PRE_SEC as usize; + let sem = cfg.qps_per_core.map(|_| Rc::new(Semaphore::new(grain_n))); + + for _ in 0..cfg.conns_per_core { + hdrs.push(monoio::spawn(run_conn( + count_tls.clone(), + eps_tls.clone(), + sem.clone(), + cfg.target.clone(), + ))); + } + let mut interval = monoio::time::interval(Duration::from_secs(1) / COUNT_GRAIN_PRE_SEC); + loop { + interval.tick().await; + let c = unsafe { &mut *count_tls.get() }; + let e = unsafe { &mut *eps_tls.get() }; + count.fetch_add(*c, std::sync::atomic::Ordering::Relaxed); + *c = 0; + eps.fetch_add(*e, std::sync::atomic::Ordering::Relaxed); + *e = 0; + if let Some(s) = sem.as_ref() { + s.add_permits(grain_n); + } + } +} + +async fn run_conn( + count: Rc>, + eps: Rc>, + qps_per_conn: Option>, + target: String, +) { + let mut buf = vec![0; PACKET_SIZE]; + let stream = TcpStream::connect(target).await.unwrap(); + + loop { + if let Some(s) = qps_per_conn.as_ref() { + s.acquire().await.unwrap().forget(); + } + + let begin = std::time::Instant::now(); + let (w, buf_w) = stream.write_all(buf).await; + if w.is_err() { + // The connection is closed. + return; + } + let (r, buf_r) = stream.read_exact(buf_w).await; + if r.is_err() { + // The connection is closed. + return; + } + let eps_ = begin.elapsed().as_micros() as u64; + buf = buf_r; + unsafe { + *count.get() += 1; + *eps.get() += eps_; + } + } +} diff --git a/config/Cargo.toml b/config/Cargo.toml new file mode 100644 index 0000000..c48efaf --- /dev/null +++ b/config/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "config" +version = "0.1.0" +edition = "2021" + +[dependencies] +clap = "3.0.0-beta.5" diff --git a/config/src/lib.rs b/config/src/lib.rs new file mode 100644 index 0000000..71ccb9d --- /dev/null +++ b/config/src/lib.rs @@ -0,0 +1,105 @@ +use clap::Parser; + +// in Byte +pub const PACKET_SIZE: usize = 10; +// 100ms +pub const COUNT_GRAIN_PRE_SEC: u32 = 10; + +#[derive(Parser, Debug, Clone, PartialEq)] +#[clap(version = "1.0", author = "ihciah ")] +pub struct ServerConfig { + #[clap( + short, + long, + min_values = 1, + default_value = "1", + about = "cpu core id list" + )] + pub cores: Vec, + #[clap( + short, + long, + about = "bind address, like 127.0.0.1:8080", + default_value = "[::]:40000" + )] + pub bind: String, +} + +#[derive(Parser, Debug, Clone, PartialEq)] +#[clap(version = "1.0", author = "ihciah ")] +pub struct ClientConfig { + #[clap( + short, + long, + min_values = 1, + default_value = "0", + about = "cpu core id list" + )] + pub cores: Vec, + #[clap( + short = 'n', + long, + about = "connection numbers per core", + default_value = "50" + )] + pub conns_per_core: usize, + #[clap( + short, + long, + about = "QPS limit per core, leave blank means unlimited" + )] + pub qps_per_core: Option, + #[clap( + short, + long, + about = "target address, like 127.0.0.1:8080", + default_value = "127.0.0.1:40000" + )] + pub target: String, +} + +impl ServerConfig { + pub fn parse() -> Self { + Parser::parse() + } +} + +impl ClientConfig { + pub fn parse() -> Self { + Parser::parse() + } +} + +pub fn format_cores(cores: &[u8]) -> String { + cores + .iter() + .map(|&c| c.to_string()) + .collect::>() + .join(",") +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_cfg() { + let cfg = ServerConfig::parse_from(&["test", "-c", "1", "2", "-b", ":8080"]); + assert_eq!( + cfg, + ServerConfig { + cores: vec![1, 2], + bind: ":8080".to_string() + } + ); + + let cfg = ServerConfig::parse_from(&["test", "-b", ":8080"]); + assert_eq!( + cfg, + ServerConfig { + cores: vec![1], + bind: ":8080".to_string() + } + ); + } +} diff --git a/glommio-server/Cargo.toml b/glommio-server/Cargo.toml new file mode 100644 index 0000000..f34646a --- /dev/null +++ b/glommio-server/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "glommio-server" +version = "0.1.0" +edition = "2021" + +[dependencies] +config = {path="../config"} + +glommio = "0.6" +futures-lite = "1.12" \ No newline at end of file diff --git a/glommio-server/src/main.rs b/glommio-server/src/main.rs new file mode 100644 index 0000000..87a1b17 --- /dev/null +++ b/glommio-server/src/main.rs @@ -0,0 +1,52 @@ +use std::sync::Arc; + +use config::{ServerConfig, PACKET_SIZE}; +use futures_lite::{StreamExt, AsyncReadExt, AsyncWriteExt}; +use glommio::{LocalExecutorBuilder, net::TcpListener, Task}; + +fn main() { + let cfg = Arc::new(ServerConfig::parse()); + println!( + "Running ping pong server with Glommio.\nPacket size: {}\nListen {}\nCPU slot: {}", + PACKET_SIZE, + cfg.bind, + config::format_cores(&cfg.cores) + ); + + let mut threads = Vec::new(); + for cpu in cfg.cores.iter() { + let cfg_ = cfg.clone(); + let cpu_ = *cpu as _; + let h = std::thread::spawn(move || { + let ex = LocalExecutorBuilder::new().pin_to_cpu(cpu_).make().unwrap(); + + ex.run(serve(cfg_)); + }); + threads.push(h); + } + for h in threads { + let _ = h.join(); + } +} + +async fn serve(cfg: Arc) { + let listener = TcpListener::bind(&cfg.bind).unwrap(); + let mut incoming = listener.incoming(); + while let Some(stream) = incoming.next().await { + let mut stream = stream.unwrap(); + Task::local(async move { + let mut buf = vec![0; PACKET_SIZE]; + loop { + match stream.read_exact(&mut buf).await { + Ok(_) => {} + Err(_) => return, + } + match stream.write_all(&buf).await { + Ok(_) => {} + Err(_) => return, + } + } + }) + .detach(); + } +} diff --git a/monoio-server/Cargo.toml b/monoio-server/Cargo.toml new file mode 100644 index 0000000..39f1a58 --- /dev/null +++ b/monoio-server/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "monoio-server" +version = "0.1.0" +edition = "2021" + +[dependencies] +config = {path="../config"} + +monoio = {path="../../monoio/monoio"} diff --git a/monoio-server/src/main.rs b/monoio-server/src/main.rs new file mode 100644 index 0000000..ed5943d --- /dev/null +++ b/monoio-server/src/main.rs @@ -0,0 +1,54 @@ +use std::sync::Arc; + +use config::{ServerConfig, PACKET_SIZE}; +use monoio::{net::TcpListener, RuntimeBuilder, io::{AsyncReadRentExt, AsyncWriteRentExt}}; + +fn main() { + let cfg = Arc::new(ServerConfig::parse()); + println!( + "Running ping pong server with Monoio.\nPacket size: {}\nListen {}\nCPU slot: {}", + PACKET_SIZE, + cfg.bind, + config::format_cores(&cfg.cores) + ); + + let mut threads = Vec::new(); + for cpu in cfg.cores.iter() { + let cfg_ = cfg.clone(); + let cpu_ = *cpu as _; + let h = std::thread::spawn(move || { + monoio::utils::bind_to_cpu_set(Some(cpu_)).unwrap(); + let mut rt = RuntimeBuilder::new() + .with_entries(2560) + .build() + .unwrap(); + rt.block_on(serve(cfg_)); + }); + threads.push(h); + } + for h in threads { + let _ = h.join(); + } +} + +async fn serve(cfg: Arc) { + let listener = TcpListener::bind(&cfg.bind).unwrap(); + while let Ok((stream, _)) = listener.accept().await { + monoio::spawn(async move { + let mut buf = vec![0; PACKET_SIZE]; + loop { + let (r, buf_r) = stream.read_exact(buf).await; + if r.is_err() { + // The connection is closed. + return; + } + let (w, buf_w) = stream.write_all(buf_r).await; + if w.is_err() { + // The connection is closed. + return; + } + buf = buf_w; + } + }); + } +} diff --git a/tokio-server/Cargo.toml b/tokio-server/Cargo.toml new file mode 100644 index 0000000..ac8c8fe --- /dev/null +++ b/tokio-server/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "tokio-server" +version = "0.1.0" +edition = "2021" + +[dependencies] +config = {path="../config"} + +tokio = {version = "1", features = ["full"]} diff --git a/tokio-server/src/main.rs b/tokio-server/src/main.rs new file mode 100644 index 0000000..9b2183c --- /dev/null +++ b/tokio-server/src/main.rs @@ -0,0 +1,53 @@ +// Since we can hardly control every thread, we should use `taskset`. + +use config::{ServerConfig, PACKET_SIZE}; +use tokio::{ + io::{AsyncReadExt, AsyncWriteExt}, + net::TcpListener, + runtime::{Builder, Runtime}, +}; + +fn main() { + let cfg = ServerConfig::parse(); + let cores = cfg.cores.len(); + println!( + "Running ping pong server with Tokio.\nPacket size: {}\nListen {}\nCPU count: {}", + PACKET_SIZE, cfg.bind, cores + ); + let rt = if cores == 1 { + Builder::new_current_thread().enable_all().build().unwrap() + } else { + Builder::new_multi_thread() + .enable_all() + .worker_threads(cores) + .build() + .unwrap() + }; + + rt.block_on(serve(&cfg, &rt)) +} + +async fn serve(cfg: &ServerConfig, rt: &Runtime) { + let listener = TcpListener::bind(&cfg.bind).await.unwrap(); + + loop { + let (mut stream, _) = listener.accept().await.unwrap(); + rt.spawn(async move { + let mut buf = vec![0; PACKET_SIZE]; + loop { + match stream.read_exact(&mut buf).await { + Ok(_) => {} + Err(_) => { + return; + } + } + match stream.write_all(&buf).await { + Ok(_) => {} + Err(_) => { + return; + } + } + } + }); + } +}