Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Does nodejs mean js?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces nodejs refers to JS, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Nodejs is not a js, but a platform that lets js run on the server side. Js (full name JavaScript) is a programming language, while Node is a JavaScript runtime environment based on Chrome V8 engine, a development platform that allows JavaScript to run on the server side.

This tutorial operating environment: windows7 system, nodejs version 12.19.0, DELL G3 computer.

Nodejs is not a js, but a platform that lets js run on the server side.

Node.js was released in May 2009 and developed by Ryan Dahl. It is a JavaScript runtime environment based on Chrome V8 engine. It uses an event-driven, non-blocking I-peg O model to let JavaScript run on the server-side development platform. It makes JavaScript a scripting language on a par with PHP, Python, Perl, Ruby and other server-side languages.

JavaScript can be programmed on the server side based on Node.js technology.

Characteristics of Node.js

Non-blocking asynchronous io

For example, when accessing a database to get data, it takes a while. In the traditional single-threaded mechanism, after the code to access the database is executed, the entire thread will be paused and wait for the database to return the result before the following code can be executed. In other words, Imax O blocks the execution of the code and greatly reduces the execution efficiency of the program.

Because of the non-blocking Icano mechanism in Node.js, after executing the code that accesses the database, it will immediately turn to execute the following code, and put the processing code of the result returned by the database in the callback function, thus improving the execution efficiency of the program.

When the execution of an Icano finishes, the thread executing the Icano operation is notified in the form of an event, and the thread executes the callback function for the event. In order to handle asynchronous IDUBO, the thread must have an event loop, constantly checking for unhandled events and dealing with them in turn.

In blocking mode, a thread can only handle one task, and throughput must be multithreaded to improve throughput. In non-blocking mode, a thread is always performing computing operations, and the thread's CPU core utilization is always 100%. Therefore, this is a particularly philosophical solution: instead of having a large number of people, but a lot of people are idle, it is better to play with one's life and work to death.

Single thread

In server-side languages such as Java, PHP, or. Net, a new thread is created for each client connection. Each thread consumes about 2MB memory. In other words, in theory, a server with 8GB memory can connect to a maximum of about 4000 users at the same time. For Web applications to support more users, you need to increase the number of servers, and the hardware cost of Web applications goes up, of course.

Node.js does not create a new thread for each customer connection, but uses only one thread. When a user is connected, an internal event is triggered, and the Node.js program is macroscopically parallel through non-blocking I _ paw O and event-driven mechanism. Using Node.js, a server with 8GB memory, can handle more than 40, 000 connections at the same time.

In addition, with the benefits of single threading, the operating system no longer has the time overhead of thread creation and destruction. But single-threading also has many drawbacks, which will be explained in detail in Node.js. Please continue to read.

Event driven

In Node, the client requests to establish a connection, submit data, and so on, which will trigger the corresponding events. In Node, only one event callback function can be executed at a time, but in the middle of executing an event callback function, other events are generated, and you can turn to other events (for example, a new user is connected), and then return the callback function that continues to execute the original event, a handling mechanism called the "event ring" mechanism.

At the bottom of Node.js is C++ (V8 is also written by C++). Nearly half of the underlying code is used to build event queues and callback function queues. It is only a genius can think of using event-driven to complete the task scheduling of the server. The dance on the tip of the needle, with a thread, takes on the mission of dealing with a lot of tasks.

Notice the event loop here, which can also be said to be a quintessence of Node.js. Here is a quote from the official website of Node.js.

┌──┐┌─ > │ timers ││ └─┬─┘│ ┌─┴─┐│ │ pending callbacks ││ └ ─┬─┘│ ┌─┴─┐│ │ idle Prepare ││ └─┬─┘ ┌─┐│ ┌─┴─┐ │ incoming: ││ │ poll │

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report