The book of Reading in layman's notes (Fri)

Source: Internet
Author: User

This article says about JavaScript's memory management issues in the V8 engine.

(1) In essence, node is based on the V8 engine to develop, V8 in a series of a bit to node, but also brought some flaws, such as memory limitations is one aspect. Because of the V8 limit, node can only use 1.4G of memory under a 64-bit machine, and it can only use 0.7G under 32-bit machines. V8 memory limit is to prevent the time spent in garbage collection is too long lead to the Dayton. This is covered in the article below.

(2) All JavaScript objects are allocated through the heap for memory allocation, V8 at the beginning of the application of a good heap of memory, the creation of JS object is used to allocate the heap, if the requested heap is not enough to allocate new objects, it will continue to apply for the heap, until the V8 limit of memory reached.

(3) V8 garbage collection mechanism: a generational garbage collection mechanism.

In V8, there are two main types of memory: objects in the Cenozoic have short survival time, objects in the Laosheng generation have long lived or reside in memory.

The new generation of memory object garbage collection algorithm: Scavenge algorithm: Heap memory in two, half use (from space), half idle (to space), allocated objects are only allocated to the From space, garbage collection when the From space alive objects copied to the to space, both swap roles. Cons: Only half of the heap memory is used

Promotion: When multiple copies of an object are still alive, they are moved to the Laosheng generation for management. It's called promotion. The promotion is based on two: whether the object is reclaimed by scavenge, whether or not the to space occupies more than 25%, and if it is exceeded, it is not conducive to the object assignment after the from space.

Laosheng Memory Object garbage collection mechanism: Mark-sweep and Mark-compact algorithms. That is, the markup cleanup algorithm. The first algorithm is to traverse the objects in the memory of the Laosheng generation, to mark the alive and to erase the dead. However, it can cause discontinuous fragments of memory space, and the second algorithm moves the living object to the same side at the time of the tag and clears the other side.

Note: In the garbage collection will let JS application logic pause, called ' full pause ', there are some ways to alleviate, there is no discussion here.

  

Next, the HTTP protocol has some very basic knowledge in node:

(1) There is an HTTP module in node that is used to build the Web service. It abstracts the read and write of the socket used as serverrequest and Serverresponse objects, respectively, corresponding to the request and response operation, when the request occurs, the HTTP module gets the data from the connection, calls the binary module Http_parse to parse the data.

(2) Serverrequest object:

(3) Serverresponse: The structure is similar to the top, and the response packet header requires the SetHeader () and Writeheader () methods to write

Res.writehead ($, {' Content-type ': ' Text/plain '});

Newspaper Style section with Res.write () and Res.end () to write, when you want to close the connection must be called with res.end (), otherwise the connection will always be in a waiting state.

  

The book of Reading in layman's notes (Fri)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.