Erlang Basics--Introduction--History and Erlang concurrency

Source: Internet
Author: User
Tags riak rabbitmq

Objective

Recently summarizing some of the basics of Erlang programming languages, we are going to introduce the Erlang programming language from the base to the advanced, and then do the analysis of the interesting libraries in the Erlang programming language.

In fact, it is hoped that more and more people will focus on Erlang, using Erlang, to expand the Erlang programming language community.

To tell the truth, I am not so noble, is to see a lot of people on the Erlang programming language misunderstanding, Erlang programming language Community wither, recruit a erlang development difficult and difficult, only to sprout this thought.

This time we mainly introduce the Erlang programming language. Including the brief history of Erlang and the application scenario, Erlang concurrent programming, Erlang programming language features, environment installation just a little bit. Well, finally, I'm going to show you an example of a wordcount, and look at the Erlang concurrency process and what the distribution really looks like.

Erlang Brief History and application scenarios

How does Erlang come from? Grammatical strange, functional, look "ugly" to a lot of people do not like to use, but why many people also "boast" Erlang (I belong to the "boast" that the ticket person)?

Brief History

Erlang appeared in the mid 1980s and was developed by a laboratory under the jurisdiction of Ericsson, a Swedish telecommunications equipment manufacturer. That was the vote. In search of a programming language suitable for next-generation telecom products, Ericsson Labs spent more than two years using the prototype method to test all possible programming languages, eventually discovering that, while existing programming languages had some interesting and relevant features, But there is no independent language that embraces all the features required by the telecommunications industry. This makes them very uncomfortable.

Well, they decided to develop a new programming language.

By the year 1996, the Erlang programming framework OTP was born, and OTP gave the Erlang programming language system a structured framework and a set of tools and class libraries for robustness and fault tolerance. And then, in December 1998, Ericsson decided to release Erlang as an open source code. In January 1991, the official Erlang programming language Web site was about 36k, 10 years later, reaching 2800k. It seems that the Erlang community is growing (but this development speed, eh ... Or too worried about Mulberry).

Application Scenarios

Although many programming languages do not find their own location before development, the Erlang programming language is very well positioned to build a distributed , fault- tolerant , massively concurrent soft Real-time system. So Erlang is not only used in the telecommunications industry, but also in a variety of areas has been a great development and use.

    • im/push: WHATSAPP, Weibo private messages
    • Ad data: OpenX, AOL AD, Ptengine
    • Infrastructure: Riak, Ejabberd, RabbitMQ, RDS
    • Financial payment: Easy access, E-Banking
    • Games: 4399, Ming Dynasty

such as im/push field, advertising data field, infrastructure, financial payment, and games.

The 19 billion-knife acquisition of WhatsApp by Facebook is mainly used by Erlang,ejabberd and RABBITMQ in the Erlang circle, which is also a very well-known framework-level application.

Domestic do im/push the company a bit more, Beijing Circle, Weibo private message, ring letter, Gome, Shenzhen's cloud bar, incomplete statistics, I know there are about 10. Advertising data field, there are openx,aol ad abroad, the domestic ptengine (my club, ah, to do an advertisement, ptengine.com), Adsage. The distributed nature of Erlang makes it very convenient to build large-scale distributed systems. In infrastructure, Riak as a very well-known nosql, mainly developed with Erlang, the domestic erlang great God Yu Feng also uses Erlang to develop RDS. In the domestic financial payment field, the integration of Yi Tong and Shanghai Electric Bank, almost erlang in the domestic development advocates, for the domestic training of a bunch of erlang programmers.

Look, look, Erlang. With its excellent concurrency, distributed , fault-tolerant , soft real-time and other characteristics, many applications have been favored and large-scale use.

Erlang Concurrent Programming

Let's talk about the basic concepts and brief differences between concurrency and parallelism.

Now a lot of people will be called "concurrency", anyway, before finishing this blog, I have the difference between concurrency and parallelism is a bit vague.

Concurrency and parallelism

In daily life, concurrency and parallelism almost mean the same thing, but in programming languages, it's a precise distinction.

What is the concept of concurrency?

In computer operating systems, concurrency refers to the time interval in which several programs are running between the start and end runs, and these programs are run on the same processor, but at any one point only one program is running on the processor. There are three characteristics of concurrency:

    • Several programs are running within a single time interval
    • Several programs are run on the same processor
    • At the same moment, only one program will be running.

What is parallelism?

In the understanding of Chinese, parallelism refers to walking or being implemented concurrently, in the operating system, parallel refers to a set of programs in a separate asynchronous way, not equal to the overlap of time. When the operating system has two or more CPUs, one of the CPUs performs one thread (or process) operation, the other CPU can perform another thread (or process) operation, and two threads (or processes) do not preempt CPU resources, which can be done concurrently, this method is called parallel. Parallel is common in high-performance computing, like godson what the super-calculation, hydrodynamics and high-performance computing.

Difference?

concurrency and parallelism, which are two similar but differentiated concepts, parallel refers to two or more events occurring at the same point in time, while concurrency refers to two or more events occurring at the same interval. If you have only one single-core computer, you cannot execute a parallel program on your computer because the computer has only one CPU, and you can only do something at a time. However, concurrent programs can be executed on a single-core computer, and computers can share computer CPU events between different tasks.

What are the benefits of concurrency?

Concurrency can bring us many benefits that can improve the performance of our systems and create scalable and fault-tolerant systems.

The first benefit is to improve the performance of the system, imagine that there are two tasks, task A requires 10 seconds of execution time, task B takes 15 seconds to execute time, if only to perform task A and task B on a single CPU, the time required is 25 seconds. However, if it is on a computer with two CPUs, task A and task B need to be executed for only 15 seconds. If this performance improvement is to be achieved, concurrent programs are required. Now is the era of multi-core computers, usually using a PC is multicore, and 8-core CPU has become the basic standard of the server, 32 core, 64 core computer is not a rare configuration. and concurrent programs can better utilize multi-core CPU to maximize the performance of the system.

The second is extensibility, where concurrent programs are typically made up of small, independent processes, so increasing the number of processes and adding more computer CPUs can easily extend the system.

Thirdly, it can make the system clearer. In the real world, many things are concurrent, but the things in most programming languages happen sequentially. The difference between the real-world parallelism and the sequential nature of programming languages brings a lot of trouble. In the Erlang programming language, it is possible to visually map the real-world parallelism to the concurrency of Erlang, and to make program code and even architecture clearer and easier to understand.

In the Erlang programming language, the Erlang process is concurrent and executes independently. First, in the Erlang programming language, the Erlang process is different from the operating system process. Erlang's process is very lightweight and it has its own stack space. And the Erlang process is independent of each other, that is, each Erlang process has its own stack space and is completely private, and the stack space between the two Erlang processes is not shared. If two Erlang processes need to communicate, you can only use the way messages are sent. Therefore, in the heap space of the Erlang process, there is a need for a zone as the message mailbox for the Erlang process to communicate.

is the Erlang process stack structure, we can see that every process in the Erlang system has its own separate PCB structure, stack space, already heap space. Because of the lightweight nature of the Erlang process, a very large number of Erlang processes can be maintained in the system, which is one of the biggest differences from the operating system process. A large number of erlang processes, under the scheduling of Erlang virtual machines, can use multicore computers as much as possible to provide concurrency for the system.

The last point to note is that the concurrency of the Erlang programming language is provided by the Erlang virtual machine, not the operating system, nor the external library. The Erlang programming language is run on a virtual machine, so its concurrency works the same way on all operating systems.

Summarize

Erlang is widely used at home and abroad, many domestic teams belong to their own use of cool, foreign relatively "radical".

Reference:

1. Characterizing the scalability of Erlang VM

2. Several books of Erlang

The next article will focus on the features of the Erlang programming language, concurrent processes, distributed, and so on, quickly. Then you'll find out why Erlang is such a dick.

Erlang Basics--Introduction--History and Erlang concurrency

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.