'Response time increasing with time Spring-Boot application?

I am a beginner in Backend development. So, in case I haven't mentioned my problem correctly or you want more information around the problem, please ask, I will learn.

We have our backend in Python-Django monolithic architecture, which we are planning to shift to Spring-boot micro-services. The database we are using is Postgres.

I started it by shifting the critical GET APIs first of our existing code, i.e. POST and PATCH requests are handled by the Django application independently, but the GET requests are handled by Spring-Boot.
So, I have re-routed the GET API call on Python-Django to Spring boot microservice, using Requests HTTP Library and added a fall back again to Python-Django code if the requests.status_code is not 200 from Spring-Boot Application

Python Rerouting code snippet:

SPRING_URL = SPRING_MICROSERVICE_URL + "/users/sent/{user_id}/"
response = requests.get(
   url=SPRING_URL.format(user_id=self.request.user.id), params=payload
)
if response.status_code == 200:
    return self.get_response(data=response.json())
else 
    fallback to the existing python-django code

There are 6-7 DB calls, out of which only 1 is time-consuming on a Materialized View PSQL, which takes around 1 sec for some of the requests in my local and staging machines. I am using HikariCP for connection pooling.

Now, when I am testing it on my local machine and staging machine using JMeter directly on the Spring-Application it shows an average time of 90-100 ms with max-min being 30 and 2500 ms respectively, and around 110-140 ms with min-max 50-3000 ms respectively through django rerouting, which is acceptable.

JMeter Thread Properties:

Number of threads (users) : 2
Ramp-up period (seconds) : 1
Loop Count : 1000

Now, when I deploy it on Production (django http requests are rerouted to spring-boot) server, the response time goes on increasing with time, which I expected to decrease or at-least equals with django application.
Django application (without rerouting) took around 200-220 ms on Production, but now it increases with time from 31 ms to 10,000 ms and continues to increase (so we reverted back to django application)

One of the bottlenecks is the query to psql-view, for which I tried to increase connection pool size from the application as well as DB side, but it didn't work.

I have no idea, why is it behaving so badly in production, which I expected to improvise. Please suggest something.

My questions:

  1. Is it a good practice to call Spring-boot application from Django application? As both handle multiple HTTP requests differently.
  2. As spring applications can handle multiple requests using multiple threads, and django serves one request at one time, so does it play any role in the slowdown?
  3. Does increasing connection pool size helps, in my case?

Some Configs :
Using Gradle as build-automation tool
Django - gunicorn.config - threads = 4



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source