This project aims to compare WebSocket implementations in two Python frameworks: Tornado and Websockets. The evaluation includes measuring latency, throughput, scalability, and collecting hardware details during data exchange.
- Clone the repository:
git clone https://github.com/Rectiras/repo-websockets.git
- Navigate to the project directory:
cd repo-websockets
- Ensure Python is installed on your system.
- Install project dependencies:
pip install -r requirements.txt
-
tornado_client.py
: Tornado WebSocket client. Sends messages to the server and generates an Excel file named tornado.xlsx containing real-time data, including latency, throughput, and hardware details. -
tornado_server.py
: Tornado WebSocket server. Listens for incoming messages from the client, simulates real-time data, and calculates latency and throughput.
- Start the server:
python tornado_server.py
- Launch the client:
python tornado_client.py
- The client can input messages and receive responses from the server with fixed JSON data (modifiable in
tornado_server.py
). - To generate the Excel file with a summary, clients must input
exit
.
-
websockets_client.py
: Websockets WebSocket client. Sends messages to the server and generates an Excel file named websockets.xlsx containing real-time data, including latency, throughput, and hardware details. -
websockets_server.py
: Websockets WebSocket server. Listens for incoming messages from the client, simulates real-time data, and calculates latency and throughput.
- Start the server:
python websockets_server.py
- Launch the client:
python websockets_client.py
- Similar to Tornado, the client can input messages and receive responses from the server with fixed JSON data (modifiable in
websockets_server.py
). - To generate the Excel file with a summary, clients must input
exit
.
-
Latency Comparison
-
Tornado Average Latency: 0.000965
-
Websockets Average Latency: 0.000876
-
Websockets Performed 10% better than Tornado
-
-
Throughput Comparison
-
Tornado Throughput: 30,2804844366243
-
Websockets Throughput: 30,3015221337059
-
Almost Identical Throughput with Websockets performing slighly better than Tornado.
-
-
Scalability
-
Tornado:
-
- Well-suited for handling concurrent connections
-
- May require fine-tuning for specific scalability requirements
-
Websockets:
-
- High concurrency support
-
- Asynchronous architecture for efficiency
-
Based on the comparison, Websockets demonstrated approximately 10% better latency and nearly identical throughput compared to Tornado. While both libraries have their strengths, Websockets is recommended for this scenario due to superior latency performance.