This framework provides tools for testing and comparing the performance of different network protocols: HTTP/1.1, HTTP/2, and BitTorrent. It includes client and server implementations for all three protocols, designed to measure throughput, latency, and protocol overhead across different file sizes.
- Requirements
- Installation
- Directory Structure
- HTTP/1.1 Implementation
- HTTP/2 Implementation
- BitTorrent Implementation
- Running Comprehensive Tests
- Understanding Results
- Troubleshooting
- Python 3.6+
- Flask (
pip install flask) - Requests (
pip install requests) - Werkzeug (
pip install werkzeug) - Statistics module (part of Python standard library)
- Python 3.6+
- h2 (
pip install h2) - socket (part of Python standard library)
- Statistics module (part of Python standard library)
- psutil (
pip install psutil)
- Python 3.6+
- libtorrent (
pip install python-libtorrentor platform-specific installation) - Statistics module (part of Python standard library)
- argparse (part of Python standard library)
- Clone or download this repository
- Install the required dependencies:
# Common requirements
pip install statistics
# For HTTP/1.1 implementation
pip install flask requests werkzeug
# For HTTP/2 implementation
pip install h2 psutil
# For BitTorrent implementation
# Note: libtorrent installation can be platform-specific
# On Ubuntu/Debian:
sudo apt-get install python3-libtorrent
# On macOS (with Homebrew):
brew install libtorrent-rasterbar
pip install python-libtorrent
# On Windows:
# Download appropriate binaries or use Anaconda:
conda install -c conda-forge libtorrentCreate the following directory structure:
network-testing/
├── http1/
│ ├── http1_server.py
│ ├── http1_client.py
│ ├── Data files/ # Test files for HTTP/1.1
│ └── http1_server.log # Generated when running
├── http2/
│ ├── server.py
│ ├── client.py
│ ├── Data files/ # Test files for HTTP/2
│ └── http2_server.log # Generated when running
├── bitTorrent/
│ ├── seeder.py
│ ├── leecher.py
└── README.md
-
Navigate to the HTTP/1.1 directory:
cd http1 -
Start the server:
python http1_server.py
The server will:
- Listen on 0.0.0.0:8080 (all interfaces)
- Serve files from the "Data files" directory
- Log activity to http1_server.log
-
Edit the
http1_client.pyfile to update the server IP address:# Define server URLs - update with your actual server IPs computer1_url = 'http://YOUR_SERVER_IP:8080' # Replace with your server's IP
-
Run the client:
python http1_client.py
The client will:
- Download files of different sizes (10kB, 100kB, 1MB, 10MB)
- Perform multiple transfer repetitions (1000, 100, 10, 1 respectively)
- Calculate throughput, latency, and overhead metrics
- Save results to
http1_1_throughput_results.json
-
Navigate to the HTTP/2 directory:
cd http2 -
Start the server:
python server.py
To use specific host/port:
python server.py --host 192.168.1.100 --port 8443
The server will:
- Listen on the specified interface (default: 0.0.0.0:8080)
- Serve files from the "Data files" directory
- Log activity to http2_server.log
-
Run the client with your server's IP and port:
python client.py --server YOUR_SERVER_IP --port 8080
-
For testing a single file:
python client.py --server YOUR_SERVER_IP --port 8080 --file A_1MB --repeats 5
-
For testing with two servers:
python client.py --server SERVER1_IP --port 8080 --server2 SERVER2_IP --port2 8080
The BitTorrent implementation requires both a seeder and a leecher component to measure file transfer performance. This implementation uses existing torrent files rather than creating test files from scratch.
Before running the BitTorrent tests, you need to install the libtorrent library:
sudo apt-get install python3-libtorrentInstall a library to create a .torrent file which is shared to all the peers.
pip3 install py3createtorrentThe sender needs to creates the .torrent file which will be used to send files to the peers.
- CMD: py3createtorrent -t udp://tracker.opentrackr.org:1337/announce <path-to-file>
Example:
- py3createtorrent -t udp://tracker.opentrackr.org:1337/announce A_1MBpython seeder.py --torrent myfile.torrent --dir . --port 7001Parameters:
--torrent: Path to the .torrent file--dir: Directory where the original file is located--port: Base port for BitTorrent communication (default: 7001)
The seeder will:
- Load the torrent file
- Start serving the file to peers
- Continue running until manually terminated (Ctrl+C)
-
Run the leecher with the path to the torrent file and test parameters:
python leecher.py --torrent myfile.torrent --trials 5 --filesize 1048576
Before running these that leecher also has the torrent file mentioned in the command if you don't have create torrent file as told from above
Parameters:
--torrent: Path to the .torrent file--trials: Number of download trials to run--filesize: Expected file size in bytes (required for accurate metrics)
The leecher will:
- Download the file multiple times (based on trials)
- Measure download time, throughput, and overhead
- Save detailed metrics to a timestamped CSV file
- Generate a summary file with average metrics
For a complete comparison of all three protocols:
- Set up test files for all protocols
- Run tests for each protocol separately
- Compare results across protocols
First, test HTTP/1.1:
cd http1
python http1_server.py # Run on server machine
python http1_client.py # Run on client machineNext, test HTTP/2:
cd http2
python server.py # Run on server machine
python client.py --server SERVER_IP # Run on client machineFinally, test BitTorrent:
py3createtorrent -t udp://tracker.opentrackr.org:1337/announce A_1MB
python seeder.py --torrent A_1MB.torrent --dir test_files # Run on server machine
python leecher.py --torrent A_1MB.torrent --trials 3 --filesize 1048576 # Run on client machineBoth HTTP implementations generate JSON result files that include:
- Average Throughput: Data transfer rate in kilobits per second (kbps)
- Standard Deviation: Variation in throughput across multiple transfers
- Overhead Ratio: The ratio of total transferred data to file size (headers and protocol overhead)
- Transfer Count: Number of transfers performed
BitTorrent generates two files per test:
- Detailed CSV file: Contains metrics for each trial
- Summary file: Contains average metrics across all trials
Metrics include:
- Round-Trip Time (RTT): Total download time
- Throughput: Data transfer rate in kilobits per second
- Total Data Transferred: Ratio of total data to file size
- Total Payload Transferred: Actual file data received
When comparing protocols, look for:
- Throughput differences across file sizes
- Overhead ratios - typically BitTorrent has higher overhead for small files
- Consistency (standard deviation) - lower variation means more predictable performance
- Scaling efficiency - how performance changes as file size increases
-
Connection Refused:
- Ensure the server/seeder is running
- Check if the IP address and port are correctly configured
- Verify firewall settings allow traffic on the specified port
-
Slow Performance:
- Check network conditions
- Verify no other bandwidth-intensive applications are running
- Try running tests during periods of low network usage
- File Not Found Errors:
- Ensure test files are created in the correct directories
- Check file permissions
- Verify filenames match exactly what the client is requesting
-
Tracker Connection Issues:
- If using an external tracker, ensure it's accessible
- Consider using DHT or local trackers for testing
-
Seeding Issues:
- Ensure the seeder has the complete file
- Verify the seeder is properly configured for incoming connections
- Check that both seeder and leecher are using the same .torrent file
-
libtorrent Installation Problems:
- libtorrent can be difficult to install on some platforms
- Consider using Docker for a consistent environment
- For Windows, the Anaconda distribution often simplifies installation