1.1. High concurrency
1. Process
- The smallest Execution Unit of Erlang is a process, and the biggest feature of the process is good isolation (with its own independent memory space, crash will not affect other work units ).
- Erlang process features
2. coroutine
- Switch by yourself
- Efficient. Because the system context (such as page tables) is not frequently switched, the efficiency is higher than that of operating systems.
3. Extremely Low Cost
- An Erlang process has more than 2 k overhead by default (mainly stack and default stack)
- Corresponding to an OS thread. Generally, the stack space is no less than 512 KB.
- Because it is a coroutine, the direct cost of process switching is extremely low
4. CPU affinity
- Coroutine, of course, you can control the Erlang process bound to a specific OS thread.
- This feature greatly avoids lock overhead
5. Zero lock Programming
- Function programming requires no locks.
- No global variables are available, and the process itself can only be accessed by itself. Therefore, the lock cannot be found.
- It is not absolute. For example, the language itself cannot solve the problem by relying on external heterogeneous resources.
- Erlang's process costs are so low that we can build our asynchronous system in synchronous mode. This is also true for its Implementation. Time-consuming operations will cause traps for the current process.
1.2. Fault Tolerance
1. built-in Fault Tolerance
- Process-based and highly isolated
- Supports exception capture
- Processes can establish relationships directly.
Two processes with a link relationship can perceive the end of another process. By default, they exit together.
2. Process and node monitoring
- There is a built-in monitoring mechanism to monitor a process or node, You can perceive them down
- The built-in support for failed restart starts with the-heart cmd flag. The current node crash can be restarted automatically. In this way, you do not need to write monitoring scripts on your own.
The supervisor can build processes into a tree structure based on the dependency, and the high-level nodes or leaf nodes are monitored by the lower layer.
The monitoring node determines the restart policy of the stator node based on the parameters.
- The restart interval for the current process to be suspended
- Maximum restart frequency within a specified time period
- Restart yourself | all processes | after the current process
1.3. Distributed support
1. the node location is transparent
You can connect to a node by node name without specifying a specific port number.
2. Automatic Connection
Communication process. If the two nodes are on, the two nodes can be automatically connected.
3. configurable connection protocols
The connection protocol between nodes can be configured, with built-in support for TCP and SSL, or you can develop your own protocol.
4. China Unicom
A connects B. If a is connected to C, then B and C can also perceive each other (nodes () and monitor can both perceive)
5. Transparent Routing
Processes can communicate with each other on the same node, across nodes, or across machines! Message.
Therefore, we can build our system in a unified manner.
6. Takeover
You can configure multiple nodes to run the specified application. The system selects the current service node in sequence. If the node fails, the node is selected in sequence. After the priority node is restored, it will snatch the operation right and provide services again.
7. Code Center
You can specify to run code on the specified machine.
The specific implementation is to run Erlang on the specified machine through SSH, copy the code to be run, and then execute it.
1.4. Code hot upgrade
Because there are no variables and they are all implemented based on functions, code hot upgrades can be implemented. (The execution entry is changed. All statuses are in the context of the process. The next call will include them in the parameters)
1.5. Port MPs queue
Erlang is a DSL and is not suitable for systems that are too complex to build services. He provides a mechanism for heterogeneous systems to communicate with each other, namely the port pipeline.
You can directly call an external application to connect to the external application stdin and stdout. You can also develop your own driver (for example, resident memory select input, output, and different callbacks at different stages)