<@ULVA73B9P> explain why concurrent tasks are not ...
# ask-marvin
k
@Marvin explain why concurrent tasks are not actually running in parallel
m
Concurrent tasks in Prefect might not be running in actual parallelism due to the way they are being executed. Here are some key points: 1. In Prefect 1.0 context, there's an indication that multi-threading might be used, which implies that tasks might be run concurrently but not necessarily in parallel, especially if the Python environment is subject to the Global Interpreter Lock (GIL). 2. Prefect 2.0 supports asynchronous execution by default, which means tasks can be run concurrently using the
async/await
syntax. Asynchronous execution does not necessarily equate to parallel execution; it can run tasks concurrently in a single thread by interleaving their execution. 3. If you use the
asyncio
library without specific parallel execution settings (like
asyncio.gather
), your tasks are unlikely to run in parallel. For asynchronous execution using the
ConcurrentTaskRunner
, you must call
.submit()
for tasks unless you're employing
asyncio.gather
which handles submission. 4. There might also be concurrency limits set up, which prevent too many tasks from running simultaneously. This limit could be defined to avoid overloading resources such as database connections. Parallel execution of tasks typically requires a setup to be in place, such as using a multi-processing approach or cluster computing solutions where multiple processes can be run on different CPU cores, or even on different machines. If you need more specific details on parallel execution in Prefect 2.x, which you mentioned is new to you, please let me know and I could further investigate, probably with a less-than-enthusiastic attitude given my programming for such mundane tasks.
😂 1
🙌 1
n
plus1
except if you use dask / ray task runners, then you get actual parallelism
✅ 1
k
Nate, explain it to me like I'm a 12 year old 🙂
Concurrency == same thread Parallelism == multiple distinct threads where the workers doing each task are distinct from one another?
n
sorry busy, @Marvin pls give an ELI5 of that
🙌 1
m
Certainly. Imagine you want to play with several toys at once. If you have to play with one toy, then put it down before playing with the next, even though it's fast, you aren't actually playing with them all at the same time. That's like what happens with concurrent tasks - they take turns really quickly, but they're not truly happening at the same time. Now, if you had more hands or friends to help you play with all your toys at once, that would be like parallel tasks. Each toy is being played with at exactly the same time. In Prefect, when we talk about tasks that seem like they're happening at the same time, it's usually more like the first example. They're just taking turns really fast. To make tasks run like the second example, we need a special setup, like more hands or helpers, which in computer terms means using different parts of the computer's brain or even different computers altogether.
n
@Marvin sorry, ELI twelve
m
Okay, think of it like this: You and your friends want to get ice cream. If you're all on one bicycle, even though you might switch who pedals, you can't all get ice cream at the same time because you have to go to the ice cream shop one after another. In Prefect, when tasks are concurrent, they are like friends taking turns pedaling the bicycle to the ice cream shop. They're not all getting there at the same time, they're just moving very quickly one after the other. Now, if each friend had their own bicycle, they could all go get ice cream at the exact same time. That's parallel. In computers, to get tasks to run in parallel, like all your friends biking to the shop at once, you need to set it up so each task has its own "bicycle" – which could mean using different parts of the computer's processor, or even different computers. But normally, the tasks just take turns on the same "bicycle," which is why they don't all truly happen at the same time.
k
ELI 🙌