1

I am running a Django Rest Framework server on Google Cloud Platform. Most of my requests are post request. I want to analyse which request is using how much memory and how much CPU on average. Is there a way to analyze it?

My API code looks like as follow:

class GetAudioDialogue(APIView):

    def post(self, request):
        ...
hardik24
  • 1,008
  • 1
  • 11
  • 34

1 Answers1

0

I have no experience analyzing this but I found some possible options.

Custom middleware using psutil

It is possible to write your own middleware that tracks memory usage per process request and repsponse. An example of this can be found in this StackOverflow - Question

Pympler

As their Github repo states:

Development tool to measure, monitor and analyze the memory behavior of Python objects in a running Python application.

It offers ways to track memory in Django, tracking class instances, individual objects and more. More information can be found in the corresponding docs

Valgrind

As the official website states:

Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools.

It requires some setting up. Info about how to set it up for Python can be found in this StackOverflow - Question

Stevy
  • 3,228
  • 7
  • 22
  • 38