diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c97483941..0d8d4ff2f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,6 +29,10 @@ concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true +env: + CARGO_TERM_COLOR: always + RUSTFLAGS: "-C target-feature=+aes,+vaes,+avx2" + jobs: lint: name: Lint diff --git a/Cargo.lock b/Cargo.lock index 86fef956d..8226b6a71 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -935,6 +935,15 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +[[package]] +name = "gxhash" +version = "3.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a197c9b654827513cf53842c5c6d3da2b4b35a785f8e0eff78bdf8e445aba1bb" +dependencies = [ + "rustversion", +] + [[package]] name = "h2" version = "0.3.26" @@ -2341,6 +2350,7 @@ dependencies = [ "fixedstr", "form_urlencoded", "futures", + "gxhash", "hickory-resolver", "http-body-util", "hyper 1.4.1", diff --git a/Cargo.toml b/Cargo.toml index 8f2fd94cf..c3b0b3503 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -149,6 +149,7 @@ strum_macros = "0.26" cfg-if = "1.0.0" libflate = "2.0.0" form_urlencoded = "1.2.1" +gxhash = "3.4.1" [dependencies.hyper-util] version = "0.1" @@ -236,4 +237,4 @@ schemars = { version = "0.8.15", features = ["bytes", "url"] } url = { version = "2.4.1", features = ["serde"] } [workspace.lints.clippy] -undocumented_unsafe_blocks = "deny" \ No newline at end of file +undocumented_unsafe_blocks = "deny" diff --git a/build/build-image/Dockerfile b/build/build-image/Dockerfile index 492fb869e..5f00d6e09 100644 --- a/build/build-image/Dockerfile +++ b/build/build-image/Dockerfile @@ -19,6 +19,8 @@ ARG RUST_TOOLCHAIN ENV RUSTUP_HOME=/usr/local/rustup \ CARGO_HOME=/usr/local/cargo \ PATH=/usr/local/cargo/bin:$PATH \ + CARGO_TERM_COLOR=always \ + RUSTFLAGS="-C target-feature=+aes,+vaes,+avx2" \ LC_ALL=C.UTF-8 \ LANG=C.UTF-8 diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 0110689b2..8fa2fa28a 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -103,6 +103,8 @@ options: - "CARGO_HOME=/workspace/.cargo" - "REPOSITORY=${_REPOSITORY}" - "BUILD_IMAGE_TAG=${_BUILD_IMAGE_TAG}" + - "CARGO_TERM_COLOR=always" + - 'RUSTFLAGS="-C target-feature=+aes,+vaes,+avx2"' machineType: E2_HIGHCPU_32 dynamic_substitutions: true timeout: 7200s diff --git a/src/components/proxy/error.rs b/src/components/proxy/error.rs index ee59eccc4..247850eaa 100644 --- a/src/components/proxy/error.rs +++ b/src/components/proxy/error.rs @@ -105,17 +105,7 @@ impl Hash for PipelineError { } } -pub struct SeahashBuilder; - -impl std::hash::BuildHasher for SeahashBuilder { - type Hasher = seahash::SeaHasher; - - fn build_hasher(&self) -> Self::Hasher { - seahash::SeaHasher::new() - } -} - -pub type ErrorMap = std::collections::HashMap; +pub type ErrorMap = gxhash::HashMap; pub type ErrorSender = tokio::sync::mpsc::Sender; //pub type ErrorReceiver = tokio::sync::mpsc::Receiver; @@ -140,7 +130,7 @@ pub struct ErrorAccumulator { impl ErrorAccumulator { pub fn new(tx: ErrorSender) -> Self { Self { - map: ErrorMap::with_hasher(SeahashBuilder), + map: <_>::default(), tx, oldest: Instant::now(), } @@ -160,7 +150,7 @@ impl ErrorAccumulator { }; #[allow(clippy::mutable_key_type)] - let map = std::mem::replace(&mut self.map, ErrorMap::with_hasher(SeahashBuilder)); + let map = std::mem::take(&mut self.map); permit.send(map); true } diff --git a/src/components/proxy/packet_router.rs b/src/components/proxy/packet_router.rs index 21be559f5..4408017a0 100644 --- a/src/components/proxy/packet_router.rs +++ b/src/components/proxy/packet_router.rs @@ -169,7 +169,7 @@ pub async fn spawn_receivers( let mut log_task = tokio::time::interval(std::time::Duration::from_secs(5)); #[allow(clippy::mutable_key_type)] - let mut pipeline_errors = super::error::ErrorMap::with_hasher(super::error::SeahashBuilder); + let mut pipeline_errors = super::error::ErrorMap::default(); #[allow(clippy::mutable_key_type)] fn report(errors: &mut super::error::ErrorMap) { diff --git a/src/config.rs b/src/config.rs index 38785f966..7064792c8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -234,7 +234,7 @@ impl Config { crate::net::cluster::proto::FilterChain::try_from(&*self.filters.load())?, ); let any = resource.try_encode()?; - let version = seahash::hash(&any.value); + let version = gxhash::gxhash64(&any.value, 0xdeadbeef); let vstr = version.to_string(); diff --git a/src/filters/read.rs b/src/filters/read.rs index d48882914..ca412289d 100644 --- a/src/filters/read.rs +++ b/src/filters/read.rs @@ -50,7 +50,7 @@ impl ReadContext { destinations: Vec::new(), source, contents, - metadata: DynamicMetadata::new(), + metadata: <_>::default(), } } } diff --git a/src/filters/write.rs b/src/filters/write.rs index dee9ee181..fd01010ec 100644 --- a/src/filters/write.rs +++ b/src/filters/write.rs @@ -14,8 +14,6 @@ * limitations under the License. */ -use std::collections::HashMap; - use crate::{ net::endpoint::{DynamicMetadata, EndpointAddress}, pool::PoolBuffer, @@ -45,7 +43,7 @@ impl WriteContext { source, dest, contents, - metadata: HashMap::new(), + metadata: <_>::default(), } } } diff --git a/src/net/cluster.rs b/src/net/cluster.rs index c237fbfa3..9cc3bfbc3 100644 --- a/src/net/cluster.rs +++ b/src/net/cluster.rs @@ -15,7 +15,7 @@ */ use std::{ - collections::{hash_map::RandomState, BTreeSet}, + collections::BTreeSet, fmt, sync::atomic::{AtomicU64, AtomicUsize, Ordering::Relaxed}, }; @@ -27,6 +27,7 @@ use serde::{Deserialize, Serialize}; use crate::net::endpoint::{Endpoint, EndpointAddress, Locality}; const SUBSYSTEM: &str = "cluster"; +const HASH_SEED: i64 = 0xdeadbeef; pub use crate::generated::quilkin::config::v1alpha1 as proto; @@ -60,7 +61,7 @@ pub(crate) fn active_endpoints() -> &'static prometheus::IntGauge { &ACTIVE_ENDPOINTS } -pub type TokenAddressMap = std::collections::BTreeMap>; +pub type TokenAddressMap = gxhash::HashMap>; #[derive(Copy, Clone)] pub struct Token(u64); @@ -68,7 +69,7 @@ pub struct Token(u64); impl Token { #[inline] pub fn new(token: &[u8]) -> Self { - Self(seahash::hash(token)) + Self(gxhash::gxhash64(token, HASH_SEED)) } } @@ -123,7 +124,7 @@ impl EndpointSet { pub fn new(endpoints: BTreeSet) -> Self { let mut this = Self { endpoints, - token_map: TokenAddressMap::new(), + token_map: <_>::default(), hash: 0, version: 0, }; @@ -141,7 +142,7 @@ impl EndpointSet { pub fn with_version(endpoints: BTreeSet, hash: EndpointSetVersion) -> Self { let mut this = Self { endpoints, - token_map: TokenAddressMap::new(), + token_map: <_>::default(), hash: hash.number(), version: 1, }; @@ -177,14 +178,14 @@ impl EndpointSet { #[inline] pub fn update(&mut self) -> TokenAddressMap { use std::hash::{Hash, Hasher}; - let mut hasher = seahash::SeaHasher::with_seeds(0, 1, 2, 3); - let mut token_map = TokenAddressMap::new(); + let mut hasher = gxhash::GxHasher::with_seed(HASH_SEED); + let mut token_map = TokenAddressMap::default(); for ep in &self.endpoints { ep.hash(&mut hasher); for tok in &ep.metadata.known.tokens { - let hash = seahash::hash(tok); + let hash = gxhash::gxhash64(tok, HASH_SEED); token_map .entry(hash) .or_default() @@ -200,12 +201,12 @@ impl EndpointSet { /// Creates a map of tokens -> address for the current set #[inline] pub fn build_token_map(&mut self) -> TokenAddressMap { - let mut token_map = TokenAddressMap::new(); + let mut token_map = TokenAddressMap::default(); // This is only called on proxies, so calculate a token map for ep in &self.endpoints { for tok in &ep.metadata.known.tokens { - let hash = seahash::hash(tok); + let hash = gxhash::gxhash64(tok, HASH_SEED); token_map .entry(hash) .or_default() @@ -257,7 +258,7 @@ impl EndpointSet { } /// Represents a full snapshot of all clusters. -pub struct ClusterMap { +pub struct ClusterMap { map: DashMap, EndpointSet, S>, token_map: DashMap>, num_endpoints: AtomicUsize, @@ -268,7 +269,7 @@ type DashMapRef<'inner, S> = dashmap::mapref::one::Ref<'inner, Option, type DashMapRefMut<'inner, S> = dashmap::mapref::one::RefMut<'inner, Option, EndpointSet, S>; -impl ClusterMap { +impl ClusterMap { pub fn new() -> Self { Self::default() } diff --git a/src/net/endpoint/metadata.rs b/src/net/endpoint/metadata.rs index dce49e904..c5f4da0b4 100644 --- a/src/net/endpoint/metadata.rs +++ b/src/net/endpoint/metadata.rs @@ -21,12 +21,10 @@ pub mod build { pub const GIT_COMMIT_HASH: Option<&str> = option_env!("GIT_COMMIT_HASH"); } -use std::{collections::HashMap, convert::TryFrom}; - pub use symbol::{Key, Reference, Symbol}; /// Shared state between [`Filter`][crate::filters::Filter]s during processing for a single packet. -pub type DynamicMetadata = HashMap; +pub type DynamicMetadata = gxhash::HashMap; pub const KEY: &str = "quilkin.dev";