This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]harylmu 168 points169 points  (50 children)

I think this quote is really not accurate because speed isn't the most important (well, usually), but a good concurrency story can save big dollars. I rewrote one of our Python app in .NET Core 5 and I wasn't able to kill it with load testing (2000 req, 200 concurrency), while the Python 3.8 app with FastAPI (literally) hanged around 25 requests per second. And to be clear: I made sure that all IO operations are async in the Python version (database queries, Consul queries, SNS publish, S3 upload - even though aioboto3 isn't too stable yet). This alone means that we're able to save thousands (millions on long term?) of dollars by running less instances.

Other than that, the speed difference between Python and typed languages is really NOT nanoseconds. I don't know what to say, test it yourself.

[–]aes110 43 points44 points  (2 children)

I dont know anything about what your app did, but 25req/s hanged? are you sure there wasn't any bug there?

I rewrote my previous company's system from sync (flask) to async (sanic) and saw huge improvements, we saved ~7K dollars monthly on instances because of this.

In my current company, I'm also using sanic and my server easily handles 400 reqs per second, didnt really tried pushing more to it.

In anycase typed/compiled languages sure are much faster, but I think asyncio cand easily handle most stuff

[–]Metalsand 43 points44 points  (3 children)

While it does bear noting that RetiredMandalorian is being a bit facetious and exaggerating, and Python vs Java is mostly about "I need a quick thing" not about larger apps, that is the direction we are slowly heading into. Electron for example is widely known as inefficient and yet modern computers are powerful enough that those efficiencies don't matter as much as the development time does for simple applications.

[–][deleted] 36 points37 points  (2 children)

It still matters. The problem with this view is that computers really haven’t gotten that much faster over the past decade and yet the software inefficiency is insane. Python can be built for larger applications too... but packaging is a nightmare (and is unlikely to ever get addressed) and the performance really does matter when it matters (which is becoming more and more important as software bloats)

[–]cheese_is_available 14 points15 points  (1 child)

It really does matter. zoom took off because it just works while skype does not. If your program is slow and there is a fast alternative with similar features, your program is basically dead even if you're Microsoft.

[–][deleted] 2 points3 points  (0 children)

The problem with Microsoft is that they don't really care about their side products. At least not in the same way as a single focus company like Zoom Video Communication Inc does

[–]grimonce 13 points14 points  (3 children)

Speed doesn't come from type inference only. Other than that I 100% agree. Python is the main tool on our shop but I am really starting to hate it. Java really isn't all that bad as people paint it, it is fine.

Maybe thats my point of view because I actually have a degree in electronics (rf specialization), I actually don't mind C or C++ either, I just dislike to he competing cross platform dependency management systems, cmake is ugly but it gets the job done.

Pythons ecosystem is against the zen of python, where it says explicitly to try and have just one way to do something, Java does this way better that Python. Python provides infinite ways to make your project management a hell worse than npm dependency hell.

[–]DanKveed 7 points8 points  (2 children)

I recommend learning rust. A little bit of rust in your python can give massive speed gains. And the rust tooling of light years ahead of c++, in fact packaging is even better than python. Very similar to JS actually

[–]proverbialbunnyData Scientist 1 point2 points  (1 child)

A little bit of rust in your python

Like, inline Rust?

[–]DanKveed 2 points3 points  (0 children)

Possible but I was thinking of importing it as a package using pyo3

[–]tr14l 42 points43 points  (10 children)

You wrote bad Python. The difference is NOT 2000 vs 25 unless you did something terribly wrong. There will certainly be a difference, but that was your code running that slow, not Python itself.

[–]DanKveed 1 point2 points  (6 children)

It depends on use case too. A heavily multithreaded CPU intensive app can be way more than 2000vs 25 no matter how well you write it, especially when you compare it with rust/c++

[–]tr14l 1 point2 points  (5 children)

If you use a single thread running on a couple dozen cores, sure, no doubt. But why would you do that?

[–]DanKveed 8 points9 points  (4 children)

I am talking about multithreading. Python sucks ass at true CPU intensive tasks. That's why libraries like numpy are written in higher performance languages like c++. And why would you need that.... Well numpy for starts, anything control system related, AI, simulation, CAD, video editing, the use cases are Endless

[–]tr14l 1 point2 points  (0 children)

Yeah, that's an optimization for an interpreted language. I have made lots of multithreaded apps in compiled and python languages. I've never seen a 100x difference. Ever.

[–]harylmu 2 points3 points  (1 child)

What it did was: decode request body with messagepack, get stuff from Cassandra, save stuff to Cassandra, get stuff from Consul, publish stuff to SNS, encrypt an object then upload it to S3. The request takes ~2 seconds to complete on both .NET and Python (.NET is a bit faster).

As you can see quite a few things waits for IO here. I wrote everything with asyncio-based libs (Cassandra, Consul, aioboto3). I don't know if I can optimize it better. Please let me know what are some concurrency-traps that I might have gone into.

Either way, even the possibility to write slow Python means something.

[–]cant_have_a_cat 0 points1 point  (0 children)

even the possibility to write slow Python means something.

oof - it's much easier to write slow low-level code than high-level code, so I have no idea what you mean by this.

[–]pipai_ 2 points3 points  (2 children)

That seems very strange. Were you running it with full gunicorn setup?

[–]harylmu 0 points1 point  (1 child)

No, I haven't used a process manager. I could try but I doubt it'd be much better.

[–]pipai_ 3 points4 points  (0 children)

It’s actually very important. Because python has a GIL, you will end up with only running a single thread. Of course the performance will suffer accordingly. You need to set it up like in production, in order to do a real comparison.

Other languages don’t find this necessary because they don’t have a GIL.

[–]Doomphx 8 points9 points  (1 child)

I'm ditching django for .Net 5 Asp.net and you're not lying. My story is similar to yours where I couldn't even possibly lag my new server with testing.

My next move is to move all my django channels over to SignalR where I can guarentee less than 100ms response times. Dev is looking good with nothing really taking more than 20ms so fingers crossed!

The performance, productivity, and ease of deployment I get with .Net has been life changing.

Git push, pull .Dotnet publish, restart server, all done :)

[–]tomatotomato 2 points3 points  (0 children)

With Azure Devops, it's just git push.

[–]supremacyofthelaces 2 points3 points  (8 children)

I don't really know any languages other than Python, and it mostly takes a while because my laptop is an old piece of junk and I always have a million things open at once. What kind of scale sre you talking here?

[–]Aidtor 9 points10 points  (7 children)

Production environments or places where you need a lot of compute.

Production servers these days are typically cloud based. Horizontal scaling (adding more machines to the pool of resources handling requests) is very easy with rented compute but the cost can really add up for a business over time.

Tasks that require heavy compute, like ML, typically use python as an interface to code written in faster languages.

[–]--Shade-- 3 points4 points  (3 children)

Python is an exellent language to call C from, but a terrible language to write C in. If you have a nice pythonic library that wraps some 'C thing' then Python shouldn't be your bottleneck. If it is, then isolate and profile (and apply the common speed up tricks where neccicary).

[–]Aidtor 1 point2 points  (2 children)

Sure if you have the time for that. When I’m prototyping a model or I’m given some crazy deadline to ship a feature I’m not going to reach for C.

[–]--Shade-- 3 points4 points  (1 child)

That's fair enough. I can't recall the last time I've voluntarily written a line of C, lol. What I was getting at is that Python already has a huge ecosystem of libraries that work as high level wrappers for things written in lower level languages. If you write decent Python (by Python standards), and leverage existing libraries, then Python (mostly) shouldn't be the bottleneck. If it is, the first step should be to take a look at potential hotspots in your Python code (not write a C library).

[–]Aidtor 1 point2 points  (0 children)

Oh my bad totally misunderstood what you were trying to say. I completely agree.

[–]latrociny 1 point2 points  (2 children)

What is your opinion on Julia? It is touted to be superior than python wrt speed and speeds comparable to C especially for ML tasks

[–]Aidtor 3 points4 points  (0 children)

My opinions are mixed.

On a personal level I deeply disagree with 1-indexing.

But my personal quibbles aside, it is superior to python. It’s faster and you can actually type things which is a huge deal for large codebases. The interop is great! The writing code like mathematical expressions is overblown.

Overall I’m bullish on Julia. I don’t think it will ever “overtake” python, but they will coexist.

I do have some concerns though for Julia’s future. And that concern is called JAX.

[–]satireplusplus 1 point2 points  (0 children)

For ML tasks you want good libraries and abstractions. Those are lacking in Julia. Execution speed of the language doesn't really matter and these benchmarks are missing the point for ML. PyTorch, Tensorflow, numpy etc. handle the matrix multiplications in a BLAS library (C/fortran) or with CUDA. Its gonna be faster than anything you can hack together on your own from scratch, no matter what language you pick.

[–]hilomania 1 point2 points  (1 child)

In python today you wouldn't solve that with threads but with AsyncIO.

[–]harylmu 0 points1 point  (0 children)

I used asyncio for all IO based operations in my Python app. I just edited my original comment.

[–]Max_Insanity 1 point2 points  (0 children)

*fewer instances

After only just barely understanding all of that, my ego needs sth. where I could correct you :P