Speed Up Your Node App Using Worker Threads!

Поділитися
Вставка
  • Опубліковано 5 вер 2024

КОМЕНТАРІ • 65

  • @bricehemery1534
    @bricehemery1534 2 роки тому +21

    Can't believe how clean is this explanation. Thank you sir.

  • @code2287
    @code2287 2 роки тому +4

    I've always known I needed to know Workers but am always so overwhelmed with how complicated it seemed thanks for making me understand this better

  • @Miketar2424
    @Miketar2424 Рік тому +4

    This was great. After spending some time going through various tutorials, I found some that had typos in the code, others where the demo was filled with very complex js, and yours was simple and to the point.

  • @Applemann97
    @Applemann97 Рік тому +3

    Perfect example, perfect explanation & presentation. Thanks for this video!

  • @user-lt1jqrhcp7ext321
    @user-lt1jqrhcp7ext321 2 роки тому +3

    Chaim, thank you so much for the video. Your explanation is clear and awesome

  • @whatskookin6429
    @whatskookin6429 Рік тому +1

    Someone at my job gave me this exact explanation, excellent content

  • @patrickc.2680
    @patrickc.2680 2 роки тому +2

    This is really good, seen it here first! Thank you man, keep up the great work.

  • @Dipenparmar12
    @Dipenparmar12 2 роки тому +1

    One of the most interesting and very beautifully explained topic.
    Thank you very much.

  • @anmolsharma8949
    @anmolsharma8949 Рік тому

    Amazing example. very sorted and easy. Thanks and love from India

  • @MrLinuxFreak
    @MrLinuxFreak 10 місяців тому

    סרטון מאוד מעניין ומעשיר ידע תודה לך חיים

  • @dmaniac4
    @dmaniac4 2 роки тому +2

    Wonderful explanation!!!! Thank You!

  • @trucheitor
    @trucheitor Рік тому

    Well thanks, i Will try this today. Just curious about what happens when you Open several Windows causing going out of threads in your system

  • @mosheritterman3472
    @mosheritterman3472 2 роки тому +4

    Thanks for another great video! I'm not a node developer but wouldn't you be able to accomplish this by wrapping the loop in a promise?

    • @CodingWithChaim
      @CodingWithChaim  2 роки тому +2

      good question. I think the answer is that a promise does not make a sync operation happen async, instead it gives you a way to deal with an already async operation. At the end of the day this is just a simple for loop and it will always happen synchronously

    • @litbro8180
      @litbro8180 2 роки тому +1

      @@CodingWithChaim you can promisify this for loop
      Edit: I recreated the same environment you used in this video and spent 5 hours playing with worker threads. My original comment is wrong. While/for loop is still blocking even if it’s wrapped in a promise unless there is a promise within its conditional or within its block.

  • @djneils100
    @djneils100 Рік тому

    great video - helped my solve a problem - thanks Chaim!

  • @hsdev
    @hsdev Рік тому

    Thanks Chaim. This was very helpful.

  • @sankeths3508
    @sankeths3508 Рік тому +1

    can we define the pool size for this ?

  • @Kareszrk
    @Kareszrk Рік тому

    Thank you very much! This was exacly what I was looking for. :)

  • @thomasnguyen1150
    @thomasnguyen1150 Рік тому

    thank you very helpful

  • @CafeAsp
    @CafeAsp 9 місяців тому

    Awesome video

  • @ayami123
    @ayami123 2 роки тому +1

    Question, can I pass just a function inside the worker threads,
    or does it really need to be a file ?

  • @user-zt1hx3ci2v
    @user-zt1hx3ci2v 2 роки тому

    Thank you very much! More videos on the node! :)

  • @jeetchheda8916
    @jeetchheda8916 7 місяців тому

    Now, can you tell me the limitations of using this worker thread ? Like how many workers can we spawn ? does it depend on the CPU ? can it be used as promise.all() ?

  • @reassume4826
    @reassume4826 2 роки тому

    Straight to the point. Great.

  • @karlostj4683
    @karlostj4683 Рік тому

    Are there any threading concerns (race conditions, deadlocking, etc.) that can arise with Workers? For instance, is the registering of the worker.on('message'...) code guaranteed to execute before the worker calls its postMessage()?

  • @chiragkamatkamat
    @chiragkamatkamat 2 роки тому

    Simple and crisp, thanks

  • @arvi8843
    @arvi8843 Рік тому

    That's a great explanation! Thank you. 💯

  • @smnomad9276
    @smnomad9276 2 роки тому +1

    Great video man thanks a lot 🙏🏻💯 I run some bots written in JS, would this make them faster?

    • @litbro8180
      @litbro8180 2 роки тому +1

      It wouldn’t make them faster. But it would allow them to run in parallel if each of them has their own thread

  • @sainathkamble387
    @sainathkamble387 Рік тому

    Hey , I wanted to run some queries on a worker thread and passed in sequelize instnace to the thread but it failed , is there any way how we can pass sequelize instance to the thread and execute the queries on the difrent thread itself on nodejs ,it would have been much easier if it was GO

  • @soulninjadev
    @soulninjadev Рік тому

    awesome video, well presented and explained

  • @VikashSingh-wy3gd
    @VikashSingh-wy3gd 2 роки тому

    Should we always use worker thread instead of fork method of child process?

  • @samusaw
    @samusaw 2 роки тому

    brilliant, very good example!

  • @ShimonWosner
    @ShimonWosner 2 роки тому

    Thanks you, very clear explanation 👍

  • @gisdeveloper
    @gisdeveloper 2 роки тому

    Thanks you very much!

  • @royjosefsson5001
    @royjosefsson5001 Рік тому

    Are worker threads able to do the same requests as the main thread?
    I'm aggregating 5.2M documents on Mongodb. It's no problem aggregating on the main thread but it's taking for ever on the worker thread..?

  • @lucamartinsm
    @lucamartinsm 2 роки тому

    Great content! Thank you!!! :D

  • @code_lab_9994
    @code_lab_9994 Рік тому

    Hi chaim ! It was a nice explanation, but one thing i want to know about, if we make a worker thread then after it's process , will it not be an orphan task, so have we kill that child_process or not after completion?

    • @CodingWithChaim
      @CodingWithChaim  Рік тому +1

      great question! I actually dont know the answer off hand. My assumption would be that the worker will get cleaned up after its done the work, but I would have to verify to know for sure

    • @code_lab_9994
      @code_lab_9994 Рік тому

      @@CodingWithChaim Thanks for answer

  • @mckiernantim
    @mckiernantim Рік тому

    Question on cleanup - when working with a singular worker instance to we want to be instantiating a new worker for every call to that url? Is it a better practice to reuse them?

    • @CodingWithChaim
      @CodingWithChaim  Рік тому

      I would say its better to create a new worker for each request because this way we can scale. If we only had one worker that we kept re using, we would run into the same bottleneck we do as with the main thread

    • @mckiernantim
      @mckiernantim Рік тому

      @@CodingWithChaim can't believe you got back so quick! Last question - do we need to cleanup the old worker? This reminds me of RXJS observable patterns and I know that failure to cleanup observables can add up over time.
      Should we delete these workers after the message?

    • @CodingWithChaim
      @CodingWithChaim  Рік тому +1

      thats a great question! My hunch is that after they get used they will be garbage collected, but I would say you should verify that because I dont know that for sure

    • @mckiernantim
      @mckiernantim Рік тому

      @@CodingWithChaim launching my "covid-project" in two weeks with some decently heavy computational work. I had a thought like 'wait, does this block my event loop?' two days later I find your excellent , succinct solution. Thanks again for the help. I'll circle back if I find anything down the road.

    • @CodingWithChaim
      @CodingWithChaim  Рік тому

      glad you found the video, hope it helps

  • @frontend_ko
    @frontend_ko Рік тому

    okay, understood

  • @aldenasf
    @aldenasf Рік тому

    is there a way for the worker to run local function instead of another script?

    • @CodingWithChaim
      @CodingWithChaim  Рік тому

      nodejs.org/api/worker_threads.html#new-workerfilename-options seems like it has to be a file

  • @rameshramesh-bd2wu
    @rameshramesh-bd2wu 2 роки тому +1

    Watch at .75x speed

  • @kaypakaipa8559
    @kaypakaipa8559 2 роки тому

    If im running the exact same app not locally but on GCP Cloud Run, would it still hang? I assumed each request spun up a new instance of your app thua nullifying any thread issues from the heavy endpoint.

    • @CodingWithChaim
      @CodingWithChaim  2 роки тому

      Each request will not spin up a new instance of the app. I’m pretty sure that would only happen if you’re using a severless approach

  • @manoj-k
    @manoj-k 2 роки тому

    🔥🔥🔥

  • @itzik975
    @itzik975 Рік тому

    wow a jewish youtuber, thats rare, as rare as seeing a rainbow.
    not trying to be mean or anything just abit surprised, thats all, im jewish too so the more the better.
    Hello bytheway Chaim, really great english too, without any hebrew accent as well.
    thanks for the video, i'v found about worker threads through google ofc, while searching for cool things about nodejs.
    didn't quite understand how to use them so i got here, very well explain and articulated. i'll save for future reference.

  • @raymondpanjaitan9578
    @raymondpanjaitan9578 Рік тому

    gg sir

  • @PabloGnesutta
    @PabloGnesutta 2 роки тому +1

    While the explanation on how to use worker's is good,the example is really really bad.
    If this is an Endpoint that is exposed to the client, there will be potentially hundreds of thousands of requests to that endpoint, so the node application will spawn that numbers of new threads with it's corresponding node instances, event loops etc, which is a nightmare in terms of performance.
    So keep that in mind..use workers for heavy duty, yes, but not if it will be requested an inmensurable number of times

    • @trucheitor
      @trucheitor Рік тому

      So, if You have to do some chained awaits that update a database. How do you handle correctly the endpoint for anlot of users? I thought about doing nothing and let AWS spawn more tasks copies behind a las balancer. AM i right?

  • @ImTheDot
    @ImTheDot Рік тому

    Andrew Tate now teaches programming

  • @akmaldiraa
    @akmaldiraa Рік тому

    it's ilegal bruh :"

  • @Pareshbpatel
    @Pareshbpatel 7 місяців тому

    Node Worker Threads, beautifully explained. Thanks.
    {2024-01-22}

  • @ibadshaikh2215
    @ibadshaikh2215 2 роки тому

    Wonderful explanation!!!! Thank You!

  • @MrCompsci2787
    @MrCompsci2787 2 роки тому

    Beautiful explanation, thank you.