OTP in Erlang Brief

Source: Internet
Author: User

The OTP contains a set of libraries and implementations that can build large-scale, fault-tolerant, and distributed applications, including many powerful tools to implement multiple protocols such as H248,SNMP, the core concept being the OTP behavior, which can be seen as an application framework with callback functions as parameters, similar to a Java EE container. Behavior is responsible for solving the non-functional part of the problem, and the callback function is responsible for resolving the function section.

Through the Gen_server module, we can realize the semantic and hot code exchange of things.

1) determine the callback module name

2) Writing interface functions

3) write 6 required callback functions in the callback module

When a server crashes, a mechanism is needed to detect and restart it, and to use the monitoring tree, which is to create a monitor to manage the server. There are two types of monitoring trees: one-to-many.

$erl –boot START_SASL

Creates an environment that runs production systems, and the System Architecture support Library (Sasl,system Administration supports libriaries) will be responsible for error logging and overload protection.

Using Gen_server, gen_supervisor,application and other behaviors, you can build a system with a reliability of 99.9999999.

Unified Erlang Message:

1) Abstract the difference between different line protocols

2) Erlang messages do not need to be parsed, the receiving process does not have to parse the message before processing, and the HTTP server must parse all the messages it received

3) Erlang messages can contain data types of any complexity, and HTTP messages must be serialized to be flattened for transmission

4) Erlang messages can be transferred between different processors

Common third-party libraries are rebar (Https://github.com/basho/rebar) and Cowboy (Https://githun.com/extend/cowboy). Rebar is the de facto standard for managing Erlang projects, where users can create new projects, compile projects, package them, and integrate them with other projects, while integrating GitHub with rebar. Cowboy is a high-performance Web server written in Erlang and is a popular implementation of the embedded web. In addition, the encoding and decoding methods of library MOCHIWEB2 (Http://github.com/mochi/mochiweb) enable the conversion of JSON strings to Erlang data types.

Erlang programs run on multi-core CPUs

1) Use a large number of processes

2) Avoid side effects, such as not using shared ETS or Dets

3) Avoid sequential bottlenecks, you can choose PMAP instead of map

4) Small message, big calculation

5) Parallelization of computations with MapReduce

Mapreaduce is a parallel high-order function, defined as follows

-specmapreduce (f1,f2,acc0,l)->ACC

F1 = Fun (pid,x)->void

F2 = Fun (key,[value],acc0)->ACC

L = [X]

ACC = X =term ()

Mapreduce is defined in the parallel higher-order function (PHOFS) module.

OTP in Erlang Brief

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.