Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,603 changes: 3,603 additions & 0 deletions frameworks/trillium-tuned/Cargo.lock

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions frameworks/trillium-tuned/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[package]
name = "httparena-trillium-tuned"
version = "0.1.0"
edition = "2024"

[dependencies]
trillium = "1.1"
trillium-tokio = "0.6"
trillium-router = "0.5"
trillium-rustls = "0.11"
trillium-quinn = "0.1"
trillium-websockets = "0.8"
trillium-compression = "0.2"
trillium-logger = "0.4"

swansong = "0.3.4"
futures-lite = "2"
serde = { version = "1", features = ["derive"] }
sonic-rs = "0.5"
querystrong = "0.4"

deadpool-postgres = "0.14"
tokio-postgres = { version = "0.7", features = ["with-serde_json-1"] }
serde_json = "1"

dashmap = "6"
log = "0.4"
env_logger = "0.11"
mimalloc = { version = "0.1", default-features = false }
socket2 = { version = "0.5", features = ["all"] }
num_cpus = "1"
signal-hook = "0.3"

[profile.release]
opt-level = 3
codegen-units = 1
lto = "fat"
panic = "abort"
strip = true
13 changes: 13 additions & 0 deletions frameworks/trillium-tuned/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM rust:1.94-bookworm AS build
WORKDIR /app
COPY Cargo.toml .
RUN mkdir src && echo "fn main() {}" > src/main.rs && \
cargo build --release && \
rm -rf src/ target/release/httparena-trillium-tuned* target/release/deps/httparena_trillium_tuned*
COPY src ./src
RUN RUSTFLAGS="-C target-cpu=native" cargo build --release

FROM debian:bookworm-slim
COPY --from=build /app/target/release/httparena-trillium-tuned /server
EXPOSE 8080 8081 8443/tcp 8443/udp
CMD ["/server"]
30 changes: 30 additions & 0 deletions frameworks/trillium-tuned/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"display_name": "trillium",
"language": "Rust",
"type": "tuned",
"engine": "trillium-http",
"description": "Trillium 1.x with one current_thread tokio runtime per CPU, SO_REUSEPORT TCP sharding (single QUIC endpoint for h3), tuned HttpConfig (larger response/body buffers, 64K h2 frames, eager body preallocation), and static files preloaded into memory at startup. sonic-rs for JSON, deadpool-postgres, mimalloc.",
"repo": "https://github.com/trillium-rs/trillium",
"enabled": true,
"tests": [
"baseline",
"pipelined",
"limited-conn",
"json",
"json-comp",
"json-tls",
"upload",
"static",
"async-db",
"crud",
"api-4",
"api-16",
"baseline-h2",
"static-h2",
"baseline-h3",
"static-h3",
"echo-ws",
"echo-ws-pipeline"
],
"maintainers": ["jbr"]
}
13 changes: 13 additions & 0 deletions frameworks/trillium-tuned/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
comment_width = 100
format_code_in_doc_comments = true
format_macro_matchers = true
format_strings = true
group_imports = "One"
imports_granularity = "Crate"
normalize_comments = true
reorder_impl_items = true
unstable_features = true
use_field_init_shorthand = true
wrap_comments = true
style_edition = "2024"
edition = "2024"
44 changes: 44 additions & 0 deletions frameworks/trillium-tuned/src/handlers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//! HTTP endpoint handlers, split by section:
//!
//! - [`h1`] — `/pipeline`, `/baseline11`, `/baseline2`, `/json/:count`, `/upload`
//! - [`db`] — `/async-db`
//! - [`crud`] — `/crud/items` and `/crud/items/:id`
//! - [`ws`] — `/ws` echo

mod crud;
mod db;
mod h1;
mod ws;

pub use crud::{crud_create, crud_list, crud_read, crud_update};
pub use db::async_db;
pub use h1::{baseline_any, baseline_get, json_handler, pipeline, upload};
use querystrong::QueryStrong;
use trillium::{Conn, KnownHeaderName, Status};
pub use ws::ws_echo;

const TEXT_PLAIN: &str = "text/plain";
const APPLICATION_JSON: &str = "application/json";

fn sum_query_values(q: &str) -> i64 {
QueryStrong::parse(q)
.as_map()
.into_iter()
.flat_map(|m| m.values())
.filter_map(|v| v.as_str().and_then(|s| s.parse::<i64>().ok()))
.sum()
}

fn plain_text<S: Into<String>>(conn: Conn, body: S) -> Conn {
conn.with_status(Status::Ok)
.with_response_header(KnownHeaderName::ContentType, TEXT_PLAIN)
.with_body(body.into())
.halt()
}

fn json_response(conn: Conn, body: Vec<u8>) -> Conn {
conn.with_status(Status::Ok)
.with_response_header(KnownHeaderName::ContentType, APPLICATION_JSON)
.with_body(body)
.halt()
}
Loading