0

I am seeing massively degraded DRF performance for simple python code when running under an API vs. standalone.

For e.g., here are the benchmarks when running the python code standalone (i.e. outside of Django. Just a plain old script in python). I am loading a user file, converting it into a custom object and running some validations on it. All done in regular python code with no Django dependencies nor any ORM.

xlsname = 'user_file.xlsx'
dash = Dashboard(xlsname,logging.ERROR,create_copy=True)  #loading user file
Load time: 1.828125

dash.validate() #validate user file
Validation time: 0.203125

Now when running the same code under a simple DRF function view:

#views.py

@api_view(['GET'])
def load_and_validate(request):
    xlsname = 'user_file.xlsx'
    dash = Dashboard(xlsname, logging.DEBUG, create_copy=True)
    dash.validate()
    return Response({"message": "{} loaded".format(xlsname)})

My response times are:

Load time: 1.96875 #this is in line with standalone execution
**Validation time: 5.21875 # this is 2500x slower than standalone!**

The validation time for my file is now 2500x slower than standalone!

I am not even using any ORM yet so there are no queries. Everything is loaded into the memory and executed from there.

What may be causing this and how can I diagnose it?

2
  • Can you eliminate the obvious and set logging.DEBUG to logging.ERROR in the DRF case? Commented Nov 7, 2019 at 17:58
  • 1
    That was it. Clearly missed my morning coffee. Commented Nov 7, 2019 at 17:59

1 Answer 1

1

User error. I was running the DRF case under logging.DEBUG instead of logging.ERROR.

Sign up to request clarification or add additional context in comments.

Comments

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.