6 ms·
PostgresML is 8-40x faster than Python HTTP microservices
- davewbrwn 4y agoIs it easy to install on aws aurora postgresql?
- grzm 4y agoIt looks like it's a PostgreSQL extension, and probably not one supported by AWS RDS for PostgreSQL or Aurora PostgreSQL. AWS generally only supports extensions that ship with PostgreSQL (and maybe some limited third-party extensions?). The lists of supported extensions are here: * https://docs.aws.amazon.com/AmazonRDS/latest/PostgreSQLReleaseNotes/postgresql-extensions.html https://docs.aws.amazon.com/AmazonRDS/latest/PostgreSQLRelea... * https://docs.aws.amazon.com/AmazonRDS/latest/AuroraPostgreSQLReleaseNotes/AuroraPostgreSQL.Extensions.html https://docs.aws.amazon.com/AmazonRDS/latest/AuroraPostgreSQ...
- deepstack 4y agoplease just run postgresql in EC2, there are many presentation why that is preferred over RDS.
- breckenedge 4y agoNice to see! Would have liked to have seen a more useful application of XGBoost, but I hope this helps alleviate the Python monopoly on ML.
- learndeeply 4y ago"ML" was never monopolized by Python. Boosted decision trees, as the post demonstrates, are commonly done in Matlab, R, or Julia. Deep learning however is 99% Python interface.
- deleted 4y ago[deleted]
- chaps 4y ago"In Python, most of the bottleneck comes from having to fetch and deserialize Redis data." This isn't a fair comparison. Of freaking course postgres would be faster if it's not reaching out to another service.
- montanalow 4y agoAs a contributor, I think it's interesting when comments focus on the language (Python vs Rust) vs the architecture (local vs remote). Inference is embarrassingly parallelizable, with Python Flask or Postgres replicas. I think the interesting thing is that data retrieval costs tend to dominate other costs, and yet are often ignored. ML algorithms get a lot focus and hype. Data retrieval, not as much.
- chaps 4y agoFor anyone who skips the intro and just goes to the results, this is what they see: https://imgur.com/tEK73e8 https://imgur.com/tEK73e8 A suggestion: clean up the blog post's charts and headers to make it much, much more clear that what's being compared isn't python vs postgresml.
- montanalow 4y agoAnother suggestion: Don't build you identity around a language or platform. They come and go. Except SQL. It's been around for longer than either of us.
- chaps 4y agoAgreed, which is why I use postgres for most of my work unless I can't avoid it.
- deepstack 4y agothat is reason many older developer tend to do everything biz logic etc all in db store procedure/functions/view, etc. The cost of getting the data is native, no connection pooling needed, and with V8/python integration in the PG, it is non trivial what language you use. If you are dealing with large amount of data in a db, why not just do everything there. DB like sql has cursor, merge, that makes manipulating large set of data much easier than moving it on to another language environment.
- habibur 4y agoPython is slow for ML. People will take time to realize it. The claim that most of the work is done in GPU -- covers only a small fraction of cases. For example, in NLP a huge amount of pre and post processing of data is needed outside of the GPU.
- __mharrison__ 4y agoSpacy is much faster on the GPU. Many folks don't know that Cudf (a Pandas implementation for GPUs) parallelizes string operations (these are notoriously slow on Pandas)... shrug...
- westurner 4y agoApache Ballista and Polars do Apache Arrow and SIMD. The Polars homepage links to the "Database-like ops benchmark" of {Polars, data.table, DataFrames.jl, ClickHouse, cuDF*, spark, (py)datatable, dplyr, pandas, dask, Arrow, DuckDB, Modin,} but not yet PostgresML? https://h2oai.github.io/db-benchmark/ https://h2oai.github.io/db-benchmark/
- minhazm 4y ago> Python is slow for ML The python runtime is slow in general. But anyone using it for ML is not actually using the python runtime to do any of the heavy lifting. All of the popular ML/Ai libraries for python like tensorflow, pytorch, numpy, etc. are just thin python wrappers on top of tens of thousands of lines of C/C++ code. People just use python because it's easy and there's a really good ecosystem of tools and libraries.
- madduci 4y agoYou forgot that there's also an overhead converting data from/to C++ and Python as well. Sure, Python can make you start fast with any ML project, but when you have to deal with heavy-duty tasks, a switch to pure C++/Rust/Any-Compiled-Language implementations might be a good investment in terms of performance and cost-savings, especially if the above heavy tasks are done in any cloud platform
- koyanisqatsi 4y agoVery interesting architecture. Article mentions XGBoost but what if I want to run another kind of algorithm? How does PostgresML support that use case?
- sanxiyn 4y agoYou would need to add support to PostgresML. It doesn't seem to have an extension mechanism, maybe in the future. It seems easy enough, and you can use any Python libraries through Rust's PyO3 binding. PostgresML includes an example using HuggingFace transformers.
- koyanisqatsi 4y agoThat makes sense. Thanks.
- levkk 4y agoWe have LightGBM also. The entire Scikit library is available (although via a Python wrapper) and a couple algorithms from Linfa (a Rust Scikit rewrite). We will be adding more algorithms and move to Rust entirely for v3.0.
- koyanisqatsi 4y agoVery cool.
- a-dub 4y agoi always thought that elasticsearch would make a good host for a ML enabled datastore. building indices and searching them are similar computational paradigms to training and inference and the scaling framework would lend itself well to both computation heavy training and query/inference. although i dunno if it has good support for lots of floats. and i guess all the ml code would have to be java.
- anonu 4y agoKinda duh if your data never leaves the process space. Should be faster IMO...
- Jweb_Guru 4y agoRight, so why not leave it there? I believe that is the point here, there's no trickery going on.
- localhost 4y agoIt seems like Postgres isn't really doing anything here in the benchmark besides acting as a host for XGBoost? It needs to load the model parameters from the database whereas the Python microservice is reading the model parameters from a model.bin file in the filesystem. Both are one-time costs presumably (I'm guessing the SQL that loads the model keeps the model around in memory which seems reasonable given its performance gap to Python). So it seems like what is needed is a better host for XGBoost models instead of having to install, maintain and launch an entire database? Or am I missing something here?
- montanalow 4y agoI think what you're missing is that XGBoost is worthless without data to use for inference. That data can come from in process, or over the wire. One is fast, one is not.
- theamk 4y agoWell, imagine nginx plugin that runs XGBoost. Or even standalone Rust/C++ microservice which provides XGBoost via standard http interface. The data might come from filesystem, or loaded from network location on startup/reload and kept in memory. Basically, postgresql is a stateful service, and stateful services are always major pain to manage -- you need to back them up, migrate, think about scaling... Sometimes they are inevitable, but that does not seem to be the case here. If you have CI/CD set up, and do frequent deploys, it will be much easier and more reproducible to include models in build artifact and have them loaded from filesystem along with the rest of the code.
- montanalow 4y agoStateful services are indeed more painful to manage than non stateful ones. Ignoring state (data fetch time) for ML as if the model artifact is the only important component is... not a winning strategy.
- learndeeply 4y agoPython can be fast if you don't intentionally cripple it. Doing the following will be most likely a lot faster than postgresml: - replace json (storing data as strings? really?) with a binary format like protobuf, or better yet parquet - replace redis with duckdb for zero-copy reads - replace pandas with polars for faster transformations - use asynchronous, modern web framework for microservices like fastAPI - Tune xgboost CPU resource usage with semaphores
- montanalow 4y agoLow effort comment that didn't read the post. - Multiple formats were compared - Duckdb is not a production ready service - Pandas isn't used You seem to be trolling.
- learndeeply 4y agoHow would I be able to respond to the post in detail if I didn't read it? What a bizarre, defensive response. To address your points: - Multiple formats were compared Yes, but not a zero-copy or efficient format, like flatbuffer. It was mentioned as one of the highlights of postgresML: > PostgresML does one in-memory copy of features from Postgres > - Duckdb is not a production ready service What issues did you have with duckdb? Could use some other in-memory store like Plasma if you don't like duckdb. > - Pandas isn't used that was responding to the point in the post: > Since Python often uses Pandas to load and preprocess data, it is notably more memory hungry. Before even passing the data into XGBoost, we were already at 8GB RSS (resident set size); during actual fitting, memory utilization went to almost 12GB. > You seem to be trolling. By criticizing the blog post?
- jb_gericke 4y ago+1 and Gunicorn with an ASGI server/Uvicorn
- akx 4y agoA good start would be to not do silly things like body = request.json key = json.dumps(body) in the prediction code to begin with: https://github.com/postgresml/postgresml/blob/15c8488ade86b0b68be52aa8af40a1152d292c06/pgml-docs/docs/blog/benchmarks/python_microservices_vs_postgresml/predict.py#L17-L18 https://github.com/postgresml/postgresml/blob/15c8488ade86b0...
- urcyanide 4y agoIf you are trying to compare the performance as a ML service, maybe you should try to compare it with other ML model serving frameworks like https://github.com/mosecorg/mosec https://github.com/mosecorg/mosec or https://github.com/bentoml/BentoML https://github.com/bentoml/BentoML. Flask/FastAPI are not built for ML services.
- est 4y ago
- johndough 4y agoThis benchmark is not very useful. To get any real insights, you'd have to benchmark every single line of the prediction function (called "api") to see where the slowdown is actually coming from https://github.com/postgresml/postgresml/blob/15c8488ade86b0b68be52aa8af40a1152d292c06/pgml-docs/docs/blog/benchmarks/python_microservices_vs_postgresml/predict.py#L16 https://github.com/postgresml/postgresml/blob/15c8488ade86b0... Everything else is just speculation.
- 8bitwhiterabbit 4y agoAnything over 20x approaches the theoretical limit. And a services speed will only increase overall latency by the fraction it's used.
- atoav 4y agoThere are many reasons to rely on python, speed is not one of them. You may still have speed when using python if you do it correctly, but this is more or less despite using python not because of it. One reason for python in my eyes is maintainability: Well written python code can be easily understood and nearly as easily modified. Well written python code becomes close to what pseudo code would look like. This is the reason python's weird jungle of dependency managment tools is so out of place for the language: It is a maintenance nightmare. I would describe myself as someone who is very able to deal with those problems, yet they are such an utter waste of time and energy.
- rcarmo 4y agoThis is disingenuous since we’re not even looking at the same kind of TCP connection and request handling (using persistent connections in Python typically speeds things up, going async reduces concurrency overheads, etc.). But of course iteration through any kind of dataset to get a reply would take longer in Python as well when compared to C.
- levkk 4y agoWe're using persistent connections for Python/Gunicorn as well. See the Methodology section for more details.
- deleted 4y ago[deleted]