The Asynchronous Web Server (AWS) is a high-performance Linux-based web server designed to serve files efficiently by leveraging advanced I/O paradigms. The primary goal of this project is to minimize CPU overhead and memory latency through asynchronous operations and zero-copy data transfer.
- I/O Multiplexing: Utilizes the
epollAPI for high-scale, event-driven management of multiple simultaneous client connections. - Zero-Copying: Implements
sendfilefor static content, bypassing user-space data buffering to accelerate throughput. - Asynchronous File I/O: Employs Linux AIO (
io_setup,io_submit) for dynamic file processing, ensuring the server remains responsive during heavy disk operations. - Non-blocking Sockets: All network operations are performed on non-blocking sockets to prevent thread starvation and maximize scalability.
- Connection State Machine: Each client session is governed by a dedicated state machine to track the lifecycle of HTTP requests and responses.
The server categorizes content based on its location within the AWS_DOCUMENT_ROOT directory:
- Static Files (
/static/):
- Designed for assets that require no post-processing.
- Mechanism: Handled via
sendfile(Zero-copy) for maximum efficiency.
- Dynamic Files (
/dynamic/):
- Designed for files that theoretically require server-side processing.
- Mechanism: Read from disk using the Asynchronous API (AIO) and pushed to clients via non-blocking sockets.
- Implements a functional subset of the HTTP/1.1 protocol.
- Response Codes:
200 OKfor successful retrievals and404 Not Foundfor invalid paths. - Parsing: Utilizes a callback-based
http-parserto extract resource paths and headers efficiently.
.
├── aws.c # Core server implementation (epoll loop, connection logic)
├── aws.h # Macros, data structures, and configuration (port, root dir)
├── http-parser/ # External HTTP parsing library
├── tests/ # Automated testing suite
└── Makefile # Build instructions
- A Linux-based environment (Kernel support for
epollandeventfdis required). gcccompiler andmakeutility.
Build the executable by running the following command in the root directory:
make
The testing suite validates server functionality, API usage (sendfile, epoll, io_submit), and monitors for memory leaks.
cd tests/
make check
To execute a specific test case (e.g., Test 31):
./_test/run_test.sh 31
To manage asynchronous events, each connection structure maintains a state:
STATE_RECEIVING: Reading and parsing the incoming HTTP request.STATE_SENDING_HEADER: Constructing and transmitting the HTTP response header.STATE_SENDING_DATA: Streaming the file content (viasendfileorAIO).STATE_CLOSING: Releasing resources and terminating the socket connection.
- Multiplexing:
epoll_create,epoll_ctl,epoll_wait. - Zero-Copy:
sendfile. - Async I/O:
io_setup,io_submit,io_getevents,eventfd.
By combining event-driven multiplexing with asynchronous disk access, this server mitigates the "C10k problem." It minimizes context switching and memory copies, making it significantly more efficient than traditional thread-per-connection models.
Developed by: Daria-Ioana Drăghici]
Project: Operating Systems - Advanced Asynchronous Web Server Implementation