News for hackers. Stuff that matters.
Re:Our Plan for Python 3.13 by matsemann on Thursday June 15, 2023 @10:06AM (#36340703)
GIL is one of the things that make Python an annoyance to work with. In saner languages, you could handle multiple requests at the same time, or easily spin something off in a thread to work in the background. In Python you can't do this. You need to duplicate your process, then pay the price of memory usage and other things multiple processes hinder (like communication between threads or pre-computed values now aren't shared so you need something external again). To deploy your app, you end up with 10 different deploys because each of them have to have a different entry point and separate task to fulfill.
Re:Our Plan for Python 3.13 by stinos on Thursday June 15, 2023 @11:24AM (#36341865)
GIL is one of the things that make Python an annoyance to work with

For your particular usecase, yes. Personally I've been using Python for like 20 years for various tasks and so far never got really bothered by the presence of it once. Worst case was having to wait somewhat longer for things to complete. For my case: still worth it compared to making things multithreaded. And async fixed the rest. And the things which I actually need to be fast aren't usually in Python anyway. I'm not saying the GIL should stay, it's just that it doesn't seem as much of a problem in the general land of Python. Or in other words: how many Python users out there even know what GIL means and does?

Re:Our Plan for Python 3.13 by stult on Thursday June 15, 2023 @12:44PM (#36343203)
> For your particular usecase, yes.

The use case they are describing is a standard web server or web application. That's a pretty important and widely applicable use case to dismiss out of hand as "your particular usecase".

Re:Our Plan for Python 3.13 by semiquaver on Thursday June 15, 2023 @01:34PM (#36343940)
The GIL is not held during IO, which is what most web applications and web servers should be spending the vast majority of their time doing.

https://docs.python.org/3/library/threading.html

If that’s too limiting, preforking and other forms of process-based parallelism are a tried and true approach that has been used for years to run python, ruby, PHP, and once upon a time Perl web applications at enormous scale. The difference between threads and processes on Linux is relatively minor.

Saying that python doesn’t work for web application use cases because of the GIL is frankly sort of bizarre given the large number of python web applications in the wild chugging along delivering value.

Re:Our Plan for Python 3.13 by jrochkind1 on Thursday June 15, 2023 @02:10PM (#36344408)
> The GIL is not held during IO, which is what most web applications and web servers should be spending the vast majority of their time doing.

While this has been oft-repeated for years, more or less language-independently, I have become convinced it no longer accurately describes ruby on rails apps. People still say it about ruby/rails too though. But my rails web apps are spending 50-80% of their wall time in cpu, rather than blocking on IO. Depending on app and action. And whenever I ask around for people who have actual numbers, they are similar -- as long as they are projects with enough developer experience to avoid things like n+1 ORM problems.

I don't have experience with python, so I can't speak to python. but python and ruby are actually pretty similar languages, including with performance characteristics, and the GIL. Python projects tend to use more stuff that's in C, which would make more efficient use of CPU, so that could be a difference. (Also not unrelated to what we're talking about!)

But I have become very cautious of accepting "most web applications are spending the vast majority of their time on io blocking rather than CPU" as conventional wisdom without actually having any kind of numbers. vast majority? I would doubt it, but we need empirical numbers.

Re:Our Plan for Python 3.13 by zarzavat on Friday June 16, 2023 @12:02AM (#36351063)
But are they CPU limited?

There’s a difference between spending most of your time in CPU, and being CPU limited. If I’m serving 10 requests/second then even if I’m 90% CPU and 10% IO, it doesn’t matter because I’m 99% idle.

My mental model for a very high-interpreter overhead language like Ruby or Python for webdev, is that it is appropriate for sites that don’t see that much absolute interactive traffic. e.g. it’s good for a blog where you can put a cache in front of it, or an intranet service where you control the number of users. I would never use Python for a fully interactive high traffic service sitting on the open internet. There are languages that are much better at that.

Re:Our Plan for Python 3.13 by miketheman on Friday June 16, 2023 @08:13AM (#36355279)
> I would never use Python for a fully interactive high traffic service sitting on the open internet.

So, nothing like Instagram, Dropbox, or YouTube?

Re:Our Plan for Python 3.13 by jrochkind1 on Friday June 16, 2023 @09:33AM (#36356318)
> If I’m serving 10 requests/second then even if I’m 90% CPU and 10% IO, it doesn’t matter because I’m 99% idle.

I get your point I think, but that depends on the capacity of the host you are on, and how much the total amount of CPU is, not just the proportion vs IO.

Rails may not be a good comparison to python, perhaps it is especially a CPU hog, but I have definitely seen rails apps for which 90% CPU and 10 rps would saturate the hosts CPU yeah.

I mean, the math is--- if you have a 111ms response time, 90% of that was spent on cpu (90% of 111 is 100), and you have 10 requests per second (100ms * 10 == 1 second) -- you are now saturating a single core cpu, right? Those are not crazy numbers.

But of course Rails has a GIL too -- so you can be "cpu limited" with spare CPU available on other cores, depending on how you've set things up -- that's the original conversation topic here, right? How the GIL may or may not complicate attempts to make efficient use of resources?

For what we're talking about, the issue I guess is whether they would be CPU limited with the GIL but not without the GIL. Which seems plausible.

(And of course Rails is very very commonly used "for a fully interactive high traffic service sitting on the open internet" -- so I don't see why python, a language with pretty similar relevant characteristics, couldn't or shouldn't be? Despite having little python experience, the issues with GIL are something very very similar in Ruby/Rails, is why I'm in the conversation)

It's easy to start getting confused about what we're talking about here, or be talking about different things at once.

Re:Our Plan for Python 3.13 by mlyle on Thursday June 15, 2023 @03:12PM (#36345145)
> which is what most web applications and web servers should be spending the vast majority of their time doing.

Sure... but if you have dozens of threads spending most of their time doing I/O, that still leaves many threads wanting to do things other than I/O.

> The difference between threads and processes on Linux is relatively minor.

Except having any shared state between processes is painful. If you're hitting an outside database for everything, it's fine.

Re:Our Plan for Python 3.13 by nunuvit on Thursday June 15, 2023 @01:25PM (#36343825)
The dismissiveness really goes the other way. Pythons like IronPython and Jython don't have a GIL. CPython does because it's primarily a glue language for extensions that might not be thread-safe. Web apps were given huge accommodation with async, so you can't say their needs are being dismissed. Why must we break the C in CPython for a use-case that could use one of the GIL-free Pythons?
Re:Our Plan for Python 3.13 by nomel on Thursday June 15, 2023 @01:04PM (#36343527)
> The use case they are describing is a standard web server or web application.

I believe this is what they were referring to when they said “async fixed the rest”.

Re:Our Plan for Python 3.13 by stinos on Thursday June 15, 2023 @03:16PM (#36345197)
That's somewhat out of context. With the bit you quoted I meant "sure working around the GIL by implemening a web server in that particular way is annoying". I'm not saying that "web server" as a whole is not important or not widely applicable, merely that amongst all other usecases and applications of Python out there, web servers are just one of many. And the particular implementation stated like "10 different deploys" is even a subset of that 'one' and as explained by fellow comments, probably not the most appropriate one.
Re:Our Plan for Python 3.13 by Fiahil on Thursday June 15, 2023 @05:53PM (#36347131)
I think Data Scientists would like a word with you. They have plenty of time since their parallel pipeline was OOMKilled.
Re:Our Plan for Python 3.13 by paulddraper on Thursday June 15, 2023 @11:29AM (#36341940)
Other languages do that: JavaScript, PHP, Erlang.

Python multiprocessing is pretty usable.

Mulithreading has more footguns then the rest of programming combined.

I'm not convinced Python's approach is that bad in practice.

Re:Our Plan for Python 3.13 by mohaine on Thursday June 15, 2023 @03:03PM (#36345057)
It is, until the GIL bites you in the ass. As it is you get different behavior if your call is calling out to external code vs being pure python. Note that you really don't know if a random function call is python or wrapping external class so you really get random behavior.

The time it got me was a thread just to timeout another process. Tests worked great but the timeout didn't work in production because the call it was wrapping was calling out to C code so nothing would run until the call returned. We even still got the timeout error in the logs and it looked like it was working (it even tossed the now waited for valid results), but not at the time of the timeout but after the call finally returned a few hours later.

Re:Our Plan for Python 3.13 by paulddraper on Thursday June 15, 2023 @04:16PM (#36345891)
So.... It would have been better if GIL were even more aggressive?
Re:Our Plan for Python 3.13 by ActorNightly on Thursday June 15, 2023 @02:26PM (#36344613)
The other languages are not saner. You are basically saying "Python GIL is annoying because I can't write parallel processing performant code in Python". Python has never been and is not a performant language. Its designed for rapid and easy development.

The multiprocessing+asyncio in Python fulfills the aspect of utilizing all the resources, albeit at a higher memory cost, but memory is dirt cheap these days. You have a master process and then worker threads. For all things that you would write in Python, where in >90% cases you are network latency limited, the paradigm of a master process and worker processes with IPC on unix sockets works extremely well. Set up a web app with fast api/gunicorn master/uvicorn workers, and it will be plenty fast enough for anything you do.

Re:Our Plan for Python 3.13 by oconnor663 on Thursday June 15, 2023 @05:09PM (#36346537)
> you could handle multiple requests at the same time

To be fair to Python and the GIL, it's totally capable of parallelizing requests when most of the work is network-bound, which is probably the common case. And when the work is CPU-bound, but the CPU-intensive part is written in C, it's also possible for C to release the GIL. So it's really only "heavy computational work directly in Python" programs that are affected by this. (On the other hand, Python applications do naturally expand to look like this over time...)

Re:Our Plan for Python 3.13 by slt2021 on Thursday June 15, 2023 @06:18PM (#36347424)
No it is not.

If you want to reach peak performance single-threaded app with no locks is the way to go, and work being sharded (not shared) among multiple single-threaded apps.

Multi-threaded apps with shared state introduce more complexity, than the performance when compared to multiple single-threaded apps running asyncio event loop.

For example LMAX Disruptor

Re:Our Plan for Python 3.13 by gnulinux on Thursday June 15, 2023 @09:33PM (#36349766)
This is your opinion, but many disagree. I personally find processes infinitely easier to deal with than thread, it's not even a discussion in my mind. For me, threads are banned from usage, until it's absolutely necessary to do so. When I write code in C++ there are cases where a problem cannot be solved unless threads are used. It's fine to use threads there. For everything else I appeal to either multiprocessing or `async` concurrency.
Re:Our Plan for Python 3.13 by hgs3 on Thursday June 15, 2023 @09:56PM (#36349975)
> You need to duplicate your process, then pay the price of memory usage ...

I believe the implementation of the Python multiprocessing package uses fork() on *nix systems which means memory should be copy-on-write.

Processes do have the advantage of being self-contained meaning if one crashes, then it will not take down the entire system. Also, the message passing model can theoretically scale to processes running on separate hardware. Thread's cannot do that.