mirror of
https://github.com/MercuryWorkshop/epoxy-tls.git
synced 2025-05-13 06:20:02 -04:00
switch to jemalloc and add memory stats
This commit is contained in:
parent
0f05588b8f
commit
6f0e1e7feb
3 changed files with 81 additions and 1 deletions
39
Cargo.lock
generated
39
Cargo.lock
generated
|
@ -573,6 +573,8 @@ dependencies = [
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_yaml",
|
"serde_yaml",
|
||||||
"shell-words",
|
"shell-words",
|
||||||
|
"tikv-jemalloc-ctl",
|
||||||
|
"tikv-jemallocator",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-util",
|
"tokio-util",
|
||||||
"toml",
|
"toml",
|
||||||
|
@ -1205,6 +1207,12 @@ dependencies = [
|
||||||
"windows-targets",
|
"windows-targets",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "paste"
|
||||||
|
version = "1.0.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "percent-encoding"
|
name = "percent-encoding"
|
||||||
version = "2.3.1"
|
version = "2.3.1"
|
||||||
|
@ -1726,6 +1734,37 @@ dependencies = [
|
||||||
"once_cell",
|
"once_cell",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tikv-jemalloc-ctl"
|
||||||
|
version = "0.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f21f216790c8df74ce3ab25b534e0718da5a1916719771d3fec23315c99e468b"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"paste",
|
||||||
|
"tikv-jemalloc-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tikv-jemalloc-sys"
|
||||||
|
version = "0.6.0+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cd3c60906412afa9c2b5b5a48ca6a5abe5736aec9eb48ad05037a677e52e4e2d"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tikv-jemallocator"
|
||||||
|
version = "0.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4cec5ff18518d81584f477e9bfdf957f5bb0979b0bac3af4ca30b5b3ae2d2865"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"tikv-jemalloc-sys",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio"
|
name = "tokio"
|
||||||
version = "1.39.3"
|
version = "1.39.3"
|
||||||
|
|
|
@ -27,6 +27,8 @@ serde = { version = "1.0.208", features = ["derive"] }
|
||||||
serde_json = { version = "1.0.125", optional = true }
|
serde_json = { version = "1.0.125", optional = true }
|
||||||
serde_yaml = { version = "0.9.34", optional = true }
|
serde_yaml = { version = "0.9.34", optional = true }
|
||||||
shell-words = { version = "1.1.0", optional = true }
|
shell-words = { version = "1.1.0", optional = true }
|
||||||
|
tikv-jemalloc-ctl = { version = "0.6.0", features = ["stats", "use_std"] }
|
||||||
|
tikv-jemallocator = "0.6.0"
|
||||||
tokio = { version = "1.39.3", features = ["full"] }
|
tokio = { version = "1.39.3", features = ["full"] }
|
||||||
tokio-util = { version = "0.7.11", features = ["codec", "compat", "io-util", "net"] }
|
tokio-util = { version = "0.7.11", features = ["codec", "compat", "io-util", "net"] }
|
||||||
toml = { version = "0.8.19", optional = true }
|
toml = { version = "0.8.19", optional = true }
|
||||||
|
|
|
@ -40,9 +40,45 @@ fn format_stream_type(stream_type: StreamType) -> &'static str {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_stats() -> Result<String, std::fmt::Error> {
|
fn generate_stats() -> anyhow::Result<String> {
|
||||||
let mut out = String::new();
|
let mut out = String::new();
|
||||||
let len = CLIENTS.len();
|
let len = CLIENTS.len();
|
||||||
|
|
||||||
|
use tikv_jemalloc_ctl::stats::{active, allocated, mapped, metadata, resident, retained};
|
||||||
|
tikv_jemalloc_ctl::epoch::advance()?;
|
||||||
|
|
||||||
|
writeln!(&mut out, "Memory usage:")?;
|
||||||
|
writeln!(
|
||||||
|
&mut out,
|
||||||
|
"\tActive: {:?} MiB",
|
||||||
|
active::read()? as f64 / (1024 * 1024) as f64
|
||||||
|
)?;
|
||||||
|
writeln!(
|
||||||
|
&mut out,
|
||||||
|
"\tAllocated: {:?} MiB",
|
||||||
|
allocated::read()? as f64 / (1024 * 1024) as f64
|
||||||
|
)?;
|
||||||
|
writeln!(
|
||||||
|
&mut out,
|
||||||
|
"\tMapped: {:?} MiB",
|
||||||
|
mapped::read()? as f64 / (1024 * 1024) as f64
|
||||||
|
)?;
|
||||||
|
writeln!(
|
||||||
|
&mut out,
|
||||||
|
"\tMetadata: {:?} MiB",
|
||||||
|
metadata::read()? as f64 / (1024 * 1024) as f64
|
||||||
|
)?;
|
||||||
|
writeln!(
|
||||||
|
&mut out,
|
||||||
|
"\tResident: {:?} MiB",
|
||||||
|
resident::read()? as f64 / (1024 * 1024) as f64
|
||||||
|
)?;
|
||||||
|
writeln!(
|
||||||
|
&mut out,
|
||||||
|
"\tRetained: {:?} MiB",
|
||||||
|
retained::read()? as f64 / (1024 * 1024) as f64
|
||||||
|
)?;
|
||||||
|
|
||||||
writeln!(
|
writeln!(
|
||||||
&mut out,
|
&mut out,
|
||||||
"{} clients connected{}",
|
"{} clients connected{}",
|
||||||
|
@ -108,6 +144,9 @@ fn handle_stream(stream: ServerRouteResult, id: String) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[global_allocator]
|
||||||
|
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
|
||||||
|
|
||||||
#[tokio::main(flavor = "multi_thread")]
|
#[tokio::main(flavor = "multi_thread")]
|
||||||
async fn main() -> anyhow::Result<()> {
|
async fn main() -> anyhow::Result<()> {
|
||||||
if CLI.default_config {
|
if CLI.default_config {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue