first thing is concurrency and parallelism this sounds kind of a similar but they are not concurrency basically means that you execute things that are overlapping in time so you could have two or three any number of things executing and there seem to be executing at the same time but not necessarily they are happening in parallel so in order to do parallelism then you have you can execute multiple processes or have multiple threads right if you have a multi-core system Hardware then they could execute literally at the same time so what is the process and what is a thread basically there are many resources that on the internet that define them very well and they are also goods etc but here I will I will give you a very quick summary basically both are independent flows of execution in a in a program let's say but a process is at the program level and a threat is inside the process right so you can have multiple processes in each of the process having multiple threads up thread of a process share the memory the
same memory space so if you have different processes they will have their own memory space but if you have a thread like all the threads inside the process will share them the same memory space and that has some connotations where you are tackling concurrency when programming using multiple threads
then it's called multi-threading programming .
multi-threading programming can be very useful for your program because it will allow you to execute things in parallel and so times improved efficiency or the execution time of your program it's very
tricky sometimes to know how many threads you should use and it would depend a lot on your use case on the programming languages are you using on the operating system the machine that you are then used in basically if you really really want to have an optimized the most optimized version you need to
do benchmarking and check what is improving or not the performance of your application
during general there are different roles that allow you to more or less have an idea at least how to discuss the performance of your program if you want to do a concurrency or if you want to
implement multi-threaded solution traditional rule of thumb is to have as many threads of course have your hardware machine right and this is a rule of thumb but it's it's not always the way to go that's a because you can have things for example that execute always sequentially right so even if you
have four core or eight cores or how many cores you will need still to execute things sequentially you are not going to do better having four or eight threat versus having only one there are also other cases where you're doing a lot of calculations that can be wrong in powering in which case you cannot do
more calculations that the CPU allows you at the same time so if you have four cores then you will have probably four threads executing calculations on all of them but also if you have IO or input I would operations during those times the CPU is going to be idle so it doesn't matter if you only have four threads in the four of them are doing I all like waiting for the t-score doing a requested data base or resolving a request from a user on the web server then the CPU is going to be either in those cases so in n that case might be useful to have more threats than the CPU cores because you will be able to always
have a tray that is executing something if you have to feel or too many threads your application can run significantly slower so it's very important to have this kind of reflection when you are thinking about doing things concurrently or and this is something very important to have when you're discussing with your teammates when you are a new solution and you want to define what is going to be the best way to optimize your server for example or your application it's good to have these kind of discussions but of course it's also very important or anything like an interviews if you need to you know think about these topics right like why you're taking one decision versus another what is going to be the performance impact of doing something versus another in terms of concurrency so that's it for today.
Thank you very much for Reade and if you liked the Article don't forget to click the like button, follow, share it. And if I missed something, or you want me to explain something a little bit better don't forget to mention it in the comments.