Concurrency Model And Distributed Systems

Swapnil Kant
Javarevisited
Published in
7 min readFeb 7, 2021

Concurrency Model: The concurrency model in java is defined as the model which is responsible for carrying out the communication between the threads in the system which is responsible for carrying out the large or executing the large process running in the system along with proper synchronization to prevent partial reading or writing of the final value in the program which is running in the system.

Distributed Systems: Distributed system in computing is defined as a system where components of the software are connected or shared among different distributed computers in order to increase the efficiency of the system.

Different Concurrency Models In Java:

Fig 1.1: Parallel Workers Model

Parallel Workers Model: Parallel workers concurrency model in java is defined as the model where the work is assigned to different workers working in parallel to each other simultaneously with each thread executing different tasks parallelly either all different or subtasks of a single big task. Here each thread completes the full task and they may be running in different C.P.Us. The diagram describing the parallel workers model is given above, one of the biggest advantages of this model is that in this process no single thread or the worker is said to sit idle, it is easy to understand and implement and to increase the computation power of the system more number of threads or workers are added to the system, the diagram is as shown above.

Fig 2.2: Assembly Line Model

Assembly Line Model: This model is called so because the work gets executed in a line or one after another with some amount of work given to each worker to complete, this model is also known as the workers model, parallel worker model, reactive systems, or even event-driven systems. In this method, the workers are arranged in such a manner that is similar to the manner in which the workers are arranged in a factory. Not all the work is completed by a single worker, rather the work is divided into small parts and is executed by each and every worker in the queue line by line in a single direction. Working of the assembly line model is explained as when the work is given to be finished than during the I/O stage the worker does not wait for the C.P.U. to finish it’s completing of the task, rather as soon as the task is finished the next task is assigned to the next worker in the queue and this process is continued till the work is completed. Here each of the workers is independent and shares nothing with the neighboring workers, due to which the process goes concurrently, the diagram is as shown above.

Functional Parallelism: Parallelism is defined as doing multiple tasks parallelly in the system and functional parallelism is defined as multiple functions that are running or executing parallelly by using more than one C.P.Us in the system, this concept is new in Java 8 programming language. The value which is passed into the function gets copied to prevent the race conditions on the shared data of the program, and thus all the processes are carried interdependently within the system each different processes which run parallelly gets executed in the different processors within the computer, functional parallelism is only available in the systems where there is more than one processors or C.P.Us.

Advantages Of Parallel Workers Model: The advantages of parallel workers models are described below:-

  • It is easy to implement and easy to understand.
  • If the amount of work is high or more then to decrease the time complexity or to decrease the execution time more workers can be added to increase the work parallelly.

Disadvantages Of Parallel Workers Model: The disadvantages of the parallel workers model are:-

  • Due to multiple threads having access to the same stored data, the mechanism should be working in such an order so that, the multiple strings can correctly read and write the data into the storage space and the changes made on one thread is visible to other threads, avoiding deadlocks, race conditions, and other shared concurrency problems.
  • Due to waiting in the time given to different threads to get executed to finish the process, there is an increase in the number of threads waiting to get executed and it may happen that only a limited number of threads are given chance to get executed, due to which there is an increase in the serialization of the threads in the queue which were about to get parallelly executed, non-blocking concurrency algorithms may be used to decrease the contention, but they are hard to implement.
  • In case of a persistent list, a copy of the original content is preserved and when a thread tries to modify the data in the list then the modification takes place successfully but the copy of the data which has been created remains the same and all the other threads which are running can access the data from there, but this method although seems to be perfect but it too has some demerits which are that when there is any modification in the data all the changes are made in the head node and the function simply returns the reference to the newly created list but, still the previous threads in the list keep a reference of the previous first node of the list and hence the data remains unchanged and newly added elements cannot be seen.
  • One of the major disadvantages of this method is that this method is uncertain i.e. there is no guarantee of the system that the process will execute sequentially or will not, suppose if process 1 has to be executed after process 2 then it may happen that process 2 is executed after process 1, so we could not get the correct output from the system.
  • Since, the process gets executed concurrently so the reading of the data from the memory should be done parallelly but, re-reading data every time can get costly and more time taking which is not efficient.

Types Of Assembly Line Model: There are mainly two types of assembly model which are:-

Fig 3.3: Multiple Assembly Model

Multiple Assembly Model: This type of model comes under the parallel workers model where the task to be executed is divided into various subtasks and distributed among different workers, sometimes the task to be performed is so big so that the work has to be executed in parallel order distributed among many workers in different threads as shown in the diagram above.

Fig 4.4: Middle Assembly Line

Middle Assembly Line: This type of model mainly describes the assembly line where the work from workers in different threads is given to the same common worker to be executed as shown in the above diagram.

Advantages Of Assembly Line Model: The advantages of the assembly line model is described below:-

  • The workers are totally independent of each other and they entirely do not bother about the different concurrency problems that may arise from the shared data among the workers.
  • Due to the assembly line model, it is possible for the system to successfully schedule the job so that the work is carried out smoothly and with perfection when the jobs are written in the log then during the failure of the system, the jobs which are stored in the logs get executed from the place where the work has been stopped and resumes from the same place.
  • Since the work of a worker cannot be modified by the threads so the workers can be stateful and can use the data in the memory for calculation and processing purposes.

Some Terminologies Related To Assembly Line Model:

There are various terminologies related to the assembly line model few of which are described below:-

Fig 5.5: Actors in an assembly line model
  • Actors: Actors are responsible for communicating with the different components or different other actors in order to process one or more jobs as given in the case of the assembly line concurrency model, the model is described in the above diagram.
Fig: 6.6 Channels in an assembly line model
  • Channel: When different actors communicate with other different actors then, they cannot directly communicate with each other there is a special mode of communication used to publish their message that is through channels, the senders publish their messages via channels to communicate with other actors and the senders are unaware of whom the message is sent through these channels they just have an idea that through which channel they have to send or publish their messages, the channel is shown in the above diagram.

Keep learning and keep growing and also keep exploring more!

All the very best!

For more interesting and informative articles and tips follow me on Medium and Linkedin

--

--

Swapnil Kant
Javarevisited

Hi, I am Swapnil Kant, an avid programmer, and a full-time learner! One who is highly interested in Algorithm Optimization and Development