0% found this document useful (0 votes)
11 views15 pages

Seminar PPT

Uploaded by

rajabetting873
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views15 pages

Seminar PPT

Uploaded by

rajabetting873
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

SEMINAR PRESENTATION ON

Internals of Node.JS

Guided By- Rahul Ranjan


Name- Biswaranjan Mohanty
Regd. No- 2101289069
Roll No- 55
Branch- CSE-A

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


TRIDENT ACADEMY OF TECHNOLOGY, BHUBANESWAR
1.

Agenda:
 Introduction

 Understanding the V8 engine

 V8 Engine’s role in Node.JS

 The role of Libuv in Node.JS

 Event loop internals in Node.JS

 The Event Loop Concept

 Microtasks and Macrotasks

 Asynchronous I/O with Libuv

 Handling Concurrency in Node.js

 Conclusion

 References
What is Node JS ?
Node.js is a JavaScript runtime environment that is used for building web applications, including
the backend and frontend components. It's used for a variety of purposes, including:

• Real-time applications: Node.js is often used to develop real-time applications because of its
asynchronous, event-driven nature. This allows it to handle heavy input-output operations,
which is important for real-time applications.

• Single-page applications and dynamic websites: Node.js can handle multiple requests
asynchronously, which allows it to serve dynamic content to users.

• Scalability: Node.js applications can be easily scaled vertically and horizontally. Vertical
scaling allows you to add more resources to the current nodes, while horizontal scaling
allows you to add new nodes quicker.
Understanding the V8 Engine

Just-in-Time Compilation Garbage Collection Optimized for Performance


V8 utilizes a just-in-time (JIT) V8 uses a sophisticated garbage V8 is designed for high-
compilation technique, which collector to manage memory performance execution of
dynamically compiles JavaScript allocation and deallocation, JavaScript code, particularly for
code at runtime. This allows for freeing up developers from web applications and backend
faster execution of frequently manual memory management. services.
used code segments.
V8 Engine's Role in Node.js

JavaScript Runtime
Node.js utilizes the V8 engine as its JavaScript runtime
environment, providing a platform for executing JavaScript code
outside of a web browser.
Server-side JavaScript
V8's integration into Node.js enables the execution of JavaScript
code on servers, facilitating the development of back-end
applications.
Asynchronous Programming
Node.js leverages V8's support for asynchronous programming,
allowing for efficient handling of I/O operations and concurrent
tasks.
The Role of Libuv in Node.js

What is Libuv ?
Libuv is an open-source library that provides the core asynchronous I/O functionality for Node.js. It
allows Node.js to handle non-blocking operations, enabling high concurrency without needing
multithreading..

1 Asynchronous I/O 2 Event Loop 3 Cross-Platform 4 Thread Pool


Compatibility Management
Libuv handles all Libuv provides a core event Libuv supports multiple Libuv manages a thread
asynchronous I/O loop that manages events operating systems, pool for blocking I/O
operations in Node.js, triggered by I/O operations, ensuring Node.js operations, allowing
including network requests, enabling efficient handling applications can run Node.js to handle resource-
file system access, and of concurrent operations. seamlessly across different intensive tasks without
timers. platforms. blocking the event loop.
Event Loop Internals in Node.js

Phase 1: Timers
Executes callbacks for timers that have expired.

Phase 2: I/O Polling


Checks for I/O events, such as network connections and file system operations.

Phase 3: SetImmediate

Executes callbacks scheduled with setImmediate().

Phase 4: Close Callbacks


Executes callbacks for closing resources, like sockets and file handles.
The Event Loop Concept
The event loop is a continuous process that runs in the background and
continuously checks for events or tasks that need to be processed.

1 Check for Pending Events


The event loop checks if there are any events or tasks
waiting to be processed.

2 Process Events
If events are found, the event loop executes the
appropriate callbacks associated with those events.

3 Repeat
The event loop continuously repeats these steps, ensuring
that events and tasks are handled in a timely manner.
Microtasks and Macrotasks
The event loop distinguishes between different types of tasks, categorizing them as microtasks and macrotasks.

Microtasks Macrotasks

High priority tasks such as promises, Lower priority tasks, such as timers, I/O operations, and
process.nextTick(), and queueMicrotask(). setImmediate().
Asynchronous I/O with
Libuv
Non-Blocking Callbacks and Promises
Operations Node.js uses callbacks or
Libuv allows Node.js to Promises to handle
perform I/O operations asynchronous I/O results,
without blocking the main enabling efficient handling
thread, ensuring of multiple operations
responsiveness and high concurrently.
throughput.

Event Loop Management


Libuv's event loop manages the execution of callbacks when
I/O operations complete, ensuring efficient resource utilization.
Handling Concurrency in
Node.js

1 Single-Threaded Model
Node.js utilizes a single thread to handle all operations,
leveraging asynchronous I/O for concurrency.

2 Event Loop Management


The event loop efficiently schedules and executes tasks,
including I/O operations and callbacks.

3 Thread Pool for Blocking Operations


Libuv's thread pool handles resource-intensive blocking
operations, preventing the main thread from being blocked.
Conclusion
Node.js is a powerful and versatile platform for
building fast and scalable web applications.
Understanding the fundamentals of V8, Libuv,
and event-loop management is crucial for
building performant and reliable Node.js
applications.
Reference:
https://www.geeksforgeeks.org/nodejs/

https://zmushegh.medium.com/understanding-
libuv-the-powerhouse-behind-node-js-b5349c8f
0d75
THANK
YOU !!
Any Questions ?

You might also like