g0v / vaccinate

vaxx.tw is a tool to find COVID-19 Vaccine Appointments near you
http://vaxx.tw
MIT License
33 stars 20 forks source link

[3][Performance] Query airtable by city #97

Closed kevinjcliao closed 3 years ago

kevinjcliao commented 3 years ago

Context

This PR

Performance Measurement

Methodology

By inserting time.time() calls before and after each request, we can time how long it's taking for our server to respond to requests to /government_paid_hospitals.

# pyre-fixme[56]: Decorator async types are not type-checked.
@app.route("/government_paid_hospitals")
async def government_paid_hospitals() -> wrappers.Response:
    start_time = time.time()
    city: str = request.args.get("city")
    data = await get_hospitals_from_airtable("", city)
    response = app.response_class(
        response=json.dumps(data),
        status=200,
        mimetype="application/json",
    )
    end_time = time.time()
    print(f"Execution time {end_time - start_time}")
    return response

Time (seconds)

Test 1 Test 2 Test 3 Test 4 Test 5 Average
Before 13.18s 13.04s 14.93s 13.02 13.72 13.59
After 4.83s 6.08s 4.25s 2.72 2.95 4.17s

Total request response time improvement: 13.59-4.17 = 9.42 seconds. (3.25x speedup)

Test Plan

https://user-images.githubusercontent.com/8745371/126029568-e06820be-36a1-4cb1-a3cf-283b82f2c607.mp4

https://user-images.githubusercontent.com/8745371/126029606-40ba0e7b-5c50-4894-83a7-aef7d461a588.mp4