I'm working on a few Node.js serverless projects that use Aurora Postgresql with Sequelize as the ORM. We've been hitting a wall with the number of concurrent database sessions—our average should be around 2, but it often spikes to 5 or 6. Initially, a lot of this was due to inefficient code, but after some refactoring, the main culprit now seems to be the concurrent requests hitting our Lambdas, which we can't directly control.
I found a few potential solutions:
1. Sequelize has some guidance for Lambdas that I think might help with parallel queries in each function, but I'm not sure it addresses the issue of concurrent connections since new containers are created for requests.
2. Implementing RDS Proxy seems like the best route, though we need to weigh the costs and get approval.
3. We could also utilize SQS for endpoints that don't require an immediate response, and possibly throttle client calls to manage load.
I'm leaning towards a combination of these options. Would you suggest anything else?
4 Answers
It sounds like you're mixing up active sessions with total connections. Active sessions reflect the actual work being done at once, while connection counts don’t really determine that. If your workload is outpacing your DB capabilities, you'll either need to boost your DB size or reduce the workload by optimizing your queries or throttling users.
Definitely go with the RDS Proxy. It’ll manage your connections better and help reduce overhead by keeping things speedy. It’s a wise first step, and after implementation, monitor how performance looks.
Honestly, it sounds like upgrading to a larger instance could be a simple and effective solution. You're considering various strategies to throttle and queue workloads, but it might just be that your current DB can't handle the load efficiently. Give the upgrade a shot; it's an easy test to run!
Your maximum db connections going up to 6 isn’t really that extreme, but if you're experiencing issues, it’s worth looking into. With Sequelize, consider setting the max for request pooling to 2, which could help improve the situation. That way, if your maximum active sessions cap at 2, you'd only use about 4 connections on average. It may help alleviate some of the problems you're facing with timeouts and unexpected connection terminations.
Related Questions
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String