3

I have a controller that's very slow when running in Gunicorn/Gevent (21sec) over pure Flask (5s)

Upon profiling there are 300K calls to Python's built-in method time.localtime. Here's a simplified controller that also shows this behavior

import time
def my_time():
    time.localtime()


@app.route('/my_test', methods=['GET'])
def my_test():
    """
    Test endpoint
    """
    for i in range(326457):
        my_time()
    return 'OK'

Profile output from running pure Flask

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
   326457    0.204    0.000    0.387    0.000 __init__.py:23(my_time)
   326457    0.183    0.000    0.183    0.000 {built-in method time.localtime}
   326457    0.010    0.000    0.010    0.000 {method 'disable' of '_lsprof.Profiler' objects}
        0    0.000             0.000          profile:0(profiler)

Profile output w/ Gevent/Gunicorn. Gunicorn server settings gunicorn --workers=2 --threads=5 --timeout=300 --graceful-timeout=300 --worker-connections=100 --worker-class=gevent -b :8080 main:app

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
   326457    0.226    0.000   15.784    0.000 __init__.py:23(my_time)
   326457   15.557    0.000   15.557    0.000 {built-in method time.localtime}
   326457    0.016    0.000    0.016    0.000 {method 'disable' of '_lsprof.Profiler' objects}
        0    0.000             0.000          profile:0(profiler)

What's causing time.localtime to take over 15s with Gunicorn/Gevent?

Versions

Python 3.6
gevent==22.10.2
gunicorn==20.1.0

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.