some optimization using rustc-hash, parking_lot and tikv-jemallocator
This commit is contained in:
parent
6466e7a309
commit
3e850e8410
5 changed files with 27 additions and 25 deletions
16
Cargo.toml
16
Cargo.toml
|
|
@ -12,8 +12,7 @@ publish = false
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[features]
|
||||
default = ["tls"]
|
||||
tls = ["tokio-rustls", "rustls-pemfile"]
|
||||
default = []
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.58"
|
||||
|
|
@ -27,7 +26,6 @@ hyper = { version = "0.14.19", default-features = false, features = [
|
|||
"stream",
|
||||
] }
|
||||
log = "0.4.17"
|
||||
mimalloc = { version = "0.1.29", default-features = false }
|
||||
tokio = { version = "1.19.2", features = [
|
||||
"net",
|
||||
"rt-multi-thread",
|
||||
|
|
@ -36,13 +34,12 @@ tokio = { version = "1.19.2", features = [
|
|||
"sync",
|
||||
"macros",
|
||||
] }
|
||||
tokio-rustls = { version = "0.23.4", features = [
|
||||
"early-data",
|
||||
], optional = true }
|
||||
rustls-pemfile = { version = "1.0.0", optional = true }
|
||||
tokio-rustls = { version = "0.23.4", features = ["early-data"] }
|
||||
rustls-pemfile = { version = "1.0.0" }
|
||||
rustls = "0.20.6"
|
||||
rand = "0.8.5"
|
||||
toml = "0.5.9"
|
||||
rustc-hash = "1.1.0"
|
||||
serde = { version = "1.0.137", features = ["derive"] }
|
||||
hyper-rustls = { version = "0.23.0", default-features = false, features = [
|
||||
"tokio-runtime",
|
||||
|
|
@ -50,6 +47,7 @@ hyper-rustls = { version = "0.23.0", default-features = false, features = [
|
|||
"http1",
|
||||
"http2",
|
||||
] }
|
||||
parking_lot = "0.12.1"
|
||||
# hyper-trust-dns = { version = "0.4.2", default-features = false, features = [
|
||||
# "rustls-http2",
|
||||
# "dnssec-ring",
|
||||
|
|
@ -59,6 +57,10 @@ hyper-rustls = { version = "0.23.0", default-features = false, features = [
|
|||
# "native-tls",
|
||||
# ] }
|
||||
|
||||
[target.'cfg(not(target_env = "msvc"))'.dependencies]
|
||||
tikv-jemallocator = "0.5.0"
|
||||
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
use crate::log::*;
|
||||
use parking_lot::Mutex;
|
||||
use rand::Rng;
|
||||
use rustc_hash::FxHashMap as HashMap;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fs::File,
|
||||
io::{self, BufReader, Cursor, Read},
|
||||
path::PathBuf,
|
||||
sync::{
|
||||
atomic::{AtomicUsize, Ordering},
|
||||
Arc, Mutex,
|
||||
Arc,
|
||||
},
|
||||
};
|
||||
use tokio_rustls::rustls::{Certificate, PrivateKey, ServerConfig};
|
||||
|
|
@ -88,11 +89,9 @@ impl Upstream {
|
|||
impl Backend {
|
||||
pub fn get_tls_server_config(&self) -> Option<ServerConfig> {
|
||||
let lock = self.server_config.lock();
|
||||
if let Ok(opt) = lock {
|
||||
let opt_clone = opt.clone();
|
||||
if let Some(sc) = opt_clone {
|
||||
return Some(sc);
|
||||
}
|
||||
let opt_clone = lock.clone();
|
||||
if let Some(sc) = opt_clone {
|
||||
return Some(sc);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
|
@ -183,11 +182,8 @@ impl Backend {
|
|||
})?;
|
||||
server_config.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()];
|
||||
|
||||
if let Ok(mut config_store) = self.server_config.lock() {
|
||||
*config_store = Some(server_config);
|
||||
} else {
|
||||
error!("Some thing wrong to write into mutex")
|
||||
}
|
||||
let mut config_store = self.server_config.lock();
|
||||
*config_store = Some(server_config);
|
||||
|
||||
// server_config;
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
use super::toml::{ConfigToml, ReverseProxyOption};
|
||||
use crate::{backend::*, constants::*, error::*, globals::*, log::*};
|
||||
use clap::Arg;
|
||||
use parking_lot::Mutex;
|
||||
use rustc_hash::FxHashMap as HashMap;
|
||||
use std::net::SocketAddr;
|
||||
use std::{collections::HashMap, sync::Mutex};
|
||||
|
||||
// #[cfg(feature = "tls")]
|
||||
use std::path::PathBuf;
|
||||
|
|
@ -147,7 +148,7 @@ pub fn parse_opts(globals: &mut Globals, backends: &mut Backends) -> Result<()>
|
|||
}
|
||||
|
||||
fn get_reverse_proxy(rp_settings: &[ReverseProxyOption]) -> Result<ReverseProxy> {
|
||||
let mut upstream: HashMap<String, Upstream> = HashMap::new();
|
||||
let mut upstream: HashMap<String, Upstream> = HashMap::default();
|
||||
let mut default_upstream: Option<Upstream> = None;
|
||||
rp_settings.iter().for_each(|rpo| {
|
||||
let elem = Upstream {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use crate::error::*;
|
||||
use rustc_hash::FxHashMap as HashMap;
|
||||
use serde::Deserialize;
|
||||
use std::{collections::HashMap, fs};
|
||||
use std::fs;
|
||||
|
||||
#[derive(Deserialize, Debug, Default)]
|
||||
pub struct ConfigToml {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#[cfg(not(target_env = "msvc"))]
|
||||
#[global_allocator]
|
||||
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
|
||||
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
|
||||
|
||||
mod backend;
|
||||
mod config;
|
||||
|
|
@ -21,7 +22,8 @@ use crate::{
|
|||
use futures::future::select_all;
|
||||
use hyper::Client;
|
||||
// use hyper_trust_dns::TrustDnsResolver;
|
||||
use std::{collections::HashMap, io::Write, sync::Arc};
|
||||
use rustc_hash::FxHashMap as HashMap;
|
||||
use std::{io::Write, sync::Arc};
|
||||
use tokio::time::Duration;
|
||||
|
||||
fn main() {
|
||||
|
|
@ -63,7 +65,7 @@ fn main() {
|
|||
|
||||
let mut backends = Backends {
|
||||
default_app: None,
|
||||
apps: HashMap::<String, Backend>::new(),
|
||||
apps: HashMap::<String, Backend>::default(),
|
||||
};
|
||||
|
||||
let _ = parse_opts(&mut globals, &mut backends).expect("Invalid configuration");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue