Django with DRF APIs slows down after few weeks or months

I have Django with DRF website and it has couple of APIs based on DRF with GenericAPI view and API view. The APIs is used to calculate XML vs XML and JSON vs JSON differences. Two objects are passed as body to these APIs and the API returns the no of differences and exact nodes at which the differences are found. It also respond with nodes which are added or removed.

The sight and APIs work just fine when my environment is just up and running for few weeks say 2 weeks. I have recently observed that after a month or 3 weeks same APIs takes much more time to calculate the differences with same set of data.

Usually it is very fast for example If we have large JSON object then 1k differences per second is processed. If we have pretty small JSON or XML object like 5 to 10 keys (very basic) the main library function which calculates the difference tales just about few milliseconds. So overall API time is like 200 ms.

Now the issue that I have is after lets say 3 weeks or a month same very basic JSON object comparison (with just 5-10 keys) takes 20 seconds to respond. The library function takes almost 20 seconds to calculate just one or two difference.

I am not using any caching here. No Database operations are involved in any of my library function.

I do use dict and list data types in python to store the differences calculated. Any idea why does this happen?

Infra details:

  1. 4VCPU machine with 16 GB ram (AWS t3.xlarge)
  2. docker compose environment with nginx, gunicorn django
Back to Top