mirror of
https://github.com/sadoyan/aralez.git
synced 2026-04-30 06:48:37 +08:00
Performance optimization v2
This commit is contained in:
@@ -25,10 +25,10 @@ pub async fn for_consul(url: String, token: Option<String>, conf: &ServiceMappin
|
||||
for subsets in endpoints {
|
||||
// let addr = subsets.tagged_addresses.get("lan_ipv4").unwrap().address.clone();
|
||||
// let prt = subsets.tagged_addresses.get("lan_ipv4").unwrap().port.clone();
|
||||
let addr = subsets.tagged_addresses.get("lan_ipv4").unwrap().address.clone().parse().unwrap();
|
||||
let addr = subsets.tagged_addresses.get("lan_ipv4").unwrap().address.clone();
|
||||
let prt = subsets.tagged_addresses.get("lan_ipv4").unwrap().port.clone();
|
||||
let to_add = Arc::from(InnerMap {
|
||||
address: addr,
|
||||
address: Arc::from(&*addr),
|
||||
port: prt,
|
||||
is_ssl: false,
|
||||
is_http2: false,
|
||||
@@ -61,7 +61,7 @@ pub async fn for_kuber(url: &str, token: &str, conf: &ServiceMapping) -> Option<
|
||||
for addr in addresses {
|
||||
for port in &ports {
|
||||
let to_add = Arc::from(InnerMap {
|
||||
address: addr.ip.parse().unwrap(),
|
||||
address: Arc::from(addr.ip.clone()),
|
||||
port: port.port.clone(),
|
||||
is_ssl: false,
|
||||
is_http2: false,
|
||||
|
||||
@@ -136,7 +136,7 @@ async fn populate_file_upstreams(config: &mut Configuration, parsed: &Config) {
|
||||
if let Some((ip, port_str)) = server.split_once(':') {
|
||||
if let Ok(port) = port_str.parse::<u16>() {
|
||||
server_list.push(Arc::from(InnerMap {
|
||||
address: ip.trim().parse().unwrap(),
|
||||
address: Arc::from(ip),
|
||||
port,
|
||||
is_ssl: true,
|
||||
is_http2: false,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use dashmap::DashMap;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::net::IpAddr;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -10,6 +9,14 @@ pub type UpstreamsDashMap = DashMap<Arc<str>, DashMap<Arc<str>, (Vec<Arc<InnerMa
|
||||
pub type UpstreamsIdMap = DashMap<Arc<str>, Arc<InnerMap>>;
|
||||
pub type Headers = DashMap<Arc<str>, DashMap<Arc<str>, Vec<(Arc<str>, Arc<str>)>>>;
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct Extraparams {
|
||||
pub sticky_sessions: bool,
|
||||
pub to_https: Option<bool>,
|
||||
pub authentication: DashMap<Arc<str>, Vec<Arc<str>>>,
|
||||
pub rate_limit: Option<isize>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
|
||||
pub struct ServiceMapping {
|
||||
pub upstream: String,
|
||||
@@ -21,13 +28,6 @@ pub struct ServiceMapping {
|
||||
pub server_headers: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct Extraparams {
|
||||
pub sticky_sessions: bool,
|
||||
pub to_https: Option<bool>,
|
||||
pub authentication: DashMap<Arc<str>, Vec<Arc<str>>>,
|
||||
pub rate_limit: Option<isize>,
|
||||
}
|
||||
#[derive(Clone, Default, Debug, Serialize, Deserialize)]
|
||||
pub struct Kubernetes {
|
||||
pub servers: Option<Vec<String>>,
|
||||
@@ -114,9 +114,9 @@ pub struct AppConfig {
|
||||
pub rungroup: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct InnerMap {
|
||||
pub address: IpAddr,
|
||||
pub address: Arc<str>,
|
||||
pub port: u16,
|
||||
pub is_ssl: bool,
|
||||
pub is_http2: bool,
|
||||
@@ -129,7 +129,8 @@ pub struct InnerMap {
|
||||
impl InnerMap {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
address: "127.0.0.1".parse().unwrap(),
|
||||
// address: "127.0.0.1".parse().unwrap(),
|
||||
address: Arc::from("127.0.0.1"),
|
||||
port: Default::default(),
|
||||
is_ssl: Default::default(),
|
||||
is_http2: Default::default(),
|
||||
@@ -140,9 +141,18 @@ impl InnerMap {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct UpstreamSnapshot {
|
||||
pub backends: Vec<InnerMap>,
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
pub struct InnerMapForJson {
|
||||
pub address: String,
|
||||
pub port: u16,
|
||||
pub is_ssl: bool,
|
||||
pub is_http2: bool,
|
||||
pub to_https: bool,
|
||||
pub rate_limit: Option<isize>,
|
||||
pub healthcheck: Option<bool>,
|
||||
}
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
pub struct UpstreamSnapshotForJson {
|
||||
pub backends: Vec<InnerMapForJson>,
|
||||
pub requests: usize,
|
||||
}
|
||||
// pub type UpstreamsSnapshot = HashMap<String, HashMap<String, UpstreamSnapshot>>;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::utils::structs::{InnerMap, UpstreamSnapshot, UpstreamsDashMap, UpstreamsIdMap};
|
||||
use crate::utils::structs::{InnerMap, InnerMapForJson, UpstreamSnapshotForJson, UpstreamsDashMap, UpstreamsIdMap};
|
||||
use crate::utils::tls;
|
||||
use crate::utils::tls::CertificateConfig;
|
||||
use dashmap::DashMap;
|
||||
@@ -161,7 +161,7 @@ pub fn clone_idmap_into(original: &UpstreamsDashMap, cloned: &UpstreamsIdMap) {
|
||||
let hex_hash = base16ct::lower::encode_string(&hash);
|
||||
let hh = hex_hash[0..50].to_string();
|
||||
let to_add = InnerMap {
|
||||
address: "127.0.0.1".parse().unwrap(),
|
||||
address: Arc::from("127.0.0.1"),
|
||||
port: 0,
|
||||
is_ssl: false,
|
||||
is_http2: false,
|
||||
@@ -283,8 +283,19 @@ pub fn upstreams_to_json(upstreams: &UpstreamsDashMap) -> serde_json::Result<Str
|
||||
|
||||
inner_map.insert(
|
||||
inner_entry.key().to_string(),
|
||||
UpstreamSnapshot {
|
||||
backends: backends.iter().map(|a| (**a).clone()).collect(),
|
||||
UpstreamSnapshotForJson {
|
||||
backends: backends
|
||||
.iter()
|
||||
.map(|a| InnerMapForJson {
|
||||
address: a.address.to_string(),
|
||||
port: a.port,
|
||||
is_ssl: a.is_ssl,
|
||||
is_http2: a.is_http2,
|
||||
to_https: a.to_https,
|
||||
rate_limit: a.rate_limit,
|
||||
healthcheck: a.healthcheck,
|
||||
})
|
||||
.collect(),
|
||||
requests: counter.load(Ordering::Relaxed),
|
||||
},
|
||||
);
|
||||
@@ -323,7 +334,7 @@ pub fn upstreams_liveness_json(configured: &UpstreamsDashMap, current: &Upstream
|
||||
false
|
||||
};
|
||||
json!({
|
||||
"address": backend.address,
|
||||
"address": &*backend.address,
|
||||
"port": backend.port,
|
||||
"alive": alive
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user