Initial load of sub-domain takes a long time

Hi,
I am running a Django application with postgresql and about 30 tenants organized as separate schemata in postgresql. Each tenant is accessed by an individual sub-domain managed with Apache v2.4
This is running on a VPS with 48Gb Memory.
When calling the sub-domain the first time it takes 20-30 sec to get the login screen. After this it is working fine.
I already have a pre-load script running that pre-loads every sub-domain one after the other, but my feeling is that once I have loaded the last one the first one is already dropped from cache and it again takes a long time to load the initial page.
What can cause this delay and what can I do to resolve this? Could a migration to NGINX help as it uses less resources?
Thanks

This does not sound like an issue with apache.

I would recommend running a profiler on the initial load and seeing what you’ve got. Maybe also an import trace. You should be able to reproduce the startup time by writing a very basic management command that imports your main urls file and use that to run through the profiler. That’s easier to work with than doing it in production I’d think.

I have no experience with using a profiler. Can you guide me to some documentation or propose a simple profiler to use.

If you go the management command route then the docs for cProfile command line usage should be fine.

I ship a web based profiler as part of iommi that can be used for projects that otherwise don’t use iommi. Dev tools - iommi 7.14.1 documentation