Java Concurrency Interview - What is an Ideal Threadpool size?

preview_player
Показать описание
Answer - the size depends on number of CPU cores and whether the task is CPU bound or IO bound.

For CPU bound (CPU intensive) tasks, the ideal size is same as number of CPU cores.

For IO bound tasks, ideal size depends on the wait time of the IO task. More the wait time, more number of threads can be used to ensure maximum CPU utilization.

Channel
----------------------------------
Complex concepts explained in short & simple manner. Topics include Java Concurrency, Spring Boot, Microservices, Distributed Systems etc. Feel free to ask any doubts in the comments. Also happy to take requests for new videos.

New video added every weekend.

Popular Videos
----------------------------------
Рекомендации по теме
Комментарии
Автор

It's been a while since your last video! please share your knowledge again, you have a very good way of explanation. you might as well do udemy courses or create a paid courses on your youtube channel

adame
Автор

Hello Defog Tech
Thanks for the clear and candid explanation.

PFB, one of the formulae for ideal number of threads.


#of Threads <= (#of cores)/ (1-blockingFactor) where 0<= blockingFactor < 1

CPU Bound blockingFactor = 0.0 then zero time is dedicated for IO.--> #of Threads <= (#of cores)
IO Bound blockingFactor = 0.5 then half time is dedicated for IO --> #of Threads <= 2 * (#of cores)

sayyedyasin
Автор

This video has the clearest explanations around this topic from what I have ever watched!

zackzhu
Автор

Hey the channel is amazing! Just wanted to know when will you start uploading new videos?

dishithpoojary
Автор

Done thanks
CPU bound tasks (no blocking) pool size is number of cores
7:30 IO bound task diagram
11:30 Formula for number of cores

wait time is how much time the thread is in wait state, and cpu time is how much time the thread spends executing

For example, if the task executes for 1 second and 0.5 seconds of that is blocked on IO, then ideal thread count will be if we have 1 core
1(1+ (0.5/0.5)) = 2 threads

What if the task blocks longer? Say total execution time 1 second but 0.8 blocked
Ideal thread count = 1*(1+(0.8/0.2)) = 5

mostinho
Автор

best explanation i have come across so far on threadpool and its dilema. I spent last one week reading windows via c trying to understand what you explained here in under 15 mins. Thanks a lot.

nareshnegi
Автор

Wow... A very complex topic in a very simple way...Love you man.

peeyar
Автор

This word would not enough but please take it as appreciation far beyond : AWESOME

prateekkanujiya
Автор

learned a lot, useful to tlak about these things for any lowlevel design discussion,

staff eng level experience gained!!!

kumarc
Автор

Pls continue uploading new videos.. The channel is idle, you should continue.. it is really amazing..

ramkumar_balu
Автор

Your explanations are amazing. I believe, you ARE the gift given me for all the efforts I made before by learning Java and Spring :D . Thank you a lot!

dmitrikonnov
Автор

These really are excellent videos. I've been a software engineer for almost a decade now, and while I more or less understand concurrency theory for distributed systems (well, as much as anyone CAN understand it :) ), I will admit that I never really bothered learning much about low-to-mid-level multithreading. These videos are easy to follow, well presented, and provide a lot of "bang for your buck" time-wise.

tombert
Автор

Please start making videos again. Your videos are very informative and easily understandable. Hope to see you soon making videos.

harry
Автор

Please continue posting videos. Not everyone can explain complex concepts in a simple manner.

fakruu
Автор

For people who don't have patience:
The answer is: it depends on whether the task is CPU intensive or IO intesive. If it's CPU intensive, it is = number of cores, if it's IO bound, it is = depends on how much time the IO intensive task is eating on CPU. Usually much more than the number of cores.

SreeAn
Автор

what an explanation brother, really good, clear and very helpful .. thanks a ton!!

shachindrapandit
Автор

This advice is true if it assumes that there are no other threads running on the computer computer but of course there are thousands of threads running typically or at least hundred and so the more threads you allocate the more the scheduler gives time to your application. In addition to increasing the nice number / priority

johnathanrice
Автор

13:31 "L1/L2 etc need to be flushed during a thread switch", while it's architecture specific this is only needed for switching between processes, however if switching between different threads in the same process they share the same address space, so no flushing is needed (ignoring relevant fences). Also it the L2 cache is shared between multiple cores and wouldn't be flushed however the TLB and L1 potentially are.

reductor_
Автор

One of the best explanations for thread pooling I have seen so far which many have failed to do. It would be great if you can extend the discussion on how hyperthreading works along with thread pools.

asthiwanka
Автор

You are one of the best tech youtubers. Please come back to youtube.

anthonya