Skip to content
Closed
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
4 changes: 2 additions & 2 deletions frameworks/apex-tuned/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM ubuntu:24.04 AS build
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential gcc make ca-certificates libc6-dev libssl-dev libcjson-dev libbrotli-dev zlib1g-dev libnghttp2-dev pkg-config \
build-essential gcc make ca-certificates libc6-dev libssl-dev libcjson-dev libbrotli-dev libdeflate-dev libisal-dev zlib1g-dev libnghttp2-dev pkg-config \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /app
Expand All @@ -11,7 +11,7 @@ RUN make -j$(nproc)

FROM ubuntu:24.04
RUN apt-get update && apt-get install -y --no-install-recommends \
libcjson1 libbrotli1 zlib1g libssl3 libnghttp2-14 ca-certificates \
libcjson1 libbrotli1 libdeflate0 libisal2 zlib1g libssl3 libnghttp2-14 ca-certificates \
&& rm -rf /var/lib/apt/lists/*

COPY --from=build /app/server /server
Expand Down
2 changes: 1 addition & 1 deletion frameworks/apex-tuned/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ OPT_FLAGS = -O3 -march=native -mtune=native -flto=auto \

CFLAGS ?= $(OPT_FLAGS) $(WARN_FLAGS) -std=gnu2x -MMD -MP
LDFLAGS ?= -flto=auto -Wl,--gc-sections -Wl,-O3 -Wl,--as-needed -Wl,-z,now -Wl,-z,relro -s
LIBS = -lssl -lcrypto -lbrotlienc -lbrotlicommon -lz -lcjson -lpthread -lnghttp2
LIBS = -lssl -lcrypto -lbrotlienc -lbrotlicommon -lisal -ldeflate -lz -lcjson -lpthread -lnghttp2

SRCS = src/main.c \
src/buffer_pool.c \
Expand Down
2 changes: 1 addition & 1 deletion frameworks/apex-tuned/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ High-performance HTTP/1.1 framework in C23 designed for many-core NUMA architect

## Architecture

- **Runtime**: Thread-per-core shared-nothing event loop using Linux `epoll`. Workers pin to dedicated CPUs via `pthread_setaffinity_np` with per-worker `SO_REUSEPORT` listeners on ports 8080 and 8081.
- **Runtime**: Thread-per-core shared-nothing event loop using Linux `epoll` with per-worker `SO_REUSEPORT` listeners. Workers use kernel scheduling by default for co-located loads; `APEX_PIN_CPUS=1` enables dedicated CPU pinning.
- **Memory**: Slab-allocated connection contexts and pre-sized I/O rings. Zero dynamic allocations in the request-response path.
- **Parser**: Streaming state-machine HTTP/1.1 parser resilient to byte-level TCP fragmentation, supporting pipelining, chunked transfer decoding, and lower-cased header variants.
- **Routing & Middleware**: Trie router with route parameter extraction (`:ms`, `:count`) and query string slicing; middleware chain for compression negotiation.
Expand Down
14 changes: 14 additions & 0 deletions frameworks/apex-tuned/src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,20 @@ static inline bool parse_ascii_digits_fast(const char *digits, size_t length, ui

static inline bool sum_two_ascii_digits_fast(const char *first_digits, const char *second_digits, size_t length,
uint64_t *out_sum) {
if (__builtin_expect(length == 2, 1)) {
unsigned int first_high = (unsigned int)(unsigned char)first_digits[0] - (unsigned int)'0';
unsigned int first_low = (unsigned int)(unsigned char)first_digits[1] - (unsigned int)'0';
unsigned int second_high = (unsigned int)(unsigned char)second_digits[0] - (unsigned int)'0';
unsigned int second_low = (unsigned int)(unsigned char)second_digits[1] - (unsigned int)'0';
*out_sum = (uint64_t)(first_high * 10 + first_low + second_high * 10 + second_low);
return ((first_high > 9) | (first_low > 9) | (second_high > 9) | (second_low > 9)) == 0;
}
if (__builtin_expect(length == 1, 0)) {
unsigned int first_digit = (unsigned int)(unsigned char)first_digits[0] - (unsigned int)'0';
unsigned int second_digit = (unsigned int)(unsigned char)second_digits[0] - (unsigned int)'0';
*out_sum = (uint64_t)(first_digit + second_digit);
return ((first_digit > 9) | (second_digit > 9)) == 0;
}
#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
if (__builtin_expect(length == 7, 1)) {
uint64_t first_bytes = 0;
Expand Down
12 changes: 3 additions & 9 deletions frameworks/apex-tuned/src/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,8 @@ void conn_list_remove(worker_t *worker, conn_t *connection) {
}

void conn_touch(worker_t *worker, conn_t *connection, uint64_t current_time_ms) {
(void)worker;
connection->last_active_ms = current_time_ms;
if (connection == worker->active_tail) {
return;
}
conn_list_remove(worker, connection);
conn_list_insert_tail(worker, connection);
}

conn_t *alloc_conn(worker_t *worker, int client_fd, bool is_tls, SSL *ssl_session) {
Expand Down Expand Up @@ -224,11 +220,9 @@ void trim_inactive_connections(worker_t *worker, uint64_t current_time_ms) {
continue;
}

if (current_time_ms - curr->last_active_ms < IDLE_TIMEOUT_MS) {
break;
if (current_time_ms - curr->last_active_ms >= IDLE_TIMEOUT_MS) {
close_conn(worker, curr);
}

close_conn(worker, curr);
curr = next;
}

Expand Down
Loading