Enterprise-grade HTTP server with zero-copy transfers, intelligent caching, and industry-leading DDoS protection
Built for mission-critical applications where reliability, security, and performance are non-negotiable
Master-worker design with 4 workers ensures optimal CPU utilization and automatic process recovery for maximum reliability.
Files served directly from kernel to network without expensive buffer copying, dramatically reducing CPU usage and latency.
Intelligent rate limiting that automatically adjusts based on server load, with per-IP connection limits and automatic banning.
LRU file caching system with configurable memory limits stores frequently accessed files for near-instant response times.
Dedicated watchdog thread monitors worker processes and automatically recovers from hangs, deadlocks, or other failures.
High-performance event notification system handles up to 50,000 simultaneous connections with minimal resource usage.
Multi-process design with self-healing capabilities ensures continuous operation even under extreme conditions
ProTech implements a sophisticated master-worker architecture where a supervisor process manages multiple worker processes. Each worker handles connections independently, providing both improved performance and fault tolerance:
// Process management with automatic restart
void handle_master_signal(int sig) {
if (sig == SIGCHLD) {
// A worker died, determine which one
pid_t pid;
while ((pid = waitpid(-1, NULL, WNOHANG)) > 0) {
for (int i = 0; i < WORKER_PROCESSES; i++) {
if (worker_pids[i] == pid) {
syslog(LOG_WARNING, "Worker %d died, restarting", i);
workers_running--;
// Restart the worker
pid_t new_pid = fork();
if (new_pid == 0) {
// Child process
run_worker(i);
exit(0);
} else {
// Parent process
worker_pids[i] = new_pid;
workers_running++;
}
break;
}
}
}
}
}
Each worker process has a dedicated watchdog thread that monitors the main event loop for responsiveness. If a worker hangs for more than 30 seconds, the watchdog automatically recovers the process:
// Watchdog thread implementation
void *watchdog_thread_func(void *arg) {
while (running) {
// Increment watchdog timer
watchdog_timer++;
sleep(1);
// Check if main thread is responsive
if (watchdog_timer > 30) {
syslog(LOG_CRIT, "Watchdog timeout - worker not responding!");
// Kill and restart worker
if (USE_WATCHDOG) {
longjmp(watchdog_jmp, 1);
}
}
}
return NULL;
}
// Worker process uses setjmp to create recovery point
if (USE_WATCHDOG) {
if (setjmp(watchdog_jmp) != 0) {
syslog(LOG_ERR, "Worker %d recovered from watchdog timeout", worker_id);
}
pthread_create(&watchdog_thread, NULL, watchdog_thread_func, NULL);
}
The intelligent file caching system dramatically improves performance by keeping frequently accessed files in memory, eliminating disk I/O for common requests:
// File cache structure
typedef struct cache_entry {
char *path; // File path
char *data; // File content
size_t size; // File size
time_t last_modified; // Last modified time
time_t last_accessed; // Last accessed time
uint32_t hash; // Path hash
struct cache_entry *next; // Next entry in hash bucket
} cache_entry;
// Intelligent caching with hit rate tracking
cache_entry* cache_get_file(const char *path) {
pthread_mutex_lock(&cache_lock);
uint32_t hash = hash_path(path);
cache_entry *entry = file_cache[hash];
while (entry) {
if (strcmp(entry->path, path) == 0) {
entry->last_accessed = time(NULL);
pthread_mutex_unlock(&cache_lock);
cache_hits++;
return entry;
}
entry = entry->next;
}
pthread_mutex_unlock(&cache_lock);
return NULL;
}
Cutting-edge techniques that maximize throughput while minimizing resource usage
ProTech implements true zero-copy data transfers using Linux's sendfile() syscall, eliminating expensive user-space buffer copying:
// Zero-copy file transfer using sendfile()
void continue_sending_file(connection *conn) {
off_t offset = conn->file_offset;
ssize_t sent = sendfile(conn->fd, conn->file_fd, &offset,
conn->file_size - conn->file_offset);
if (sent > 0) {
conn->file_offset = offset;
conn->last_active = time(NULL);
stats_add_bytes(sent);
}
if (sent < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
// Would block, try again later
return;
}
if (sent <= 0 || conn->file_offset >= conn->file_size) {
// Done or error
close(conn->file_fd);
conn->file_fd = -1;
if (conn->keep_alive) {
// Reset for next request
conn->bytes_read = 0;
update_epoll(conn->fd, EPOLLIN);
} else {
close_connection(conn->fd);
}
}
}
ProTech uses Linux's epoll API for high-performance event notification, enabling it to efficiently handle tens of thousands of connections with minimal overhead:
// Epoll event-driven I/O
int setup_epoll() {
int epfd = epoll_create1(0);
if (epfd == -1) {
perror("epoll_create1 failed");
exit(EXIT_FAILURE);
}
return epfd;
}
// Main event loop
while (running) {
// Wait for events with timeout
int nfds = epoll_wait(epoll_fd, events, MAX_EVENTS, 1000);
for (int i = 0; i < nfds; i++) {
int fd = events[i].data.fd;
if (fd == server_fd) {
// New connection
handle_new_connection(server_fd);
}
else if (events[i].events & EPOLLIN) {
// Socket readable
handle_client_data(fd_to_conn[fd]);
}
else if (events[i].events & EPOLLOUT) {
// Socket writable
continue_sending_file(fd_to_conn[fd]);
}
}
}
ProTech implements advanced TCP socket optimizations to maximize throughput and connection handling capacity:
// TCP socket optimizations
int setup_server() {
int server_fd;
struct sockaddr_in address;
int opt = 1;
// Create socket
server_fd = socket(AF_INET, SOCK_STREAM, 0);
// Set socket options
setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
setsockopt(server_fd, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof(opt));
setsockopt(server_fd, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt));
// Enable TCP FastOpen
int qlen = 5;
setsockopt(server_fd, IPPROTO_TCP, 23, &qlen, sizeof(qlen));
// Set buffer sizes
int rcvbuf = 262144; // 256K
setsockopt(server_fd, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(rcvbuf));
int sndbuf = 262144; // 256K
setsockopt(server_fd, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof(sndbuf));
// Set non-blocking mode
set_nonblocking(server_fd);
return server_fd;
}
ProTech implements advanced memory management techniques to maximize performance and stability:
// Memory optimization
// Set resource limits
struct rlimit limit;
limit.rlim_cur = MAX_CONN * 2;
limit.rlim_max = MAX_CONN * 2;
setrlimit(RLIMIT_NOFILE, &limit);
// Lock memory to prevent swapping
mlockall(MCL_CURRENT | MCL_FUTURE);
// Dynamic buffer resizing
if (space_left < 1024) {
size_t new_size = conn->buffer_size * 2;
char *new_buffer = realloc(conn->buffer, new_size);
if (new_buffer) {
conn->buffer = new_buffer;
conn->buffer_size = new_size;
}
}
Multi-layered, self-tuning defense system responds automatically to evolving threat conditions
ProTech's enhanced DDoS protection features intelligent rate limiting that automatically adjusts based on server load and attack patterns:
// Adaptive rate limiting based on server load
int check_ip(uint32_t ip) {
time_t now = time(NULL);
int allowed = 1;
pthread_mutex_lock(&ip_table_lock);
ip_entry *entry = get_ip_entry(ip);
// Reset counter if time window passed
if ((now - entry->first_request) > TIME_WINDOW) {
entry->count = 0;
entry->first_request = now;
}
// Adaptive rate limiting
int rate_limit = RATE_LIMIT;
if (ADAPTIVE_RATE) {
// Get current system load
double load[1];
getloadavg(load, 1);
// Adjust rate limit based on load
if (load[0] > 10.0) {
rate_limit = RATE_LIMIT / 4;
} else if (load[0] > 5.0) {
rate_limit = RATE_LIMIT / 2;
} else if (load[0] > 2.0) {
rate_limit = (RATE_LIMIT * 3) / 4;
}
}
// Apply rate limiting
entry->count++;
if (entry->count > rate_limit) {
entry->ban_expiry = now + BAN_DURATION;
allowed = 0;
ddos_mitigations_triggered++;
}
pthread_mutex_unlock(&ip_table_lock);
return allowed;
}
ProTech implements sophisticated protection against connection flooding attacks that attempt to exhaust server resources:
// Check for too many simultaneous connections
if (entry->in_use && entry->active_conns >= MAX_CONN_PER_IP) {
pthread_mutex_unlock(&ip_table_lock);
return 0; // Too many connections from this IP
}
// Track active connections for this IP
entry->active_conns++;
// Decrement on connection close
void decrement_ip_connections(uint32_t ip) {
pthread_mutex_lock(&ip_table_lock);
ip_entry *entry = get_ip_entry(ip);
if (entry && entry->in_use && entry->active_conns > 0) {
entry->active_conns--;
}
pthread_mutex_unlock(&ip_table_lock);
}
ProTech uses an optimized IP tracking system with O(1) lookup performance for both IPv4 and IPv6 addresses:
// IP tracking hash table
typedef struct {
uint32_t ip; // IP address in network byte order
uint16_t count; // Request count
time_t first_request; // First request timestamp
time_t ban_expiry; // Ban expiry timestamp (0 if not banned)
uint8_t in_use; // 1 if entry is in use
uint16_t active_conns; // Active connections from this IP
} ip_entry;
// Hash function for IPs (FNV-1a)
uint32_t hash_ip(uint32_t ip) {
return (ip * 2654435761) & HASH_MASK;
}
ProTech includes comprehensive attack monitoring and analytics to help identify and mitigate threats:
// From the health check response
"ddos_mitigations": %llu,
"requests": {
"total": %llu,
"dropped": %llu,
"blocked": %llu
},
// Time-series data for requests and blocks
typedef struct {
uint64_t total_requests; // Total incoming requests
uint64_t blocked_requests; // Requests blocked by rate limiting
// Time-series data (last 24 hours, 5-minute intervals)
#define STATS_INTERVALS 288 // 24 hours * 12 intervals per hour
uint32_t requests_by_interval[STATS_INTERVALS];
uint32_t blocked_by_interval[STATS_INTERVALS];
} server_stats;
ProTech delivers exceptional throughput, minimal latency, and efficient resource usage
Comprehensive health checks and performance metrics for proactive management
ProTech includes a comprehensive monitoring system with real-time metrics and insights:
/health
/stats.html
All metrics are available as JSON for easy integration with monitoring dashboards and alerting systems.
The health check endpoint returns comprehensive metrics in an easy-to-parse JSON format:
{
"status": "up",
"uptime": 345678,
"connections": {
"active": 128,
"max_seen": 3752,
"total_handled": 1547823
},
"requests": {
"total": 4982517,
"dropped": 1242,
"blocked": 23518
},
"system": {
"load_1m": 0.42,
"load_5m": 0.38,
"load_15m": 0.35
},
"cache": {
"size_mb": 186.45,
"hit_rate": 97.8,
"items": 2453
},
"ddos_mitigations": 17842
}
The detailed statistics endpoint provides time-series data for deeper analysis:
// Generate detailed statistics in JSON format
char* generate_stats_json() {
pthread_mutex_lock(&stats_mutex);
// Build JSON with time-series data
char* json = malloc(64 * 1024); // 64KB buffer
char* ptr = json;
// Add interval data for time-series analysis
ptr += sprintf(ptr, "\"interval_data\": [\n");
for (int i = 0; i < STATS_INTERVALS; i++) {
ptr += sprintf(ptr,
" {\n"
" \"timestamp\": %ld,\n"
" \"requests\": %u,\n"
" \"blocked\": %u\n"
" }",
interval_time,
stats.requests_by_interval[idx],
stats.blocked_by_interval[idx]
);
}
pthread_mutex_unlock(&stats_mutex);
return json;
}
ProTech's monitoring endpoints are designed for easy integration with popular monitoring tools:
The standardized JSON format makes it simple to integrate with any monitoring or observability platform.