4 ms·
I really hope that the website itself is running serverless on AWS, because that would be a great learning opportunity! It's quite easy and common to wreck a d
by thanatos_dem 8y ago
I really hope that the website itself is running serverless on AWS, because that would be a great learning opportunity!
It's quite easy and common to wreck a database when you have it hooked up to serverless infrastructure. Depending on the DB, there can be a significant amount of overhead for each client connection. Postgres is particularly bad at this, since it spawns an entire process for each client that connects. This is why connection pooling is so important for applications.
Serverless is a different beast tho; every function is isolated, so having a client pool is much harder/impossible. If you get a flood of traffic, and your function interacts with a DB, you suddenly have a ton of non-multiplexed client connections, which is all it takes to bring many databases to their knees.
If this is a serverless website, I can't wait for the author's next article, describing this issue and how they addressed it. If it's not serverless... add a client pool.
- Aeolun 8y agoWe solved it by having an EC2 connection pool instance :P it just sits there and ensures all the lambdas don’t blow up the database. Kind of defeats the point though :/
- ty_a 8y agoYou could run pgbouncer in a fargate container in ECS. Still serverless technically?
- djhworld 8y agoIn Java you can create a shared connection pool for AWS lambda functions, e.g. using DI and initialising your injector statically when classes are loaded by the JVM It relies on AWS using the same container/JVM for your invocations though which isn't guaranteed depending on what your load is.
- scarface74 8y agoYes you technically can do the same with any language...configure your connection statically.
- tlarkworthy 8y agoGoogle cloud functions are able to keep connections between invocations: https://cloud.google.com/functions/docs/bestpractices/networking https://cloud.google.com/functions/docs/bestpractices/networ... It solves this exact problem and enables pooling (disclosure: I worked on related infrastructure)
- mrfredward 8y agoAs a lover of irony, I was disappointed to see the "maintenance page" source references this url: "https://sinxloud.com/wp-admin/admin-ajax.php" https://sinxloud.com/wp-admin/admin-ajax.php" PHP running Wordpress. Sorry guys, it's not serverless.
- scarface74 8y agoOn top of everything you said, if you put your database inside your VPC, your lambda function has to create a network interface inside the subnet. That increases the cold start time. DynamoDB is a much better solution for serverless since it just uses a REST interface. I’m a big fan of lambda but not for user facing API end points. It works well for eventually consistent event processing. Setting up a Load Balancer and an Autoscaling group is not rocket science. Neither is automated patch management.
- benfrancis111 8y agoAws serverless Aurora... API interface, fully mysql / postgres compatible, cheap to run - billed on a cpu minutes used basis, massively scalable, auto backup and its much faster than typical dedicated server setups. Amazon's best performing aws product ever they were saying.
- scarface74 8y agoAurora is not the issue. The issue is a lack of connection pooling and the creation and destruction of ENIs when using Lambda with anything inside of a VPC. If you want to do anything with user facing APIs, suck it up and spend $10 a month for two or three micro Linux instances set up in an autoscaling group behind a load balancer. Elastic Beanstalk makes it dead simple.