BFF architecture background for front
SSR server-side rendering, why do server-side rendering, improve SEO, and reduce http requests, the problem of slow first screen loading
How to deploy node and how to connect with nginx, how about security
vue + node
1. Analysis of the principle of asynchronous IO
a. The benefits of asynchronous IO
Front-end can eliminate UI blockage through asynchronous IO
IO is expensive, async IO is more expensive, doesn't that slow things down?
NodeJS is for IO-intensive, not CPU-intensive, Libuv does polling, asynchronous memory leaks
Libuv is the internal event polling mechanism of nodejs, used to support windows and Linux
After the node receives the request, it puts the request into libuv, and libuv turns on the event loop (event loop). The polling enables different mechanisms according to different systems. Linux is Thread pool, windows is IOCP, and the callback function is executed after the event is completed, which will data is pushed to the foreground,
Difference between cluster and fork
cluster is master
fork is a copy strategy
Basic knowledge:
CPU clock cycle, 1/cpu main frequency -> 1s/2.7 GHz, the clock cycle refers to the calculation time interval
2. Several special APIs
a. setTimeout and setInterval do not participate in the thread pool
b. process.nextTick() is implemented similarly,
c. setImmediate() has lower priority than process.nextTick()
d. How Node implements a sleep
async function test(){
console.log('hello');
await sleep(1000);
console.log('world');
}
function sleep(ms){
return new Promise(resolve => setTimeout(resolve,ms))
}
test();
3. Application of functional programming in Node
Higher-order functions, which take functions as input or return values, form a way of accepting results in a subsequent pass-through style, rather than a single return value form. A pass-behind-style program passes the business focus of the function from the return value into the callback function.
app.use(function(){})
var emitter = new events.EventEmitter;
emitter.on('', function(){})
Partial function (currying), the form of specifying some parameters to generate a new custom function is a partial function.
is to generate a function, and then return a function
var currying = function (fn) { // fn refers to the official's method of digesting his wife var args = [].slice.call(arguments, 1 ); // args refers to the legal wife return function () { // already have var newArgs = args.concat([].slice.call(arguments)); // These wives use fn to digest and utilize to complete the feat of Senior Wei Xiaobao and return return fn.apply( null , newArgs); }; };
4. Commonly used node control asynchronous technology
step、wind、bigpipe、Q.js
async await
Promise/defferred is a way to execute asynchronous calls first and delay delivery. Promises are the high-level interface, events are the low-level interface. The low-level interface can build more complex scenarios. Once the high-level interface is defined, it is not easy to change, and it no longer has the flexibility of the low-level interface, but it is very effective for solving problems.
https://www.cnblogs.com/kazetotori/p/6043983.html
The order in which methods are used async/await promise event callback function
Process An application is a process, and a process can have multiple threads
A program contains multiple coroutines, just like a process contains multiple threads. Multiple threads are relatively independent, have their own context, and the switching is controlled by the system; while the coroutine is also relatively independent and has its own context, but its switching is controlled by itself, and switching from the current coroutine to other coroutines is controlled by the current coroutine .
https://www.cnblogs.com/kex1n/p/7425972.html
http://cnodejs.org/topic/58ddd7a303d476b42d34c911
In my understanding of coroutines, coroutines are included in threads, and a thread contains multiple coroutines, that is, an asynchronous operation using promises will generate a coroutine.
5. Node memory management and optimization
a. v8 garbage collection mechanism
The memory usage of node is limited, which mainly depends on the source of v8. The 64-bit system can use 1.4G, and the 32-bit system can use 0.7G. Of course this is also configurable
Pass parameters when node starts