News for hackers. Stuff that matters.
Re:One Million Database Connections by twawaaay on Tuesday November 01, 2022 @01:05PM (#33424008)
Oh my, you are doing it wrong.

If you have a lot of connections doing similar things, just batch requests to get the data in bulk.

For example, if you have 500 people logging at the same time and fetching their user details, batch those requests for example every 100ms up to 100 users and fetch 100 records with a single query.

I scaled one large banking application this way by a factor of 50 with no additional investment in hardware.

Re:One Million Database Connections by yamtaddle on Tuesday November 01, 2022 @01:19PM (#33424212)
But then you can't put "led implementation of a highly-scalable $80m/yr cloud-native solution" on your resume. And bigger numbers mean bigger salary.

Now, if you wait for someone else to do this then you swoop in and cut that spending by 90%... now you're talking. Then the next person can reverse what you did and we all keep making money digging holes then filling them back up.

Pay it forward.

Re:One Million Database Connections by Kiro on Tuesday November 01, 2022 @01:34PM (#33424482)
Why are people upvoting low-effort snark like this?
Re:One Million Database Connections by _boffin_ on Tuesday November 01, 2022 @01:43PM (#33424627)
Because it’s sadly true
Re:One Million Database Connections by twawaaay on Tuesday November 01, 2022 @02:31PM (#33425380)
Yeah, it is better to manage 50 people and millions in hardware than do the same work with just 2 engineers and one server.

You then get those completely unnecessary feats of technology when really, a single server is usually good to run hundreds of thousands of transactions per second.

It infuriates me that incompetence is promoted and the only way to get rewarded is to be good at internal politics.

Re:One Million Database Connections by andrewbarba on Tuesday November 01, 2022 @01:12PM (#33424098)
How could you possibly say this is doing it wrong? The only way you could batch requests in the way you describe is if you have 1 (or very small number) compute nodes. You would need all those requests to hit same node so you could try and batch. With serverless compute infrastructure (which is what this blog is demonstrating by using lambda) you can have 1 isolated process per request and therefore need a database that can actually handle this kind of load.
Re:One Million Database Connections by vbezhenar on Tuesday November 01, 2022 @01:23PM (#33424278)
Introduce intermediate server which accepts multiple requests and groups them into single batch requests.

With enough trickery you can even implement it using postgres wire protocol, I guess, so it'll be transparent.

Re:One Million Database Connections by cbrewster on Tuesday November 01, 2022 @01:29PM (#33424387)
Now you need to batch your requests to your intermediate server
Re:One Million Database Connections by yamtaddle on Tuesday November 01, 2022 @01:31PM (#33424439)
No, you don't. You have one per 100 nodes or whatever. Not a single one for all nodes to talk to.
Re:One Million Database Connections by mjb on Tuesday November 01, 2022 @01:29PM (#33424389)
But why? Why have an additional component if your database can do it?
Re:One Million Database Connections by vbezhenar on Tuesday November 01, 2022 @03:38PM (#33426358)
twawaaay claimed that similar approach allowed him to improve throughput by factor of 50. Apparently database couldn't do it efficiently in that case.
Re:One Million Database Connections by qaq on Tuesday November 01, 2022 @01:23PM (#33424288)
if you are at load level when you have million lambdas executing concurrently your monthly bill will make even Uncle Sam cry.
Re:One Million Database Connections by ignoramous on Tuesday November 01, 2022 @01:52PM (#33424759)
In the case of the blog post at least: It is a 1,000 lambdas making 1,000 queries each.
Re:One Million Database Connections by qaq on Tuesday November 01, 2022 @02:38PM (#33425514)
Well thats very unrealistic workload
Re:One Million Database Connections by aarondf on Tuesday November 01, 2022 @02:46PM (#33425650)
Unrealistic from the Lambda side, yes! But we were just trying to generate connections to the DB, not test the capabilities of Lambda
Re:One Million Database Connections by qaq on Thursday November 03, 2022 @01:48AM (#33447483)
sure I am not criticizing the methodology of load testing, just pointing out that at extreme high loads lambda is too expensive to use.
Re:One Million Database Connections by twawaaay on Tuesday November 01, 2022 @02:36PM (#33425473)
> With serverless compute infrastructure

Here is your problem. You are trying to build a huge application using inadequate technical building blocks.

If your database is overloaded with hundreds of thousands of connections from your lambdas, it means it is end of the road for your lambdas. Do not put effort into scaling your database up, put effort into reducing the number of your connections and efficiency of your application.

Re:One Million Database Connections by aarondf on Tuesday November 01, 2022 @03:19PM (#33426061)
I think you can start to hit connection limit walls with RDS at several hundred connections, depending on your instance size. Running an even moderately busy app you could hit those pretty quickly. I would hate to have to change my entire infrastructure at such an early stage because the DB was hitting connection limits!

Would you ever need a million open connections? Probably not! But you'll likely want more than 500 at some point. And if your entire stack is serverless already, it'd be nice if the DB could handle that relatively low number of connections too.

Re:One Million Database Connections by twawaaay on Tuesday November 01, 2022 @03:54PM (#33426580)
I look at the database connections the following way: how many connections can a database really serve effectively? For a connection to be actively served the database really needs to have a cpu core working on it or waiting for IO from the storage. And I am completely omitting the fact that databases really need a sizeable amount of memory to be able to do things efficiently.

Even if you have a server with hundreds of cores your database probably can't be actively working on more than a small multiple of the number of the cores.

Re:One Million Database Connections by aarondf on Tuesday November 01, 2022 @03:57PM (#33426623)
I'm not sure if you've seen the other post, but we can totally handle one million queries per second: https://planetscale.com/blog/one-million-queries-per-second-....

And previous HN discussion: https://news.ycombinator.com/item?id=32680957.

Re:One Million Database Connections by twawaaay on Tuesday November 01, 2022 @04:23PM (#33426972)
I am not saying you can't. I totally believe you do.

Modern hardware is totally able to execute hundreds of thousands of transactions per second on a single core. If your query is simple and you can organise getting the data from storage at the necessary speeds you should totally be able to do this many requests, possibly even tens of millions.

But handling one million queries per second is completely different from having database server making progress on one million queries in parallel. What happens is, the database server is only making progress on a small number of them (typically in tens up to hundreds on a very beefy hardware) and everything else is just queued up.

There are much, much better ways to queue up millions of things than opening a million connections to get each one done individually.

Re:One Million Database Connections by lizztheblizz on Tuesday November 01, 2022 @05:31PM (#33427812)
Lambda was a means to an end for us here, and we're not specifically endorsing its use in _this_ way. Our goal was explicitly to test our ability to handle many parallel connections, and to observe what that looked like from different angles.

We're a DBaaS company, and we do need to be prepared for anything users may throw at us. Our Global Routing infrastructure has seen some major upgrades/changes recently to help support new features like PlanetScale Connect and our serverless drivers.

From our point of view, this was a sizing exercise with the interesting side benefit that many people do happen to use Serverless Functions similarly.

Re:One Million Database Connections by ndriscoll on Tuesday November 01, 2022 @08:23PM (#33429823)
How much is a moderately busy app? I have a sketch of a twitter app in Scala with zio-http as the framework, doing the batching strategy twawaaay describes, and it can handle 46k POSTs per second on my i5-6600 with a SATA3 SSD. That's using 16 connections to postgres, though that's probably more than is reasonable for my 4 core CPU.

At 46k RPS, it only takes 5.5 ms to assemble a batch of 256, so latency is basically unaffected by doing this. Just set a limit of 5-10 ms to assemble the batch (or lower if you have a more powerful computer that can handle more throughput).

Re:One Million Database Connections by themenomen on Tuesday November 01, 2022 @01:27PM (#33424353)
I thought this was just a PoC
Re:One Million Database Connections by DSingularity on Tuesday November 01, 2022 @01:06PM (#33424019)
But the lost elegance!
Re:One Million Database Connections by dang on Tuesday November 01, 2022 @01:47PM (#33424684)
Can you please edit swipes like "you are doing it wrong" out of your HN comments? It acidifies the thread and evokes worse from others. The site guidelines are pretty clear about this: https://news.ycombinator.com/newsguidelines.html.
Re:One Million Database Connections by twawaaay on Tuesday November 01, 2022 @02:55PM (#33425769)
Edited out but the issue is it really is technically wrong. From a person that is actually building real world large scale applications this is super naive. There exists no networking hardware or disk IO that can adequately support this many active connections. What you really want to do is to do the same work with much less connections which will save you a ton of overhead and also memory that can be used to actually cache useful data.

My goal is to share this little bit of insight so that hopefully fewer people make this fatal mistake. Just because you can technically do something does not mean this is a good idea. If you need to run a million connections to the database instance you really need to rethink this entire problem.

Re:One Million Database Connections by nixgeek on Tuesday November 01, 2022 @03:13PM (#33425985)
I’m not sure I’d say anything is a “fatal mistake” if it works, and this appears to? Feels like you’re coming at this from “it’s suboptimal”, calling it a fatal mistake is a bit much?

I would look at it this way: Firstly, it’s just a demonstration of how far a technology can scale, not an endorsement of technical approach for the customers.

Secondly, on serverless, PlanetScale is just solving things their customers want? They don’t have a business if they don’t do that.

Finally, even if you are “right” or at least making a valid point, isn’t the “rethink this entire problem” take principled more than practical? There’s always 47 things to do and time only exists to do a few.

Re:One Million Database Connections by lifeisstillgood on Wednesday November 02, 2022 @02:15PM (#33440472)
Just wanted to come back and defend you (a little :-)

I read "if you have a million database connections then you are doing it wrong" less as a ad hominem attack and more as "if one is doing X one should try a different approach"

I did like the "architectural strategy" of I can call it that of batching the calls. It's "tricks" like that, expressed at this level that are somehow missing from the common software dev parlance. They are not in l33tcode tests, they don't fit into neat boxes but they are vital "common knowledge"

I wish I had a better term for these sort of optimisations.

Anyway. Thanks for the comment. Don't take the blowback personally - frankly I was surprised even if it was a small storm in a teacup.

And always do as dang says ;-)