2

I have a question to ask regarding the performance of my flask app when I incorporated uwsgi and nginx.

My app.view file looks like this:

import app.lib.test_case as test_case
from app import app
import time

@app.route('/<int:test_number>')
def test_case_match(test_number):
    rubbish = test_case.test(test_number)
    return "rubbish World!"

My app.lib.test_case file look like this:

import time
def test_case(test_number):
    time.sleep(30)
    return None

And my config.ini for my uwsgi looks like this:

[uwsgi]

socket = 127.0.0.1:8080
chdir  = /home/ubuntu/test
module = app:app
master = true
processes = 2 
daemonize = /tmp/uwsgi_daemonize.log
pidfile = /tmp/process_pid.pid

Now if I run this test case just purely through the flask framework without switching on uwsgi + nginx, using the ab benchmark, I received a response in 31seconds which is expected owning to the sleep function. What I dont get is when I run the app through uwsgi + nginx , the response time I got was 38 seconds, which is an overhead of around 25%. Can anyone enlighten me?

  • I've set up my nginx + uwsgi + flask as described in http://stackoverflow.com/questions/27196776/uwsgi-upstart-on-amazon-linux and I don't see an 8 second lag. – tourdownunder Jan 22 '15 at 06:01

1 Answers1

0

time.sleep() is not time-safe.

From the documentation of time.sleep(secs):

[…] Also, the suspension time may be longer than requested by an arbitrary amount because of the scheduling of other activity in the system.

Klaus D.
  • 13,874
  • 5
  • 41
  • 48