0
0
Flaskframework~20 mins

Why performance matters in Flask - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Flask Performance Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Why is response time critical in Flask apps?

Imagine a Flask web app that takes 5 seconds to respond to each user request. What is the most likely impact on users?

AUsers will likely get frustrated and leave the site due to slow responses.
BUsers will appreciate the delay as it shows the app is working hard.
CThe app will automatically speed up after some time without changes.
DSlower response times improve security by limiting request rates.
Attempts:
2 left
💡 Hint

Think about how you feel when a website takes too long to load.

component_behavior
intermediate
2:00remaining
What happens if Flask app blocks on a slow database query?

Consider a Flask route that waits for a slow database query before responding. What is the effect on the app's performance?

Flask
from flask import Flask
app = Flask(__name__)

@app.route('/')
def index():
    # Simulate slow DB query
    import time
    time.sleep(5)
    return 'Done'
AThe app speeds up other requests automatically.
BThe app can handle other requests normally while waiting.
CThe app crashes due to the sleep call.
DThe app will block and cannot handle other requests until done.
Attempts:
2 left
💡 Hint

Think about how Flask handles requests in its default setup.

state_output
advanced
2:00remaining
How does caching improve Flask app performance?

Given a Flask route that caches expensive results, what is the expected effect on response times for repeated requests?

Flask
from flask import Flask
app = Flask(__name__)
cache = {}

@app.route('/data')
def data():
    if 'result' in cache:
        return cache['result']
    # Simulate expensive calculation
    import time
    time.sleep(3)
    cache['result'] = 'Expensive Data'
    return cache['result']
AFirst request is slow; subsequent requests are fast due to cached result.
BAll requests are slow because cache is ignored.
CApp crashes on second request due to cache errors.
DAll requests are fast because sleep is skipped.
Attempts:
2 left
💡 Hint

Think about what happens after the first slow calculation finishes.

📝 Syntax
advanced
1:30remaining
Identify the error causing slow Flask app startup

Which option contains a syntax error that would prevent Flask app from starting?

Flask
from flask import Flask
app = Flask(__name__)

@app.route('/')
def home():
    return 'Hello World'

if __name__ == '__main__':
    app.run(debug=True)
A
def home():
    return 'Hello World'
B
def home()
    return 'Hello World'
C
'dlroW olleH' nruter    
:)(emoh fed
D
ef home():
    return 'Hello World'
Attempts:
2 left
💡 Hint

Check function definitions for correct syntax.

🔧 Debug
expert
2:30remaining
Why does this Flask app hang on multiple requests?

Analyze the code below. Why does the app hang when multiple users access it simultaneously?

Flask
from flask import Flask
app = Flask(__name__)

@app.route('/')
def index():
    while True:
        pass
    return 'Done'
AThe app crashes immediately due to syntax error.
BThe app runs fine; infinite loop is ignored by Flask.
CThe infinite loop blocks the worker, preventing it from handling other requests.
DThe app returns 'Done' immediately without delay.
Attempts:
2 left
💡 Hint

Consider what an infinite loop does to a single-threaded server.