Async Rust Is A Bad Language | Prime Reacts

แชร์
ฝัง
  • เผยแพร่เมื่อ 24 ก.ย. 2023
  • Recorded live on twitch, GET IN
    / theprimeagen
    Article: bitbashing.io/async-rust.html
    Author: Matt Kline | / @slavik262
    MY MAIN YT CHANNEL: Has well edited engineering videos
    / theprimeagen
    Discord
    / discord
    Have something for me to read or react to?: / theprimeagenreact
    Hey I am sponsored by Turso, an edge database. I think they are pretty neet. Give them a try for free and if you want you can get a decent amount off (the free tier is the best (better than planetscale or any other))
    turso.tech/deeznuts
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 224

  • @kyguypi
    @kyguypi 7 หลายเดือนก่อน +256

    I mean, the rust book does encourage channels and also quote the go docs "don't communicate by sharing memory, share memory by communicating".

    • @KyleSmithNH
      @KyleSmithNH 7 หลายเดือนก่อน +20

      I think the main issue Rust has in this space is that you're not really all that likely to stumble on an actor model as a solution. You're far more likely to try to run two functions at once and find out the borrow checker is upset but it gets less upset if you Arc (it likely even recommends this). The path you're pushed on is the hard path, and it's partly because of the types of projects that are using Rust in the large.

    • @alexandrep4913
      @alexandrep4913 7 หลายเดือนก่อน +6

      I'm not entirely sure what that abstraction is trying to say without context. Sound cool though

    • @kyguypi
      @kyguypi 7 หลายเดือนก่อน +4

      @@KyleSmithNH yeah, my take (and this might be what you're saying) is more that Mutex is more in line with Rust's raison d'etre. It exists to get as close to the bare metal as possible (as rust often does), so it kind of betrays that to enforce anything that adds overhead, even if its typically a bad idea to go without. Like, Lamborghini might strongly suggest you obey the speed limit, but they're certainly going to make it possible to speed feloniously. Probably. I don't write php.

    • @Psy45Kai
      @Psy45Kai 7 หลายเดือนก่อน +3

      Thanks, I thought the same! The article states Hoare and the solution to all the problems: channels! But then sh*ts about how async rust sucks using anything other than channels...

    • @Reydriel
      @Reydriel 7 หลายเดือนก่อน

      @@Psy45Kai The point is that Rust doesn't lead you down the path of using them naturally, therefore many make the mistake of not doing so. Whereas other languages make it much easier

  • @minikame2272
    @minikame2272 7 หลายเดือนก่อน +119

    Parallellism is several chefs preparing different dishes at the same time, concurrency is one chef preparing multiple dishes by flitting between tasks as efficiently as possible, but always one task at a time.

    • @jacekkurlit8403
      @jacekkurlit8403 7 หลายเดือนก่อน +8

      That's the best explanation of parallel vs concurrent I have ever read. I'm stealing this.

    • @ChrysusTV
      @ChrysusTV 7 หลายเดือนก่อน +5

      Concurrency is simply what people call multi-tasking. Very few people actually do multiple things simultaneously for any consequential amount of time. They just rapidly (for a human) task switch.

    • @wdestroier
      @wdestroier 7 หลายเดือนก่อน +1

      ​@@jacekkurlit8403No, I am stealing this explanation

    • @nodidog
      @nodidog 7 หลายเดือนก่อน

      Great way of simplifying a concept that people often struggle with for a while!

    • @BenAshton24
      @BenAshton24 5 หลายเดือนก่อน

      To the best of my understanding: Parallelism is a subset of concurrency. Concurrency just means running at the same time which includes parallelism. Parallelism implies concurrency, but concurrency doesn't necessitate paralelism. Concurrency is both one chef or many chefs. Single threaded concurrency is explicitly a single chef.

  • @TheCalcaholic
    @TheCalcaholic 7 หลายเดือนก่อน +37

    Concurrency is how people with ADHD process their todo list

    • @markmcdonnell
      @markmcdonnell 7 หลายเดือนก่อน +1

      I feel seen 😂

    • @cornoc
      @cornoc 7 หลายเดือนก่อน +4

      concurrency is what everyone really does when they pretend to be "multitasking", except their brains have a very small amount of memory to store those tasks in the queue and a very slow single-core task runner whose limited attention is split among the tasks evenly

    • @StinkyCatFarts
      @StinkyCatFarts 13 วันที่ผ่านมา

      Without joining

  • @EricSampson
    @EricSampson 7 หลายเดือนก่อน +29

    As trivia, C# creates hot tasks and F# creates cold tasks (and has a lot finer control of them, in general)

    • @ruanpingshan
      @ruanpingshan 7 หลายเดือนก่อน +1

      Oh interesting that it's different.

    • @Kane0123
      @Kane0123 7 หลายเดือนก่อน +3

      Clearly dotnet wins the language competition

    • @midlFidl
      @midlFidl 7 หลายเดือนก่อน +10

      f# is so underrated

  • @thingsiplay
    @thingsiplay 7 หลายเดือนก่อน +41

    I tried to convert a Python program with Async into Rust Async. I'm still not finished, but got most things done. It's really hard to do, even though the logic of the program is already solved.

    • @orbatos
      @orbatos 7 หลายเดือนก่อน +2

      You'll have to relate the gains.

    • @youtubeenjoyer1743
      @youtubeenjoyer1743 7 หลายเดือนก่อน +1

      Python async is absolutely useless even if you use uvloop. Just using a huge threadpool always beats asyncio solutions in throughput AND latency.

    • @Lucas-mp5dw
      @Lucas-mp5dw 7 หลายเดือนก่อน

      @@youtubeenjoyer1743 if i'm not mistaken, python 3.12~13 will improve this.

  • @azratosh
    @azratosh 7 หลายเดือนก่อน +60

    Honestly, the article makes some really good points, but after I've been learning async Rust for quite some time (and I have to admit, the learning curve is steep if you *really* want to get to the spicy parts), I feel like it's a complete exaggeration that async Rust is bad. The Tokio runtime provides enough things to not have function coloring be a problem, namely tokio::task::spawn_blocking and tokio::task::block_in_place. Go doesn't have function coloring problems because it's all async under the hood anyway. Go also actually does something similar to tokio::task::block_in_place for blocking code. I agree that this is where Go shines, but the projects I work on *require* the control that Rust provides; Go is just not an option at all in this case.
    It's not easy, but if there is one thing I am more tired of than complexity, then it's complexity being hidden for the sake of simplicity. Async Rust doesn't hide anything from me, and that's exactly what I need.

    • @metaltyphoon
      @metaltyphoon 7 หลายเดือนก่อน +7

      If there wasn’t a function coloring problem, we would be using the std library when doing async work yet thats not the case.

    • @AndrewBrownK
      @AndrewBrownK 7 หลายเดือนก่อน +5

      last sentence is absolutely on point, and why Rust is truly special

    • @azratosh
      @azratosh 7 หลายเดือนก่อน +4

      @@metaltyphoon I think I didn't manage to get my point across properly (that's on me); of course function coloring still exists, what I meant is that it's not a *problem* with Tokio. For example, Tokio's channels e.g. can send and receive messages in a blocking context, too. Let's say you have a worker thread (plain old std::thread::Thread somewhere) that's doing synchronous stuff. You can give that thread the receiver of a tokio::channel, and it will be able to call blocking_recv(), or vice versa, blocking_send() on a sender. You *can* therefore "go back and forth" between sync and async contexts. One just needs to learn how to do so.
      That's why I personally don't consider function coloring a problem.
      Now, my points are heavily relying on Tokio here; if I had to build my own runtime, I would have to build all of those facilities myself, which I admit would be a PITA. But that's why we have Tokio.

    • @JaconSamsta
      @JaconSamsta 7 หลายเดือนก่อน +5

      "the learning curve is steep if you really want to get to the spicy parts"
      But you honestly don't have to learn *that* much, for async to be very usable. I feel like people sometimes treat it as if they had to write their own runtime from scratch. Most of the time it's writing tokio::spawn instead of std::thread::spawn and using the async version of calls that would usually be blocking.
      And for some things it's even easier. Graceful shutdown (of the whole application, or parts of it) is a breeze with the tools tokio provides. And things like tokio-console are a godsent for taking a peek into a running program.
      "Async Rust doesn't hide anything from me, and that's exactly what I need."
      Eh, I personally think there is a bit too much magic involved. As with anything: If you understand the magic, it ceases to be magic. And to Rusts credit, at least it makes understanding said magic possible. But I do think there was room to be more transparent with the whole thing.
      I'd like to roll my own generators for instance, instead of having them perpetually locked away in nightly.

    • @jessicaclendinen7386
      @jessicaclendinen7386 7 หลายเดือนก่อน +2

      I feel the stuff about Arc is really exagerrated. I mean I've used it for init/config stuff but not like, talking to database, moving stuff over the network at runtime... I think if their program is spending a lot of time ref counting in Arcs it could be rewritten

  • @adityabanka_iso
    @adityabanka_iso 7 หลายเดือนก่อน +65

    I had a very profound realization, I have been watching you videos for the past couple of months and have learned more than I have in my last 2 years of being a CS undergrad. Conceptual things that I though were clear to me, being completely rewritten in my head. Thank you soo much. This has to be the most entertaining way I have ever gone over concurrency, it just clicked.

    • @adityabanka_iso
      @adityabanka_iso 7 หลายเดือนก่อน +5

      @@mythbuster6126 I was talking more as getting a new perspective to the problem, surely I'll check Rob out. This was a very new take to me, thought it was very intriguing. I am still learning the craft, thank you for pointing in the right direction.

    • @paulorubebe7308
      @paulorubebe7308 7 หลายเดือนก่อน

      ​@@mythbuster6126 actually, it makes sense. Pls, correct me if I am wrong. Two threads running concurrently on the same CPU core do not actually run at the same time or in Parallel.
      The OS scheduler decides which one in the ready state runs. Say it begins with thread A and for some reasons A is interrupted (timer interrupt) the CPU then becomes free and the OS scheduler begins executing thread B. B either runs till it finishes or itself is interrupted (another timer interrupt) and the OS continues to execute thread A till A finishes and it continues with B till it finishes.
      That's how concurrency works. Say these two threads were working on the same file(with critical sections) it would be easy to get into a race condition here. Hence the need for locks, condition variables, and/or semaphores.

    • @ryanshea5221
      @ryanshea5221 7 หลายเดือนก่อน +1

      I've been coding for 10 years and watching Prime's videos has made me rethink a lot

    • @artembaguinski9946
      @artembaguinski9946 2 หลายเดือนก่อน

      @@paulorubebe7308 ackchuwally, in CPUs with simultaneous multithreading (SMT, or hyperthreading, HT, if you're Intel) several threads running concurrently on the same CPU core do actually run at the same time or in parallel. Executing an instruction takes several "stages" and multiple stages can run simultaneously. They can process the instructions from the same thread, which CPU expects will follow one after another, or instructions from several threads could be interleaved: while finishing an instruction from thread A it could be starting an instruction from thread B and preparing the next instruction from thread A. On the next tick it would be finishing B, starting A and preparing B etc (here I imagined a hypothetical core with three stages - prepare, start and finish, in actual CPUs there can be more stages, so even more instructions from 1 or more threads may be processed simultaneously).

  • @dnullify100
    @dnullify100 7 หลายเดือนก่อน +35

    You very often say "I love rust for CLI tools", can you maybe go over some you've built and what approaches you follow?

    • @Reydriel
      @Reydriel 7 หลายเดือนก่อน +5

      He's mentioned before that he uses Rust at his job in Netflix, so maybe he can't exactly show them to us lol

  • @ceigey-au
    @ceigey-au 7 หลายเดือนก่อน +5

    More trivia: Meteor JS has a forked version of Node 14 using a Fibers extension to do "colourless" concurrency instead of await/async. Meteor 3.0 will be going 100% async to get away from that weird fork situation though, so it's sort of the end of a weird parallel universe of JS concurrency (pun not intended).

  • @sebred
    @sebred 7 หลายเดือนก่อน +8

    Jon Gjengset has a great stream about pinning and unpinning

  • @Iceman259
    @Iceman259 5 หลายเดือนก่อน +4

    The fact that there is this perpetual need to re-explain and argue about concurrency vs parallelism makes me feel really secure about my continuing employment.

  • @rumplstiltztinkerstein
    @rumplstiltztinkerstein 7 หลายเดือนก่อน +7

    One thing I learned about Rust is that we can't try to be big brained with it. Often it is better to use the simplest solution possible instead of just trying to specify exactly how everything should work. Better to avoid fancy code as much as possible to avoid the weirdest bugs.

    • @himboslice_
      @himboslice_ 7 หลายเดือนก่อน +3

      sounds like you'd like go lol

    • @rumplstiltztinkerstein
      @rumplstiltztinkerstein 7 หลายเดือนก่อน +2

      @@himboslice_Definitely.

    • @justin_ooo
      @justin_ooo 7 หลายเดือนก่อน +3

      @@himboslice_ i love Rust and Go for very different reasons but they're both easily amongst the best programming languages in the world

    • @vadzimdambrouski5211
      @vadzimdambrouski5211 4 หลายเดือนก่อน

      That's a recipe for a slow code. With that approach it's better to just write Go instead and get faster performance.

    • @rumplstiltztinkerstein
      @rumplstiltztinkerstein 4 หลายเดือนก่อน +1

      @@vadzimdambrouski5211 I didn't explain my point very well. I apologize. What I think it is best to say is "Better to not try reinventing the wheel when coding in Rust every time. There is most likely a crate that does what you need. Whatever it is."

  • @conceptrat
    @conceptrat 7 หลายเดือนก่อน +1

    I used to do this on an old IBM S360 reducing my shifts from 9-10 hours to only 4. Two tape units and printer running flat out. And me smashing keys to run the JCL that I'd split up to run the stock control and invoicing code at the same time. Hehe. No parallel tasks of the same code though.

  • @Tony-dp1rl
    @Tony-dp1rl 7 หลายเดือนก่อน +38

    It is kinda ironic to me, or surprising, that WebWorkers in JavaScript actually have one of the best models for parallelism going.

    • @PanSzymek
      @PanSzymek 7 หลายเดือนก่อน

      wat

    • @ra2enjoyer708
      @ra2enjoyer708 6 หลายเดือนก่อน +2

      They don't work in private browsing mode, so you have to write a conditional init logic (async ofc) for any function which can potentially interact with workers so it could work without them (potentially even after initialising with them). And don't forget interaction with workers incurs serialization/deserialization overhead, so you also want to write some sort of streaming logic on top. Which means you are going to write statically unoptimizable spaghetti and typescript makes it very painful to write cross-environment code like this. Good luck debugging all of that.

  • @Omnifarious0
    @Omnifarious0 7 หลายเดือนก่อน +3

    Concurrency is about having multiple tasks running simultaneously from a conceptual standpoint. Parallelism is about literally being able to execute more than one CPU instruction at a time. Which is made somewhat weird by the fact that pipelining makes even a single core CPU engage in parallelism even though there is no concurrency.

    • @JaconSamsta
      @JaconSamsta 7 หลายเดือนก่อน +2

      That's certainly a correct definition of parallelism, but I would constrain it to "executing more than one stream of instructions at a time".
      A CPU can definitely do fancy out-of-order and super-scaler stuff, but that only works as long as it ends up being sequential at the other end again.
      Of course a superscalar architecture, pipelining, etc. is a large part of what enables this (SMT), but I find that executing multiple streams of instructions simultaneously is usually what people mean when they talk about parallelism!

  • @atiedebee1020
    @atiedebee1020 7 หลายเดือนก่อน

    NFS is the network file system. We use it at home to have all computers' home directory on a central computer

  • @sharperguy
    @sharperguy 7 หลายเดือนก่อน +1

    Parallelism is two people each chopping an onion at the same time. Concurrency is one person chopping an onion while they wait for the oil in the frying pan to heat up.

  • @transimpedance
    @transimpedance 7 หลายเดือนก่อน

    Nice explanation of parallelism vs concurrency 👍

  • @maxmustermann3938
    @maxmustermann3938 6 หลายเดือนก่อน

    I'd say parallelism is when something runs in parallel on a given processing unit (i.e. your GPU or your CPU) while concurrent means that we are doing things in parallel across different processing units/hardware, i.e. doing work on the CPU while some other component is doing data transfers instead of just waiting for that to finish. When you're calling some function on the CPU that tells the GPU to do something, that will run concurrently. The task you gave to the GPU itself will execute in parallel on the GPU, and the GPU itself can also run things concurrently since it has more than just one streaming multiprocessor and can very well be running different tasks at the same time, but only one dedicated task in parallel on a given SMP.

  • @Sneg00vik
    @Sneg00vik 6 หลายเดือนก่อน +2

    When I figured out how asynchrony works in Rust, it helped me in understanding asynchrony in other languages. For example, like Python, where I understood asynchrony quite vaguely.

    • @wetfloo
      @wetfloo 5 หลายเดือนก่อน +1

      that happens to me a lot in rust, it's friendly enough that you don't really HAVE to think about some things that the language is doing, but if you do, you start understanding why it's doing it

  • @oblivion_2852
    @oblivion_2852 7 หลายเดือนก่อน

    Number 5. Each thread having a 4kb control block... Is this related to why when piping data between processes the buffer size is 4096 bytes?

  • @tusharsnn
    @tusharsnn 7 หลายเดือนก่อน +5

    Fun fact:
    You can't explain concurrency without explaining what those tasks do. You must first let the user getting explained understand that a task gets "paused" by the kernel during an IO op, but with modern kernel apis you can continue doing some other task by the time this previous task is again resumed. In the past application would wait for a task to get completed before it "can" move to the next one, regardless of the task being an IO op where it's simply waiting for a thing to happen.

    • @PanSzymek
      @PanSzymek 7 หลายเดือนก่อน

      its mentioned by all possible names in the article

  • @kc3vv
    @kc3vv 7 หลายเดือนก่อน +2

    I wonder if it is possible to somehow introduce things to rust that "fix" async to be more approachable.

  • @homelessrobot
    @homelessrobot 7 หลายเดือนก่อน +1

    Concurrency is parrallel waiting. In concurrency, you can sit around and do nothing while other people have their turn, and then pick up where you left off when some resource becomes available.

  • @jeremycoleman3282
    @jeremycoleman3282 7 หลายเดือนก่อน

    parallel is the same task running in multiple threads, concurrent is different tasks running at the same time maybe in different threads.

  • @emptystuff1593
    @emptystuff1593 7 หลายเดือนก่อน +2

    Explaining concurrency vs parallelism. Image building a house. You could have two workers laying bricks simultaneously. That's parallelism. You could have the same worker lay bricks, be out of bricks because there weren't enough bricks, go work on the plumbing, then go back to laying bricks when a new shipment of bricks arrived. By the way, I have no idea how to build a house.

    • @viktorshinkevich3169
      @viktorshinkevich3169 7 หลายเดือนก่อน +2

      I would rather say a kitchen. When you are making breakfast you can make a coffee while your wife makes a toast.
      Two people for two tasks. That's parallelism.
      The problem is that kitchen is small and you can't have many wives.
      Another problem is that when making a coffee the part of it is boil the water. While water is boiling you just sit and wait. The same goes for toast - while it's being heated your wife waits and does nothing useful.
      Here when concurrency comes to the rescue. You dont need a wife to make both coffee and toast concurrently - just load the toast, while heating boil the water, when toast is ready put a batter on it, then water is boiled so you switch there and finish coffee.
      Boom!
      TLDR; no wife no problem

    • @viktorshinkevich3169
      @viktorshinkevich3169 7 หลายเดือนก่อน

      People on a kitchen are CPU cores (processing unit), making a coffee (1) and making a toast (2) are tasks or jobs, loading toast/finishing coffee is computation, waiting for toast to heat/water to boil is waiting for IO, the toaster/kettle are OS/network.

    • @pnk4996
      @pnk4996 หลายเดือนก่อน

      @@viktorshinkevich3169this is the only explanation that actually made sense to me 👍🏼

  • @orbatos
    @orbatos 7 หลายเดือนก่อน

    Oh i love the days of maniacally chasing down semaphores locked by zombies.

  • @connormc711
    @connormc711 7 หลายเดือนก่อน +1

    please review Rob Pikes "Concurrency is not Parallelism" its a very good talk and a critical one for Go devs

  • @ra2enjoyer708
    @ra2enjoyer708 6 หลายเดือนก่อน

    For people elated about type annotations in the javascript files, they won't happen because they will straight up add parsing time and size to scripts with no runtime benefit whatsoever (and therefore the implementors will be blamed for "slow sites"). It might somewhat work in Python, because it's parse once and use many more times in prod, but not in browser js.
    The same reason there won't be pipe operators in JS either, because they incur a performance penalty on almost entire runtime, and implementors will be blamed for it.

  • @Alguem387
    @Alguem387 7 หลายเดือนก่อน

    Parsrelism is having multiple arms
    Concurrecy is having multiple hands

  • @MrHirenP
    @MrHirenP 7 หลายเดือนก่อน +1

    Hi! Can you explain why rust is great for CLI tools? What does it offer that, say, Go doesn’t?

    • @user-zl6om6kh9s
      @user-zl6om6kh9s 7 หลายเดือนก่อน

      serde and clap, all about the beautiful #[derive] macros

  • @tenshizer0
    @tenshizer0 7 หลายเดือนก่อน

    parallelism is a subset of concurrency... all parallel tasks are concurrent tasks, but not all concurrent tasks are parallel... concurrency is about solving problems of sharing resources (CPU, memory, files, etc.) between processes/threads/tasks both in parallel or in pseudo-parallelism

  • @MrXperx
    @MrXperx 7 หลายเดือนก่อน

    Parallel is when two chefs prepare two meals in the kitchen. Concurrent is when the same waiter two customers those two meals.

    • @tim.martin
      @tim.martin 6 หลายเดือนก่อน

      Other reply said concurrent is 1 chef making 2 meals...
      Problem is both scenarios need additional constraints to be always true. E. G.,
      1 Chef can bake 2 simple dishes in parallel, 1 waiter can serve 2 side by side customers in parallel (this would be super unusual). After careful thought, I think the waiter analogy wins because serving 2 customers simultaneously is not typical.

  • @rosehogenson1398
    @rosehogenson1398 7 หลายเดือนก่อน +2

    I like the article's explanation for parallelism vs concurrency. Concurrency is when you break your problem into independent pieces. Those pieces might run on the same CPU, they might run at the same time, or they might not.
    Parallelism is what happens when you run concurrent tasks at the same time.

  • @crimsonbit
    @crimsonbit 7 หลายเดือนก่อน +3

    I'm so confused. If async await is concurrency, then are goroutines parallelism? If so, does this mean than go doesn't actually have concurrency since it just constantly spawn green threads? In c# you have async await, green threads and "normal" threads if I understand correctly. So are languages like Go and Rust a step backwards? Are tokio spawns stackful or stackless? I'm I even alive right now?

    • @viktorshinkevich3169
      @viktorshinkevich3169 7 หลายเดือนก่อน +9

      Go abstracts the difference - goroutines are both concurrency and parallelism.
      You can have 16 CPU cores, spawn 16 computing goroutines and benefit.
      You can also have 1 CPU core, spawn 16 IO bounded goroutines and benefit.
      Because GO hides away the difference.

    • @crimsonbit
      @crimsonbit 7 หลายเดือนก่อน +1

      @@viktorshinkevich3169 Thanks for the explanation. But how does it know when to do concurrency for io bound stuff and when to do parallelism for cpu bound stuff? And is there a way to set it manually?

    • @viktorshinkevich3169
      @viktorshinkevich3169 7 หลายเดือนก่อน

      @@crimsonbit
      You are welcome!
      So again that's the cool part about go - you dont nesseceraly need to know.
      You are computing 4 different unrelated values that take time on 4CPU core computer spawning 4 goroutines? Fine, go scheduler will try and map those 4 goroutines on 4 Threads on 4 Cores. And speeding up computation 4x times
      You are requesting 4 different websites with 4 URLs on 1 CPU core toaster? Fine, go scheduler run them concurrently on 1 Thread, switching from one goroutine to another while waiting for network call response speeding you program to the time of slowest HTTP call.
      Go does so because he can difference IO bound from non IO bound (+timers).
      If you spawn goroutine that just calculates something Go will know it should not be "async".
      If you spawn another goroutine then does Timer (sleep) or that makes an HTTP call or reading from a file - that goroutine know is "async" since Go scheduler knows that it could be easily put on "waiting" list since there is nothing useful it can do in the meantime - it just awaits for response. If it just waits for HTTP call to come back and forth across ocean thru 15.000Km for a sec or two - it's totally legit.
      For the programmer in Go, there is no special syntax to know it he writes async function or a regular one.
      In Rust, NodeJS, Java, C# there is.

  • @creativecraving
    @creativecraving 2 หลายเดือนก่อน

    2:20 _Parallelism_ exploits algorithmic efficiencies to solve underutilization of CPU cores. _Concurrency_ exploits I/O bottlenecks to do the same thing _or_ allows you to logically separate the work among several actors with distinct roles.

  • @cariyaputta
    @cariyaputta 7 หลายเดือนก่อน +12

    "Just use Go" - Rust Programming Language Book.

    • @fayaz2956
      @fayaz2956 7 หลายเดือนก่อน

      really? 😮

  • @yenonn
    @yenonn 7 หลายเดือนก่อน

    Love the humour!

  • @baxiry.
    @baxiry. 7 หลายเดือนก่อน +5

    By the way, 39 data-racing vulnerabilities were announced in Rust programs, compared to 2 data-racing vulnerabilities in Go

  • @trashcan3958
    @trashcan3958 7 หลายเดือนก่อน +13

    At the end of the day I personally don't give a shit about articles like these. I have written a very large backend in Rust and it works perfectly and it is much more maintainable than any TS nightmare a different programmer would have done. The places where you need to use stuff like pin are very uncommon. Also, most frameworks do the heavy lifting for you so shard global variables become non-issues.

    • @dn5426
      @dn5426 7 หลายเดือนก่อน +4

      backend as in something that does HTTP + DB calls?

    • @0xCAFEF00D
      @0xCAFEF00D 7 หลายเดือนก่อน

      Why are you comparing to TS?
      That's garbage.

    • @ra2enjoyer708
      @ra2enjoyer708 6 หลายเดือนก่อน

      @@dn5426 No he meant a middleware which passes the values to a real backend. I'd also add FS on top, because it can get pretty spicy with all the multi-platform stuff, so I don't believe you can write a "maintainable" code in this context, especially if you need some custom storage implementation logic (multi-platform ofc).

  • @rossbagley9015
    @rossbagley9015 6 หลายเดือนก่อน

    To be fair: go's concurrency features enforce "The Right Way(tm)" to do concurrency. Now I want go-style concurrency in all languages and get frustrated that it isn't fully supported.

  • @BosonCollider
    @BosonCollider 7 หลายเดือนก่อน +1

    Go is not really CSP. The memory passed is not immutable so you can still have data races.

  • @simonfarre4907
    @simonfarre4907 7 หลายเดือนก่อน +10

    I still find the discussion of channel's funny though, particularly this article when it says "after decades of mutex madness". How do people think channel's work? They're *literally* designed as a critical section (CS) that's behind a - you guessed - a mutex (or some other locking/guarding mechanism).

    • @bonsairobo
      @bonsairobo 7 หลายเดือนก่อน +14

      Yes but the abstraction is significantly less powerful (and less dangerous) than a raw mutex. The programmer never needs to worry about shared memory, all of the messages sent and received are owned by one thread until they are moved/sent.

    • @matheusjahnke8643
      @matheusjahnke8643 7 หลายเดือนก่อน +3

      Yes, on the same line, control structures(loops, if statements and function calls) are also just glorified gotos and branches(and stacking)... they provide a structured interface which helps prevent foot guns.
      The deadlock condition on a correctly implemented queue is when there's mutual waiting because there are threads which want to consume while there is noone to produce(and the queue is empty).

    • @simonfarre4907
      @simonfarre4907 7 หลายเดือนก่อน +2

      @@bonsairobo Yes, I'm just saying, writing an ad-hoc channel is fairly trivial, particularly in languages like C++. And doing it is trivial, since you'll use a queue and a mutex that wraps the pushing and popping of values off of it.
      Reading off of a channel, is a blocking operation and as such, looks and behaves exactly like a raw mutex. And when writing your own solution, you can add a try_read that checks for content before reading, and just like that, you have implemented the mpsc channel in Rust.

    • @simonfarre4907
      @simonfarre4907 7 หลายเดือนก่อน

      @@matheusjahnke8643 That wasn't my point, or what I was implying though. What I was implying is that, writing your own ad-hoc channel abstraction is pretty trivial in languages like C++. Is it going to be *as general* as a channel from the standard library? Well, that depends on how good you are at writing templated generic code, but even with simple OOP-techniques it is extremely trivial.

    • @someonespotatohmm9513
      @someonespotatohmm9513 7 หลายเดือนก่อน

      @@simonfarre4907 What is your point? Because I read it as: "this thing is so simple ppl should just do it themselfes". Hopefuly it is clear why this is a weird statement to make, especialy in software.

  • @blenderpanzi
    @blenderpanzi 7 หลายเดือนก่อน

    4:50 It's 50 years. Pipes exist in Unix for 50 years this year, not just 40.

  • @cheaterman49
    @cheaterman49 7 หลายเดือนก่อน

    6:45 we've been doing that in Python for 32 years haha

  • @mannycalavera121
    @mannycalavera121 7 หลายเดือนก่อน +1

    Poor Ryst, getting hammered

    • @peter9477
      @peter9477 7 หลายเดือนก่อน

      It will survive, LOL.

  • @noredine
    @noredine 7 หลายเดือนก่อน +2

    A recursive async function? Would it garble the call stack, or would each recursive call not be async (for my sanity)?

    • @protox4
      @protox4 7 หลายเดือนก่อน

      It has the same problem as synchronous recursion (actually it's worse). If it's unbounded, you'll either get a stack overflow, or out of memory, depending if the recursive call is synchronous or asynchronous. Even if it's not unbounded, you could also get a stack overflow when the deepest task completes and starts to unwind the async call stack (.Net has special handling for such a situation, but it's an extremely rare case).

  • @rossbagley9015
    @rossbagley9015 6 หลายเดือนก่อน

    What I really want is Rust with all the memory safety, true functional language features, and Hoare concurrency (all communication with green threads occurs via channels with immutable messages). Who is working on this?

  • @jordixboy
    @jordixboy 7 หลายเดือนก่อน +1

    whatso hard about pointers and malloc, i dont get it

  • @YunikMaharjan
    @YunikMaharjan 7 หลายเดือนก่อน +2

    i'm with you on Pin and Unpin. I think i get it then the next day when i think about it again, i don't

  • @lainiwakura3741
    @lainiwakura3741 5 หลายเดือนก่อน

    Why is it so difficult to define concurrency? I feel every time I hear the term, people always give a different definition and can never really agree on what it actually means.. It's either that the order of operation doesn't matter, that it presents an opportunity to parallelize (i.e. concurrent tasks can be parallelized), that the code is running independently but always executes one task at a time (big difference since it means that parallelized tasks are not concurrent; prime literally said this at 1:56) and endless variation of these. The example Prime gives at 2:17 makes me think that it is all about utilizing wait time, which I've seen in several examples but I have never heard anyone explicitly says this out loud. But this doesn't feel like a definition of the word concurrent and instead is how to make concurrent tasks run faster. So it shouldn't be brought up when defining the word, but only when you talk about why concurrency is important.
    I dunno.. It feels like the concept is not complicated at all but different people focus on different details on the definition and as soon as you don't focus on the right detail in the same way as the other person, they will tell you that your idea of concurrency is wrong. I hate words.. so much...

  • @shalevh
    @shalevh 7 หลายเดือนก่อน +1

    man has a typescript cold, can't stop talking about damn node lol

  • @davidserrano2091
    @davidserrano2091 7 หลายเดือนก่อน

    Do u think he listens to Tokyo drag while using tokio

  • @jonaskoelker
    @jonaskoelker 7 หลายเดือนก่อน +2

    I can put on my left shoe and my right shoe in any order (concurrently), but I don't have the dexterity to put both of them on at the same time (in parallel).

  • @Purkinje90
    @Purkinje90 7 หลายเดือนก่อน +1

    send in the chungus

  • @user-sn6fo6gb9d
    @user-sn6fo6gb9d 7 หลายเดือนก่อน

    "pretty neat"

  • @irfanhossainbhuiyanstudent3757
    @irfanhossainbhuiyanstudent3757 7 หลายเดือนก่อน

    I really like the syntax of rust,just the lifetime complexity make it hard to use it,if rust would have a builtin semi automated garbage collector in std library,I won't gonna use other language anytime soon.

  • @freeideas
    @freeideas 7 หลายเดือนก่อน +3

    Meanwhile, Java's managed threads quietly gives you the memory benefits of async/await without all the callback complexity. With async/await to call A, B, and C, you have to say something like, "tell B to call C when B is done, then tell A to call B when A is done". In java you can say "do A, do B, then do C". Behind the scenes, java has a number of real threads proportional to the number of cores in your hardware, and all the "virtual" (aka micro-) threads just take turns using the real threads. I love the way java hides most of the ugly complexities from you while still giving you compiled-language performance. Not as fast as Rust of course, but more than fast enough for almost any job.

  • @doomguy6296
    @doomguy6296 7 หลายเดือนก่อน

    Never had to use Pin. What the h*ll were you developing? An async linked list?

  • @complexity5545
    @complexity5545 7 หลายเดือนก่อน +1

    Boy that articles's author thinks in (congested) bloat. But I think his conclusion is correct.

  • @connormc711
    @connormc711 3 หลายเดือนก่อน

    Prime I know you read parallelism vs concurrency by rob pike but you should watch the video too

  • @CristianGarcia
    @CristianGarcia 7 หลายเดือนก่อน +2

    Classic parallelism vs concurrency confusion. I don't think Prime's definition is good enough.

  • @LostInAutism
    @LostInAutism 7 หลายเดือนก่อน

    Pixel 7 eh? The volume rocker is soon to fall out.

  • @kahnzo
    @kahnzo 7 หลายเดือนก่อน +8

    Please read through Without Boats's response to this article. This is the problem with react videos. You can't just say, "oh, that sounds good" and not dig in a little further. Async without GC is hard. Linear types are interesting. Passing information between Rust and a GC language requires a LOT of forethought, knowledge, and work. But that why there are libraries and amazing groups of people to work through the nuances.

    • @Cookiekeks
      @Cookiekeks 7 หลายเดือนก่อน +2

      Where can I find it?

  • @kirillgimranov4943
    @kirillgimranov4943 7 หลายเดือนก่อน

    omg i got pixel 7 too

  • @colemichae
    @colemichae 7 หลายเดือนก่อน

    Interesting comment on Bun i heard that also from another person this week. Great for some areas but needs work in so many to really be the perfect solution

  • @alexpyattaev
    @alexpyattaev 7 หลายเดือนก่อน +3

    Rust async should be compared with c++ async. there you do not have pin.

  • @nomadshiba
    @nomadshiba 7 หลายเดือนก่อน

    rust is really good for data oriented ecs based games

  • @poorpotato4467
    @poorpotato4467 7 หลายเดือนก่อน +20

    baby shark doo doo, doo doo. doo doo

    • @0.Maiden
      @0.Maiden 7 หลายเดือนก่อน +2

      Mommy Shark, doo-doo, doo-doo, doo-doo, doo-doo

    • @AnnaGottin
      @AnnaGottin 7 หลายเดือนก่อน +1

      Nice

  • @twitzel25
    @twitzel25 7 หลายเดือนก่อน

    NFS was great (other than the stale mounts of course)!!

  • @graphicdesignandwebsolutio365
    @graphicdesignandwebsolutio365 5 วันที่ผ่านมา

    if you want nodejs to use ALL your cores, try scanning the Arbitrum blockchain, block by block for arbitrage and liquidation oppurtunities, calculating 100+ token pairs price data on each block...

  • @ivanjermakov
    @ivanjermakov 7 หลายเดือนก่อน +5

    If async/await/futures/promises is a leaky abstraction, how channels is better? I think it will become event hell the same as RxJS observables.

    • @viktorshinkevich3169
      @viktorshinkevich3169 7 หลายเดือนก่อน +1

      Its not hell in golang, its not hell in elixir, why should it be hell here?

    • @AnthonyBullard
      @AnthonyBullard 7 หลายเดือนก่อน +1

      Async and all that color the function, and that coloring spreads to its caller. With channels, you don’t know if a function you call is shelling out to something else, and don’t have to refactor everything to use it

    • @ivanjermakov
      @ivanjermakov 7 หลายเดือนก่อน

      @@AnthonyBullard but if the called function is inherently asynchronous, how does the caller can not now this? So if the caller just cares about the value it will act as await, but if the caller needs async interaction it will invoke it differently and subscribe to its channel?

  • @doxologist
    @doxologist 7 หลายเดือนก่อน +1

    Im still confused gow Rust Async is bad? Apart from the aweful Type Annotations when creating generic Async libs, I find Asyn Rust, when leveraged with veterans like Tokio/channels, just works. Am I missing something? Perhaps this is more of a problem for Embedded code?

  • @NVM_SMH
    @NVM_SMH 6 หลายเดือนก่อน

    Can't someone write the equivalent of go in a rust library

  • @9SMTM6
    @9SMTM6 7 หลายเดือนก่อน +3

    Yes, I agree on that. I'd argue, that this is the cause of part of your souring on Rust. I imagine that at Netflix you've been mostly writing async Rust, and I've long been saying, with async you loose a lot of the advantages of Rust.

  • @NotHumanPerson
    @NotHumanPerson 7 หลายเดือนก่อน +3

    I think that asynchronous rust is more like a threadpoolhandler

    • @bonsairobo
      @bonsairobo 7 หลายเดือนก่อน +1

      That's a specific implementation of an async runtime. The async language is more abstract, and it can run concurrent futures on a single thread.

    • @NotHumanPerson
      @NotHumanPerson 7 หลายเดือนก่อน

      Yes but how are you gonna use Tokio, except as a thread pool handler, give me an example where Tokio + rust is a good idea and you‘re not just using Tokio for a) internet or b) multithreading

  • @tal500
    @tal500 7 หลายเดือนก่อน +1

    The barrow checking modal is just not advanced enough for async calls, rather to stack calls and scope-timed parallelization. Wonder if a language like Val could solve this issue.

    • @steffahn
      @steffahn 7 หลายเดือนก่อน

      Val uses a simpler borrow checking model, not a more advanced one.

    • @tal500
      @tal500 7 หลายเดือนก่อน +1

      @@steffahnbut the pipeline might be easier, since quering a computation in Val could be naturally async?

    • @steffahn
      @steffahn 7 หลายเดือนก่อน +1

      I don't know much about val to be honest, but from the few things I've seen about it in presentations on TH-cam, it seems like they deliberately want to be simpler than Rust's borrow checker. I'm merely commenting on your statement that Rust's borrow checking model may not be "advanced enough" followed up by quoting val.
      Regarding the problem of scoped tasks in async Rust, as far as I know, the main blocker that prevents that has nothing to do with borrow checking anyways. The problem instead is that the relation scoped threads can enforce, that the spawning thread must wait for the spawned thread to finish (before it can drop any values the spawned thread can access), is impossible to enforce for Futures because nothing prevents someone from partially executing a future that spawns a task and then cancel it. As far as I remember, this may in particular relate to that Rust considers it safe to leak values, so you can cancel a future in a way that leaves no way for a scoped task API to notice it.

  • @pirieianip
    @pirieianip 7 หลายเดือนก่อน

    Parallelism may not use two separate CPUs; it may use two different threads, and you may use the same CPU for those threads. Splitting hairs, but, meh.

  • @SquirrltheRiddl
    @SquirrltheRiddl 16 วันที่ผ่านมา

    How can ppl be confused about parallel and concurrent the word literally describes itself lol

  • @dc0d
    @dc0d 7 หลายเดือนก่อน

    (alert: reductionism in progress)
    Parallelism is when everyone is drinking from their own bottle. Concurrency is when everyone passes the bottle to the next person after a sip.
    #erlang #elixirlang #golang

  • @kahnzo
    @kahnzo 7 หลายเดือนก่อน

    FasterThanLime buddy

  • @cotneit
    @cotneit 7 หลายเดือนก่อน

    Everyone who hosted a Minecraft server hates GC by default

  • @PanzerschrekCN
    @PanzerschrekCN 7 หลายเดือนก่อน +9

    The main advantage of async Rust over Go is possibility to throw all async-unrealated stuff in non-async program part. In Rust you just do not use Arc, Pin and other stuff like that. In Go you still pay penalty for GC, stack grow overhead, etc.

    • @rw_panic0_0
      @rw_panic0_0 7 หลายเดือนก่อน +5

      because Rust is designed to provide zero cost abstractions, Go is not, and what you said is as advantage as it is a disadvantage

    • @JOHN-um2
      @JOHN-um2 7 หลายเดือนก่อน +3

      You can in Go. I suggest you learn the language before commenting on it.

  • @rosehogenson1398
    @rosehogenson1398 7 หลายเดือนก่อน

    Every time I've wanted to use a condition variable, I've regretted it

  • @matheusjahnke8643
    @matheusjahnke8643 7 หลายเดือนก่อน

    My turn to ackchually about parallelism and concurrency.
    Parallelism is when things run at the same time... so processes aren't parallel in an old, single core, computer
    Concurrency is when things share resources... processes are concurrent because they share memory and CPU(and access to disk space... and internet and stuff)

  • @32zim32
    @32zim32 7 หลายเดือนก่อน

    Soon graalvm will gain popularity and java again will become popular. I noticed that while coding in rust I become tired very quickly. This is not I expect from modern language

  • @chaorrottai
    @chaorrottai 5 หลายเดือนก่อน +1

    The problem with multithreading is that the programmer is the one implementing it. The CPU hardware should be delegating work to it's worker cores. It should opperate internally as a multithreaded system and present the user with an apparent single thread and the user should have the option to bypass the thread overseer but the default behaviour should be to just let the thread overseer handle threading and data race prevention.
    Multi-threading should be a hardware level issue, not a software level issue. There is no reason anti-data-race circuits could not be added to memory modules using a XOR-gate access lock at minimum.
    Hell, it could even be implemented compiler level, instead of programmer level, you just have the complier mutex lock any variable that can be access from multiple threads: internally handle those as structs containing var and mutext and then overload the access opperators to aquire and release the mutext locks.
    .....at the developer level, this is a single template class.........

  • @feschber
    @feschber 7 หลายเดือนก่อน

    Came across this recently and feel like not being able to have shared mutability across async tasks on the same thread really kind of defeats the purpose of async in the first place.

  • @sinasalahshour
    @sinasalahshour 7 หลายเดือนก่อน

    deez parallel units

  • @Cookiekeks
    @Cookiekeks 7 หลายเดือนก่อน +5

    So why the fuck did I learn Rust then? It was being advertised as having excellent concurrency, and up until now I just thought I was too stupid to get, but apparently other languages have it easier. Wow, what a waste of time that was. Shit. Should I learn Go?

  • @jordixboy
    @jordixboy 7 หลายเดือนก่อน +1

    NFS = need for speed

  • @thewhitefalcon8539
    @thewhitefalcon8539 7 หลายเดือนก่อน

    You don't know what NFS is?

  • @ra2enjoyer708
    @ra2enjoyer708 6 หลายเดือนก่อน

    Just learn an entire Unix spec to write a fs call in your CRUD, bro.

  • @viktorshinkevich3169
    @viktorshinkevich3169 7 หลายเดือนก่อน +4

    Can we just all agree than when it comes to IO go abstraction is so much easier and convenient that rusts.

  • @jeffwhite3867
    @jeffwhite3867 7 หลายเดือนก่อน

    The literal definition of concurrency is running at the same time but not affecting each other. This applies even to prison sentences. If someone is sentenced to serve a 20 year sentence for one crime and a 25 year sentence for another crime, and these terms are declared concurrent by the judge (as opposed to consecutive), then the person effectively only has to serve 25 years.
    The reason they do this is very similar to the reasons we run concurrent processes. If for any reason the 25 year sentence were overturned or somehow revoked, the 20 year sentence would still be in effect without being affected by the other term. Just like if you have two concurrent units of code running in parallel and one of them finishes early, it has no effect on the other unit running.
    The entire point of concurrency is so that multiple whatever-it-is can be run in parallel, in both computing and prison sentences (and pretty much anything else that is described as concurrent).

  • @TheHackysack
    @TheHackysack 7 หลายเดือนก่อน +8

    lol
    Parallelism is about running things in parallel.
    Concurrency is about running things concurrently.

  • @mks-h
    @mks-h 7 หลายเดือนก่อน +5

    And the moment you choose to do async, you also throw away std for tokio's std

    • @mks-h
      @mks-h 7 หลายเดือนก่อน +3

      @@TheGameMakeGuy yeah, I mean third-party reimplementations of std in general.

    • @bonsairobo
      @bonsairobo 7 หลายเดือนก่อน

      Certain parts of the async libraries that overlap with std are still experimental, but many things will eventually become standard.

  • @rban123
    @rban123 7 หลายเดือนก่อน

    Parallelism IS a subset of concurrency. Asynchronousity also is a subset of concurrency. What you are referring to as “concurrency” throughout the video is actually specifically asynchronous code. Parallel code is also concurrent.

  • @aryabp
    @aryabp 7 หลายเดือนก่อน

    Bruh AsyncAgent

  • @principleshipcoleoid8095
    @principleshipcoleoid8095 7 หลายเดือนก่อน +4

    0:35 are you running GrapheneOS on it?

    • @TheSast
      @TheSast 7 หลายเดือนก่อน +3

      Asking the right questions

    • @privy15
      @privy15 7 หลายเดือนก่อน

      Is GrapheneOS still a good option for Pixels? Heard that the dev (?) has some... mental issues

    • @mks-h
      @mks-h 7 หลายเดือนก่อน +2

      @@privy15 he does, but a) paranoia probably isn't bad for a secure OS, b) he stepped down

    • @privy15
      @privy15 7 หลายเดือนก่อน +1

      @@mks-h He stepped down? Thats new. Thx

    • @principleshipcoleoid8095
      @principleshipcoleoid8095 7 หลายเดือนก่อน

      @@privy15 it's better than the stock Android full of Google. I don't think the devs even can do targeted attacks. But you can run Google things sandboxed (and even in a separate profile) for bank apps ect. Either way it is a good idea to use some FOSS Android without Google reading all of your messages and activity