Introduction to OTP in Erlang _erlang

Source: Internet
Author: User

OTP includes 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 is OTP behavior, and 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 solving the function part.

The Gen_server module enables the exchange of things semantics and thermal code,

1) determine the callback module name
2) Writing interface functions
3 Write 6 required callback functions in the callback module

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

Copy Code code as follows:

$erl –boot START_SASL

Creates an environment that runs production systems, and the System Architecture support Library (Sasl,system Administration Support 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 the different line protocols
2 Erlang message without parsing, the receiving process does not need to resolve the message before processing, and the HTTP server must resolve all messages received
3 Erlang messages can contain arbitrarily complex data types, 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, rebar, and integrate GitHub. Cowboy is a high-performance Web server written in Erlang, a popular implementation of embedded web. In addition, library MOCHIWEB2 (http://github.com/mochi/mochiweb) encoding and decoding methods enable the conversion of JSON strings and 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 to avoid sequential bottlenecks, you can choose PMAP instead of map
4) Small message, large calculation
5) using MapReduce to make the computation parallel
Mapreaduce is a parallel high-order function, defined as

Copy Code code 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 a parallel higher-order function (PHOFS) module.

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.