I have made my first LAMP deployment using Django. Basically I’m pre-processing an image and extracting info from it. When I run it in my computer the time it takes to obtain the expected result is around 11 seconds but when I deploy it in my server it takes way more time (more than a minute). I was expecting a bit more of delay due to website requests ,etc. but it’s taking too long unfortunately. I was hoping someone who has experience deploying Django websites could guide me about what could be the cause of the vast difference between deployment in my computer and my server. Probably, someone has had a similar situation and found out it was related to the database, server memory, Apache configuration, etc. Or any advice about how to face this issue is welcomed.
Some general things I’ve found that cause slowness are the following:
- Media files being stored on a different server, but interacted with as if they were files
- Insufficient DB RAM or other resources
- Queries requiring optimization as the data in the tables grows
- Insufficient server resources
If you have a staging environment where you can repeat this problem, I’d suggest installing the Django Debug Toolbar and seeing what is eating up the time. If the default panels don’t help enough, you can enable the Profiling panel, but that will cause the request to take much longer.
If you are storing your media files on AWS S3, that may be the culprit though. Some of the image-processing libraries expose an API that makes it easy to forget that the files request a web request to fetch and send data slowing things down significantly. If this is the case for you, you may want to move this logic into a background job to allow the web request to operate faster. However, you’d have to figure out what to show when the processed image isn’t ready yet.