1

I have this method

class RunningQuizAuthenticationView(APIView):

    def dispatch(self, *args, **kwargs):
        print(time.time())
        return super(RunningQuizAuthenticationView, self).dispatch(*args, **kwargs)

    def get(self, request: Request, key: str) -> Response:
        print(time.time())
        .....
        ......

Now, once I get both the time, I take the difference of this time, the difference time is about 30 ms, can you explain to me why this is taking so much time, for the login request it takes about 0 ms but for other requests it takes a long time to reach target method from dispatch method, please help me, Thank you

5
  • You don't say where you get the time difference and what they are supposed to be. Can you be more specific ? time.time() will just display a time... Commented Sep 27, 2017 at 12:44
  • Once time gets printed on the console, I take it and take the difference using a calculator. As we know dispatch is the method which calls our target method. Commented Sep 27, 2017 at 13:22
  • What operations are there in your other views? I/O examples please. Commented Sep 27, 2017 at 13:30
  • 1
    30 ms is not a long time! It is 0.03 second. How fast do you want it to be? Commented Sep 27, 2017 at 14:10
  • Finally, I got the bottleneck, It is inside dispatch method of APIView, it calls "perform_authentication" method which is taking about 30ms, I will solve it now, Thank you guys for your responses :) Commented Sep 27, 2017 at 14:37

1 Answer 1

1

I got the bottleneck, It is inside dispatch method of APIView, it calls "perform_authentication" method which is taking about 30ms,

def perform_authentication(self, request):
        """
        Perform authentication on the incoming request.

Note that if you override this and simply 'pass', then authentication will instead be performed lazily, the first time either `request.user` or `request.auth` is accessed. """ request.user

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

1 Comment

yes for us also , most of the request time is spending in this method, as per the comment, we can over-ride this method and simply do 'pass' then authentication will be performed lazily and request time is getting reduced drastically(from 25 seconds to 3 seconds).....is there any impact if, we do the way suggested in 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.