Nodejs PHP Go Language understanding

Source: Internet
Author: User
Tags epoll
This is a creation in Article, where the information may have evolved or changed.

1, Nodejs

1) simply say that node. JS is the JavaScript that runs on the server.

2) node. JS is a platform built on the Chrome JavaScript runtime.

3) node. JS is an event-driven I/O server-side JavaScript environment, based on the Google V8 engine, the V8 engine executes JavaScript very quickly and with great performance.

4) The JS code we write is executed in a single-threaded environment, but the Nodejs itself is not single-threaded. If we call the asynchronous APIs (such as IO, etc.) provided by Nodejs in our code, they may be through the underlying C (c + +?) The module is completed in a different thread. But for our own JS code, they are in a single thread. Our code can only handle one at a time because the asynchronous function passes the result to us through the callback function.

5) We write the JS code like a king, and Nodejs to the king to provide a lot of servants. In the morning, a servant woke the king and asked him what he needed. The king gave him a list of all the tasks that needed to be done, and then went back to sleep. When the king went back to sleep, the servant left the king, took the list, and assigned the other servants a task. The servants were busy each other until they had finished their task before they came back and gave the result to the king. The king summoned only one person at a time, and the others were waiting outside in line. After the king has disposed of the result, he may have given him a new assignment, or he would have just let him go, and then summoned the next person. When all the results were finished, the king went back to sleep. A new servant came to see him after he had finished the task. This is the king's happy life.

6) Nodejs is not suitable for the development of CPU-intensive procedures, and the appropriate to do those IO operation is more, but it does not need to calculate too many programs. Because IO operations are performed asynchronously by Nodejs in other threads, it does not affect the main thread.

7" from his launch so far, full of praise and criticism is its single-threaded model, all the tasks are completed in one thread (I/O and other exceptions), the advantage of the place is to eliminate the overhead of frequent switching threads, as well as reduce the problem of resource mutual rob, etc. But when the Nodejs face the CPU-intensive model, it is powerless. Although node has an asynchronous mechanism, it is possible to throw some time-consuming algorithms into the eventloop waiting for the next event to loop, but because it is still a single-threaded model, it will eventually cause blocking.

first explain the two nouns, fibers and Threads. Fibers, also known as fiber, can be understood as a synergistic program, similar to PY and LUA have such a model. The use of fibers can avoid the mutual rob of resources, reduce CPU and memory consumption, but fibers not be able to really parallel execution, at the same time only one fibers in execution, if in one of the fibers do too much CPU operation or write a dead loop, The entire main program will be stuck. The asynchronous event loop model in node is a bit like this. Threads also known as threads, he can execute concurrently at the same moment, they share the memory of the main process, and at some point a certain Threads is locked, which does not affect the main thread and the execution of other threads. But to implement this model, we have to consume more memory and CPU overhead for thread switching, as well as the possibility that multiple threads can read and write to the same memory unit and cause the program to crash.


2. php

1) PHP is a powerful server-side scripting language for creating dynamic interactive sites.

2)PHP is a single-threaded script development language that often appears in web development and system integration.

Http://www.tuicool.com/articles/JNn2ai


3. Go

1) What is the advantage of Go
  • Can be directly compiled into machine code, do not rely on other libraries, glibc version has certain requirements, deployment is to throw a file up to complete.
  • Static type language, but there is the feeling of dynamic language, static type of language is can be compiled at the time to check out the most hidden problems, dynamic language feeling is that there are a lot of packages can be used, writing up the efficiency is very high.
  • Language level support concurrency, this is go the biggest feature, innate support concurrency, I once said a word, innate gene and plastic surgery is a difference, everyone is as beautiful, but you like plastic surgery or natural genetic beauty? Go is a gene that supports concurrency, makes full use of multicore, and is easy to use concurrently.
  • Built-in runtime, which supports garbage collection, is one of the features of dynamic languages, although the GC is not perfect at the moment, but it is sufficient to cope with most of the situations we can encounter, especially after Go1.1.
  • Easy to learn, go language authors have a C gene, then go naturally has a C gene, then the GO keyword is 25, but the ability to express is very powerful, almost support most of the features you have seen in other languages: inheritance, overloading, objects and so on.
  • Rich standard library, go now has built up a large number of libraries, especially the network library is very powerful, my favorite is this part.
  • Built-in powerful tools, the go language inside a lot of tool chain, the best should be gofmt tools, automated format code, can make the team review so simple, the code format is identical, it is difficult to think differently.
  • Cross-platform compilation, if you write the go code does not contain CGO, then you can do the window system to compile the application of Linux, how to do it? Go refers to the Plan9 code, which is information that does not depend on the system.
  • Embedded c support, said the author is the author of C, so go inside can also directly contain C code, using the existing rich C library.
2) Go fit to do what
    • Server programming, if you used C or C + + to do things, go to do a good job, such as processing logs, data packaging, virtual machine processing, file system and so on.
    • Distributed systems, database proxies, etc.
    • Network programming, which is currently the most widely used, including Web applications, API applications, download applications,
    • In-memory database, some time ago Google developed groupcache,couchbase part of the build
    • Cloud platform, at present, many foreign cloud platform in the use of Go development, cloudfoundy part of the formation of the former Vmare technical director himself out to engage in Apcera cloud platform.
3) The downside of go still exists
The following disadvantages are some of the problems I have encountered in project development:
    • Go import package does not support version, sometimes upgrade is easy to cause the project is not operational, so you need to control the corresponding version information
    • Go Goroutine once started, the switch between different goroutine is not controlled by the program, runtime scheduling, need rigorous logic, otherwise goroutine sleep, over a period of time logic ended, suddenly came out and executed, will lead to logic error and so on.
    • The GC delay is a bit large, I developed the log system hurt once, at the same time concurrency is very large case, processing a large log, the GC is not so fast, memory recovery is not a force, and later through the profile program improved after the improvement.
    • Pkg under the picture processing library a lot of bugs, or the use of mature products good, call these mature libraries ImageMagick interface more reliable


4. Select Poll Epoll

Select:http://www.cnblogs.com/anker/archive/2013/08/14/3258674.html

Poll:http://www.cnblogs.com/anker/archive/2013/08/15/3261006.html

Epoll:http://www.cnblogs.com/anker/archive/2013/08/17/3263780.html

Summarize:

(1) The Select,poll implementation requires itself to constantly poll all FD collections until the device is ready, during which time the sleep and wake-up cycles may be repeated. While Epoll actually needs to call Epoll_wait to constantly poll the ready linked list, there may be multiple sleep and wake alternates, but when it is device ready, call the callback function, put the ready FD into the Ready list, and wake the process into sleep in epoll_wait. While both sleep and alternate, select and poll traverse the entire FD collection while "Awake", while Epoll is "awake" as long as it is OK to determine if the ready list is empty, which saves a lot of CPU time. This is the performance boost that the callback mechanism brings.

(2) Select,poll each call to the FD set from the user state to the kernel state copy once, and to the device to wait for the queue to hang once, and epoll as long as a copy, and the current to wait for the queue is hung only once (in Epoll_ At the start of wait, note that the wait queue here is not the device waiting queue, just a epoll internally defined wait queue. This can also save a lot of overhead.



5, UNIX and Linux BSD relationship description

both Linux and BSD are UNIX-like operating systems. We can find that Linux and BSD have different lineages by reading the Unix-like operating system history. Linux was developed by Linus Torvalds at a university in Finland. BSD stands for "Berkeley software distribution, Berkeley software Suite", which stems from a series of modifications to the Bell Labs UNIX developed at UC Berkeley, which eventually developed into a complete operating system and now has several different BSD branches.

Https://linux.cn/article-3186-1.html





Related Article

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.