Database Access Overhead in Vapor
Recently I was trying to deploy a Laravel Application using Vapor. I had to create a database for my application using Vapor. As per the Vapor Docs, a network would automatically be created when deploying for the first time. But in our project for some reason, the network was not automatically creating. So I had to create a new network from Vapor UI. I had to select the region and a name for the network to create it.
Then I created a fixed publicly accessible database with minimum configuration (db.t3.micro — 2VCPU 1Gib RAM).
Then I set up the tables in the database and deployed the application. However, the application was running slower than I expected. I tried several optimizations in the application but the application was still slow. After spending some time I found the issue was with the database connection being slow. I then scaled the database from the Vapor UI to db.t3.medium — (2 VCPU, 4Gib RAM).
But still, the database connection was slow. To test more I further scaled the database to a higher configuration. But there was no progress to the speed. After spending some time on what will be the issue I noticed the network was created on a region different from the region where the application was deployed.
The application was deployed on the us-east-2 region but the network in which the database was created was on the us-west-2 region. I deleted the network from Vapor UI and created a network again with the region as us-east-2. Then we the code and checked the speed. Speed was good now. Then we scaled down to the db.t3.medium configuration and tested the speed. The speed was the same.
So I can conclude that the AWS region to which the database is created should be the same to which the application is deployed to have good performance for any web applications.
Originally published at https://www.2hatslogic.com on November 14, 2019.