Open In App

What is a demultiplexer ?

Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will learn about the demultiplexer in Node.js and about its reactor pattern.

Node.js is the most advanced framework available for web development and programming available till now. But Node.js framework is based on the event-driven architecture, i.e it will generate all the operations that will occur in the program and will have to wait for the I/O unit to request for the event which will eventually take place through the event demultiplexer and the event queue through which the instructions are passed to the computer.

Event looping:

The series of steps in which the event looping in Node.js takes place is as follows:

  • The event-driven architecture initiates the event demultiplexer and starts collection of data collection and then sends this collected data to the processor to apply arithmetic and logical operations to it.
  • After the I/O unit collects all the data and sends it to the processor, it continuously adds the processes to the event queue list so that they can be completed in a given sequence of FIFO (first-in-first-out).
  • When the processes are arranged in the queue list then, it starts popping each process one by one so that finally the queue gets empty on the completion of all processes.
  • When all the processes are removed from the queue, and the I/O unit is also not adding any more processes for event looping to the processor, the event demultiplexer stops the process for execution.

Event looping allows the user to create an infinite set of instructions for the processor in Node.js as it is an event-driven architecture process. Whenever any request to carry out a process comes, it goes to the event demultiplexer which sends the request of the process to the processor to apply the operation and add it to the queue and provides a callback option. The event queue then traverses all the data and applies de queue operation to them. The above process runs continuously until the event queue finally becomes empty and there are no processes left to execute, the event loop stops the process.

Reactor Pattern:

The Reactor Pattern in the Node.js web framework plays an important role in the functionality of the demultiplexer in the program. The Reactor Pattern pattern allows the user to prevent the stoppage of the operations which are processed by the I/O Unit operations. The I/O unit operations are directly provided to the demultiplexer in Node.js to avoid the blockage of the I/O requests. 

Basically two types of I/O unit operations:

  • Blocking I/O: It makes a synchronous function call to stop the execution from the I/O unit until it sends the data for the next time.
  • Non-Blocking I/O: It makes an asynchronous function call to continue with the execution of the program and it does not call the processor to block the input from the I/O unit.

Importance of Demultiplexer:

  • I/O unit is very slow: The I/O unit is very slow in performing the operations and it takes a lot of time for data transfer to the processor for the event looping in the Node.js framework. It takes a lot of time to delay indirectly communicating with the CPU data and it results in an increased latency in the program execution. Technically, increased latency in the program execution in Node.js will cause the time limit to be exceeded and the program execution will eventually. Hence, we use a demultiplexer to transfer the data quickly to the processor.
  • Blocking I/O: The Blocking I/O blocks the data transmission from the I/O unit to prevent the bulking of data in the processor until the previous instruction is finished by the processor, as it helps to increase the efficiency of execution. It is unable to handle a large number of requests which are sent by the I/O unit and hence it blocks the data from the I/O unit for a certain amount of time. So, to avoid any multi-threaded requests at the same time, it uses the vent looping approach in which the instructions which are approved by the demultiplexer proceed to the event queue, and then one by one they are then transferred to the processor for execution.
  • Non-Blocking I/O: The Non-Blocking I/O performs the data execution process in the processor without blocking the threads provided by the I/O unit for multiple requests. It uses the polling bus arbitration method in which the multithreaded request with the highest priority is placed first in the queue for execution and the rest are placed after it for the execution. It is a very time-consuming process as the CPU has to waste its clock cycle to decide the bus master and the priority of each thread request in the event looping.

Last Updated : 12 Jul, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments