News for hackers. Stuff that matters.
Re:Scaling PostgresML to 1M Requests per Second by alberth on Tuesday November 08, 2022 @08:29AM (#33518705)
4 load balancers with local caches + 5 replica databases.

I don’t want to discredit the achievement but the 1MM/sec seems less exciting when you learn they horizontally scaled the architecture.

Especially when SQLite, in a client/server config (BedrockDB), achieved 4MM/sec from a single server.

https://blog.expensify.com/2018/01/08/scaling-sqlite-to-4m-q...

Re:Scaling PostgresML to 1M Requests per Second by sidpatil on Tuesday November 08, 2022 @08:42AM (#33518821)
I'm not sure the two are comparable—OP's article is about 1 million ML predictions per second, while your link is about 4 million queries per second.
Re:Scaling PostgresML to 1M Requests per Second by alberth on Tuesday November 08, 2022 @08:48AM (#33518871)
Thanks for pointing out the difference.

Genuine question: is a ML prediction slower than to fetch a row from a database and/or more difficult to scale?

Re:Scaling PostgresML to 1M Requests per Second by simonw on Tuesday November 08, 2022 @09:36AM (#33519396)
From the article:

> XGBoost cannot serve predictions concurrently because of internal data structure locks. This is common to many other machine learning algorithms as well, because making predictions can temporarily modify internal components of the model.

Re:Scaling PostgresML to 1M Requests per Second by ComputerGuru on Tuesday November 08, 2022 @03:19PM (#33523749)
I wonder if finer-grained mutex wa or other concurrency protection types covering interior components would be an option.
Re:Scaling PostgresML to 1M Requests per Second by mrfox321 on Tuesday November 08, 2022 @08:59AM (#33518967)
It's slower than a row lookup.

Specifically, this model is an ensemble of decision trees.

This involves

1. Row lookup

2. N (tree depth) inequality checks on fields in the row for M trees

3. Weighted sum over M trees

Re:Scaling PostgresML to 1M Requests per Second by tucnak on Tuesday November 08, 2022 @09:02AM (#33519005)
In this case, they are talking about xgboost inference, which can verge on the hungry side of things, but this is no match for deep learning, although word embeddings and transformers are supported[1] by PostgresML regardless. GPUs are supported[2] for Transformers as well as xgboost, so this approach is also kind of future-proof in the sense that you're not going to ever be limited by your compute, as well as the size of your replica set. But now, yes, to answer your original question— yes, for the most part typical regression-type task inference is marginally slower than fetching and involves crossing the process boundary, can't be easily parallelised, and so on. Hopefully, this is something that could be dealt with on PostgresML side, as Postgres exposes some neat parallelism primitives AFAIK. COMBINEFUNC is how you make your aggregates parallel and with SERIALFUNC potentially multinode-friendly, although here I'm not sure as I haven't maintained custom aggregates over a high-availability Postgres cluster... At any rate, this is a clear area of future research; now that there's inference, how to best parallelise it in the model of Postgres.

[1] https://postgresml.org/user_guides/transformers/setup/

[2] https://postgresml.org/user_guides/setup/gpu_support/

Re:Scaling PostgresML to 1M Requests per Second by ComputerGuru on Tuesday November 08, 2022 @03:24PM (#33523808)
Can you train xgboost on a GPU and use that model to make predications on the CPU?
Re:Scaling PostgresML to 1M Requests per Second by tucnak on Wednesday November 09, 2022 @05:27AM (#33529543)
Sure!
Re:Scaling PostgresML to 1M Requests per Second by derefr on Tuesday November 08, 2022 @12:29PM (#33521643)
Speaking in generalities rather than specifically about Postgres/PostgresML, this is how you should think about speccing hardware to solve these kinds of problems:

A DBMS that does mostly point-query reads — fetching single "cold" rows from a large storage, with high concurrency — is an IO-bottlenecked workload. Given a sufficiently mainframe-y "DMA from disk straight through to the NIC" architecture (which modern microcomputer servers are rapidly approaching), the CPU is just "guiding" that transfer — acting as a PCI-e switchboard operator — rather than actually performing it. The only things you need to worry about are JBOD IO-queue depth and (multi-aggregated) NIC total ring-buffer size. This means that you can go very far with "vertical" scaling for these workloads, in the sense that you can shove more disks and NICs into the same machine and it'll be able to serve more RPS, without really increasing CPU load. For IO-bottlenecked workloads, you only start to suffer when your PCIe bandwidth is exhausted — which is why systems built for "SAN" or "DB" or "hyperconverged" use-cases like this always use dual-socket CPUs (lately: dual Epyc 7532s) — to maximize PCIe bandwidth per machine.

Meanwhile, any kind of ML prediction is going to be a CPU (or maybe GPU) -bottlenecked workload. If you have 64 CPU cores in a machine, then you can only be doing 64 ML predictions at a time on that machine. You might be able to resolve any individual prediction "quickly"; but unlike an IO-bottlenecked workload, that "quickly" doesn't involve ever blocking + yielding the CPU to other workloads while waiting on anything; it's solid 100%-pinned CPU-cycles on that core, all the way through the prediction. There is no packing efficiency; running KN predictions across N cores makes each query take (slightly more than) K times as long to run.

This is why so many phones and other low-power devices are shipping with "AI/ML accelerators": putting ASICs in, tuned to run specific ML-model architectures faster, can vastly lower the power budget for the device as a whole, as running (concurrent) models on the device would otherwise have to ramp up the CPU to its highest frequency and pin it at 100% to do one of these predictions.

Re:Scaling PostgresML to 1M Requests per Second by montanalow on Tuesday November 08, 2022 @03:31PM (#33523893)
RAM and the Postgres shared buffers, as well OS page cache can also be important factors when there is an active working subset, e.g. the active sessions on a website might be reused hundreds of times per session, with only relatively small portion of them active at any time.

Shared RAM across all cores can be a reason to use fewer larger machines rather than more smaller ones in such a case. Postgres does give you options either way though.

Re:Scaling PostgresML to 1M Requests per Second by derefr on Wednesday November 09, 2022 @12:36AM (#33527859)
Yup. In both cases, I was presuming a worst-case workload — e.g. an OLAP workload where you have to read all the data in the DB to answer a query, and "all the data" is far larger than RAM; or 10k concurrent queries from different tenants who all care about different things. That's really where bottlenecks will hit you. "More RAM" helps when your problems aren't worst-case problems. :)
Re:Scaling PostgresML to 1M Requests per Second by gmhafiz on Tuesday November 08, 2022 @10:19AM (#33519906)
For perspective, that single server is - 1TB of DDR4 RAM - 3TB of NVME SSD storage - 192 physical 2.7GHz cores (384 with hyperthreading
Re:Scaling PostgresML to 1M Requests per Second by fulafel on Thursday November 10, 2022 @10:00AM (#33547411)
And AWS vCPUs = SMT threads, or Hyperthreads(tm) in Intel speak for anyone comparing to the machines described in the PostgresML post. (Which were answering ML ops, not simple DB queries)
Re:Scaling PostgresML to 1M Requests per Second by Foobar8568 on Tuesday November 08, 2022 @12:00PM (#33521274)
Sql Server + R 6 years ago, scoring transactions at 1M/sec https://blog.revolutionanalytics.com/2016/09/fraud-detection...
Re:Scaling PostgresML to 1M Requests per Second by bagels on Tuesday November 08, 2022 @03:37PM (#33523967)
Right, if we're allowed horizontal scaling, 1M instances, 1request/s would do the trick.