Figuring out the most efficient method to send requests to test web servers.
I've been experimenting with various ways to try and speed up COMP1531's test runners, and also check how the performance of various other request-related things relate.
Here's a link to the results.
- Using
sync-request
is about 5x slower than using thefetch
API. - Python is about twice as slow as JS when sending real requests.
- When injecting fake requests using Flask's testing library (instead of sending real requests), performance improves by 5x.
- If we can find a library to inject fake requests into Express, we may be able
to get a similar performance improvement, meaning the improvement would be
25x compared to using
sync-request
.
Here's how you can run the benchmarks on your own machine.
Note: I'm using Poetry as the dependency management tool for Python. You'll need to install it.
- Install Python dependencies with
poetry install
- Install JS dependencies with
npm install
- Run the test script with
poetry run python runner.py
You can use --progress
to get a live counter (so you know it hasn't broken)
You can also customise the particular variations that are run by editing
runner.py
.
Run server using poetry run python -m flask_app
All combinations of:
requests
library to send requestsflask.testing
library to send fake requests
GET
with query stringPOST
with JSON
- Flask's
jsonify
function - Standard
json
library
Run server using npm start
All combinations of:
sync-request
to send requests- Node's built-in
fetch
to send requests
GET
with query stringPOST
with JSON