Are Virtual Threads Going to Make Reactive Programming Irrelevant?

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ธ.ค. 2024

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

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

    Virtual threads have been a game changer for our services. Thank you, JDK engineers (and Spring engineers for adopting them in the framework).

  • @cesar.vasconcelos
    @cesar.vasconcelos หลายเดือนก่อน +12

    Mr. Paumard and Mr. Venkat are true legends. Their videos are gold and even experienced Java Developers will learn a lot from these two gurus.

  • @VuLinhAssassin
    @VuLinhAssassin หลายเดือนก่อน +51

    It is an honor to watch Jose Paumard presenting...

  • @ericm97
    @ericm97 วันที่ผ่านมา

    What a style of presentation. Your ability to explain these concepts in a way that relates to us yet easy to understand is simply amazing :)

  • @oqpo-q6c
    @oqpo-q6c หลายเดือนก่อน +2

    What I love about all this is that they did not follow the hype back then and did not add the async/await. Guys, you are awesome!

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

    typo on slide 47. blocking a virtual thread does NOT block the p.threaf.

    • @MuztabaHasanat-x2p
      @MuztabaHasanat-x2p หลายเดือนก่อน

      👏

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

      There are some exceptions.
      E.g synchronzied block

    • @ManuLG
      @ManuLG 26 วันที่ผ่านมา

      That’s the reason to replace it with ReentrantLock in order to work with VT

  • @Aqryu
    @Aqryu 20 วันที่ผ่านมา

    Thanks so much mr. osé Paumard , such a wonderful talk! I have learned so much from this
    Hopefully we can fix the pinning issue and scope values in jdk 24

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

    Great conference Mr. Paumard.

  • @capability-snob
    @capability-snob หลายเดือนก่อน +1

    The reactor allows us to reason locally about concurrent behaviour. If I know statically where my task may be switched out for another, then I know where I need to recheck my assumptions.

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

    I am glad virtual threads came along before my company decided to adopt reactive programming. Now we just need to upgrade java and use virtual threads

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

      i'm struggling with reactive code left by previous team, you are lucky!

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

      I miss Rx. So much cleaner

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

      @@jp263 I have to use Rx (JS flavored) every day and like to think I'm reasonably competent at it by now, and I have to say I hate every second of dealing with that crap.
      I just wish there was something like Virtual Threads in JS ...

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

    Great talk, very unbiased and fair! Virtual threads are a great addition to the language, without a doubt. However it is worth mentioning that in terms of sheer performance (latency, not throughput), the 20-year old Java NIO with EPoll cannot be beat. A single thread spinning and pinned to an isolated CPU core is the king when it comes to low latency. And because we are talking about a single thread, which is handling many clients, there are no multithreading pitfalls. That means no synchronization, no deadlocks, no thread starvation, no race conditions, no locks, no nothing. Coding is very easy and joyful. That's the model the financial industry (high frequency market makers) has been very successfully using for 20 years now.

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

      Yes but this is such an incredibly complicated model to build on. This is why we have frameworks like Reactor and Netty to try and make this model usable. In reality, virtual threads do exactly this. When a virtual thread yields, the scheduler either resumes another virtual thread or invokes epoll to see if any IO has completed. It's essentially the same thing but with a much simpler programming model. Virtual threads gives all the same benefits of old school Java NIO but without all the headaches of trying to put all your concurrent operations in a single epoll loop.

    • @JosePaumard
      @JosePaumard 27 วันที่ผ่านมา +1

      > Coding is very easy
      Sorry, I disagree on this one.

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

    Really helpful - I understand the use of virtual threads for the first time. Thanks.

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

    What about reactive streams? I still think there is a place for reactive in stream processing IMO.

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

    What a great presentation. Thank you!

  • @Dominik-K
    @Dominik-K หลายเดือนก่อน

    Amazing presentation! Really well made and teaches the real reasons why virtual threads are an improvement very well

  • @中本聪-d9k
    @中本聪-d9k หลายเดือนก่อน

    The great José Paumard!!!

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

    What about Kotlin Coroutines? Until now they still give you Structured Concurrency, which is the missing part in Loom. But once Loom has that covered too, do Coroutines still buy you anything?

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

      Well they will exist forever in Android (or at least for a decade after they are implemented in ART).
      Also it's not clear what's the replacement for streams of values (e.g. Flow) is. I suppose with virtual threads you can use regular blocking queues for that?

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

      @@equeim I think instead of Flows we could just use regular Java Streams (or Kotlin Sequences) that just happen to potentially block the (virtual) thread when computing the next value. At least that seems like an equivalent abstraction to me.
      Producer/consumer queues can work too, but that feels like a lower abstraction level.

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

    15:33 Modern systems don't allocate 2MB continuous memory for stack per thread. Stack is allocated dynamically.
    2MB is reserved from virtual memory for stack, which can be configured, but this won't actually optimize memory usage much, only mapping tables.
    A thread typically consumes ~64KB initially (without extra stack frames).

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

      Fun fact: OpenJ9 doesn't even allocate all that virtual memory upfront; it can grow the virtual space dynamically.

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

      @@prdoyleThat explains why Java 8 consumed more memory on my measurements of stack memory usage

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

    Before I watch the video, I can only answer the title and say: I really hope so.

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

    Amazing! Thank u 😊

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

    Very Well explained! Thank you!

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

    truth, I see fear in my coworkers about the reactive Java code I write

  • @phyohtetpaing44
    @phyohtetpaing44 2 วันที่ผ่านมา

    Virtual threads may offer better multithreading capabilities, but they can never fully replace reactive streams. Unlike reactive streams, virtual threads cannot cancel pipelines, handle backpressure, or perform operations like batching and windowing. If features like these were added to virtual threads, they would essentially become reactive streams.
    Reactive streams offer additional capabilities, such as error handling mechanisms like onErrorContinue, which allows the pipeline to continue despite errors, or onErrorCancel, which can either cancel a single element in the stream or terminate the entire stream if an error occurs. Virtual threads lack these features, and adding them would transform virtual threads into a reactive paradigm, which they are not designed to be.
    Therefore, virtual threads cannot replace reactive programming.
    Virtual threads do not have the ability to detect if a remote service is slow or to adapt by pushing elements in the proper size. Similarly, they cannot detect when a remote service cancels the stream, and they will continue processing regardless, making them inherently blocking in such cases.
    This lack of awareness and adaptability highlights a key limitation of virtual threads compared to reactive streams, which are designed to handle such scenarios efficiently.

    • @Nithril
      @Nithril 3 ชั่วโมงที่ผ่านมา +1

      Agree, that video does not talk at all about reactive, CompletableFuture is not reactive. Disappointed to see such a great presenter fall into that trap.

  • @Talaria.School
    @Talaria.School หลายเดือนก่อน

    Thanks champ.

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

    At 22:58 easiest way to explain reactive framework.

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

    Jośe is a really GOAT I mean it!

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

    José is the GOAT

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

    nice explanation

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

    the talks by Jose are always crystal clear! Thanks for sharing them!

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

    14:43 I think You meant lost threads. Loose means not tight. Also at 46:00

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

      Loose can also mean "escaped" as in "my horse got loose". Which works in the context he is using it. But since I'm not familiar what the proper nomenclature is you may be right.

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

      @@shannonkohl68 You are right. For me, loose, like a horse or fugitive, also brings the connotation that it does something rogue, uncontrolled. The threads mentioned simply get lost. However, I have only spoken English as a second language for 45 years, and the difference between loose and lost does not lessen the excellent presentation.

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

      No, the term "loose" is used metaphorically, as in if a thread is not "tight" with your system, your system is going to fall apart due that "loose thread"

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

      You have to take into account that we're talking about "threads" which has connotations with weaving and cloth. And that context a "loose thread" makes sense, something that is not part of the whole anymore. A "lost thread" on the other hand would be strange concept, it would have to disappear without us knowing where it went.

  • @DanielSimiyu-f9j
    @DanielSimiyu-f9j หลายเดือนก่อน +5

    The abuse of reactive programming will end with structured concurrency

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

    29:50 I suffered this for more than a year

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

    Virtual threads solve the blocking issue, but not the underlying task parallelization & back-pressures ones. In the data world & GUI worlds, i imagine RX is here to stay.

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

      Do you mean because virtual threads put into heap and unblock app thread only if it's well known api blocking call like http call or file open for example?

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

      Do you really write code to utilize the back-pressure feature in a reactive library? If yes, may I see an example?
      I think that back pressure is a way to push the problem (which is that there's not enough memory/cpu to process data) from this application to another application. For example, application A calls application B for data. If application A uses the back pressure feature to tell app B not to send too much data, then application A doesn't need to have a lot of memory to hold data that hasn't been processed yet and application B is the place to hold the data that application A. So, instead of holding data in application A, you hold data in application B.

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

      @@avalagum7957 yes we do, Swing ui +Chromium doing few k data points per second in between and you need to keep ui in sync, where data exchange is a mix of jni, rpc and websockets

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

      ​@@avalagum7957if application B is a MongoDB, you already have the data stored on it. I think the problem is if application B loads all data in memory and sens to A reactively

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

    What a nice talk. The only question is "will the scoped values accept a Generic value"? I do think a response for this but i wish someone of the Java team could answer so i can understand the spirit behind the usage of Scope Value in an oficial way of view.
    Thanks

  • @áúéúóá
    @áúéúóá 25 วันที่ผ่านมา

    reactive programming goes against - KISS. It's not bad, but it's not simple solution

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

    Fruit Of Loom :D

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

    Not that much Sure

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

    Always sad to see people confusing latency and throughput.
    If i dont use concurrency, my latency will go up. My throughput for that thread will suffer. However, if i have enough threads, the gains will not be immediately there: any wait time just lets the cpu do a context switch. Yes, these take time but that is not mentioned. Cpu is still completely filled. The problem occurs when we use microservices with marginal cpu use per work package. Then most time will be wait time and we will hit the max threads. But if you dont, no reason to add the complexity of manual concurrancy.

  • @abhijitbhattacharya2625
    @abhijitbhattacharya2625 14 วันที่ผ่านมา

    I enjoyed a java lecture after 20 yrs

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

    Reactive programming is more than Java. It will remain important in micro service architecture and in Java areas where the vthread approach scheduling overhead is too much. For example, using reactive programming you do not move memory between the stack and the heap. It is a very small niche segment, and for most of the programming tasks where you needed to use reactive progrmming in Java to achive the performance vthreads will provide a simpler programming paradigm.

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

      Virtual thread scheduling does some smart tricks and doesn't actually copy the stack most of the time. Stack size is also usually relatively small. When other Java features related to virtual threads arrive, and when the ecosystem matures, performance difference will all but disappear.
      Reactive programming will be used maybe for other features of it, like back pressure, or having drivers for some data sources etc.

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

    I actually enjoy reactive tho. Most of my work has been creating reactive code

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

      Yes but should we be proud of it with callback based ones when java should do it simpler? And our `doOnError` or `onErrorResume` calls on call stack to safeguard I loose track when we debug. This is needed but we shouldn't be proud of workarounds.

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

    Let's hope so. Reactive is an unusable disaster.

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

    I don't think so.

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

    How happy I am that I use kotlin at my work, coroutines there are 10 years ahead of java can be

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

    That makes no sense. Reactive Programming has more aspects

    • @m13v2
      @m13v2 3 วันที่ผ่านมา

      Indeed: en.wikipedia.org/wiki/Reactive_programming

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

    This feels like infomercial levels of dishonesty.
    Stack traces aren't that bad if you don't use the JDK reactivity, which is pretty limited and has a terrible DX as proven by this video.
    This reactor code:
    ` var links = getLinks();
    var images = getImages();
    Mono.zip(images, links)
    .map(t2 -> page(t2.getT1(), t2.getT2()))
    .block();`
    Produces this stack trace when getImages() errors:
    `boom
    java.lang.RuntimeException: boom
    at org.abickford.fp4legacy.domain.Dishonest.getImages(Dishonest.java:26)
    at org.abickford.fp4legacy.domain.Dishonest.bs(Dishonest.java:14)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1597)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1597)`
    That hardly feels like the intractable monster that was fearmongered in this video. "Loose threads" isn't a thing here either. I counted over a dozen methods to return defaults, call another async primitive, short circuit, propagate, etc on errors (default is the error channel in the subscriber).
    These toy examples also feel unfair. If you need to do actual traffic shaping and routing, timeouts, recovery, switching, etc, I'd argue a bunch of imperative threading primitives aren't better at all. I'd far prefer a nice declarative functional API over managing locks and latches.
    In fact, this whole pitch is a false dichotomy as RX can be implemented *with VT*!
    DGMW, i think VT are really cool! But the real comparison should be things like c# async/await and how VT don't color methods. VT also work with legacy blocking APIs like JPA/hibernate. This is a huge win and a real differentiator in java.
    Rx is the wrong battle.