This project uses a multithreaded server with an epoll instance to handle multiple connections, each on an individual thread. The goal was to apply modern Linux socket programming techniques, similar to those of real-world large scale applications.
Older methods, such as poll and select, are not scale-able as they perform operations with a linear time complexity. Epoll utilized an RB-Tree (Red Black Tree) under the hood to keep track of the file descriptors.
The Client takes (5) arguments which override the default values.
./Client -i [IP Address] -p [Port Number] -b [Buffer Size] -t [TCP/UDP] -m [Benchmark]
IP Address: Standard IPv4 Address
Port Number: Valid Port Number 0 - 65535
Buffer Size: uint32_t;
TCP/UDP: Char T or U;
Benchmark: bool;
The Multithreaded-Server takes (5) arguments and can be passed to the executable with the following flags.
./Multithreaded-Server -p [Port Number] -c [Max Clients] -e [Max Events] -b [Buffer Size] -t [TCP/UDP]
Port Number: Valid Port Number 0 - 65535
Max Clients, Max Events, Buffer Size: uint32_t;
TCP/UDP: Char T or U;
The server should be initialized prior to the client, otherwise the client will fail to connect since there is no server online. The resulting client / server program is shown below.
These benchmarks were taken on a (4) core Intel(R) Core(TM) i5-9300H CPU @ 2.40GHz with isolcpus on cores 2 and 3. The linux kernel is v6.10.11-200.fc40.x86_64 and compiled with gcc version 14.2.1.
Message Type | messages / sec | latency (ms) |
---|---|---|
UDP | 71,318 | 14 |
TCP | 58,539 | 17 |
The following is a diagram of the OSI (Open System Interconnection) model. The TCP and UDP is located on the 4th layer (Transport).
Source: https://vichargrave.github.io/programming/tcp-ip-network-programming-design-patterns-in-cpp/
The diagram below demonstrates the order of operations to initialize a standard server / client TCP application.
Source: https://vichargrave.github.io/programming/tcp-ip-network-programming-design-patterns-in-cpp/
The epoll instance is apart of the Linux kernel. Once there are file descriptors in the ready list, epoll_wait returns the number of FD's that are ready.
Source: https://medium.com/@avocadi/what-is-epoll-9bbc74272f7c
This repository contains a .devcontainer directory. The .devcontainer has all the required dependencies and can be run inside Docker with the Dev Containers VSCode extension.
- Google Tests | Testing Only
$ cd server && mkdir build
$ cmake -S . -B build
$ cmake --build build --target Multithreaded-Server
$ cd client && mkdir build
$ cmake -S . -B build
$ cmake --build build --target Client
This software is distributed under the GNU license. Please read LICENSE for information on the software availability and distribution.