Erlang 及其 应用

24
Erlang 及及及及 及及 2009/03/11 http:// blog.yufeng.info

description

Erlang 及其 应用. 余 锋 2009/03/11 http://blog.yufeng.info. What is Erlang. - PowerPoint PPT Presentation

Transcript of Erlang 及其 应用

Page 1: Erlang 及其 应用

Erlang 及其应用

余锋 2009/03/11http://blog.yufeng.info

Page 2: Erlang 及其 应用

What is Erlang

• Erlang is a general-purpose programming language and runtime environment. Erlang has built-in support for concurrency, distribution and fault tolerance. Erlang is used in several large telecommunication systems from Ericsson.

Page 3: Erlang 及其 应用

What sort of applications is Erlang particularly suitable for

• Distributed, reliable, soft real concurrent systems. • Telecommunication systems, e.g. controlling a switch or converting

protocols.• Servers for Internet applications, e.g. a mail transfer agent, an IMAP-4

server, an HTTP server or a wap stack• Telecommunication applications, e.g. handling mobility in a mobile

network or providing unified messaging. • Database applications which require soft realtime behaviour.• Erlang is good at solving these sorts of problems because this is the

problem domain it was originally designed for. Stating the above in terms of features:

• Erlang provides a simple and powerful model for error containment and fault tolerance (supervised processes).

Page 4: Erlang 及其 应用

续上页

• Concurrency and message passing are a fundamental to the language. Applications written in Erlang are often composed of hundreds or thousands of lightweight processes. Context switching between Erlang processes is typically one or two orders of magnitude cheaper than switching between threads in a C program.

• Writing applications which are made of parts which execute on different machines (i.e. distributed applications) is easy. Erlang's distribution mechanisms are transparent: programs need not be aware that they are distributed.

• The OTP libraries provide support for many common problems in networking and telecommunications systems.

• The Erlang runtime environment (a virtual machine, much like the Java virtual machine) means that code compiled on one architecture runs anywhere. The runtime system also allows code in a running system to be updated without interrupting the program.

Page 5: Erlang 及其 应用

What is OTP?

• OTP (Open Telecom Platform) is a large collection of libraries for Erlang to do everything from compiling ASN.1 to providing a WWW server. Most projects using "Erlang" are actually using "Erlang/OTP", i.e. the language and the libraries. OTP is also open source.

Page 6: Erlang 及其 应用

Erlang 的优势

•高性能•多核心 SMP 的支持•透明分布的支持•完善的监控信息•商业产品上经过时间的验证成熟•轻量进程的支持

Page 7: Erlang 及其 应用

为什么其他语言要移植到 Erlang 虚拟机•语言 Reia 会成功吗•作者看中什么?

o 框架o 概念o 成熟度o 性能o 模型

Page 8: Erlang 及其 应用

Erlang 语言特性

• 简单小巧• 模式匹配• 变量单次赋值• 丰富的库• 灵活多样的错误处理• 代码热替换• 天生的分布式• 多核支持

Page 9: Erlang 及其 应用

Erlang 的代码规模

• 200K 行 C 代码 几千行 Erlang 代码o 同等的 ACE 框架

•代码成熟度•尺寸很小 适合于嵌入式

o 1.5M•也适合做桌面程序 如 p2p

Page 10: Erlang 及其 应用

Erlang ERTS 是个典型的网络服务器框架• IO 处理

o kernel poll 如 epoll kqueue•定时器处理

o timewheel•逻辑处理处理

o process coroutine fiber

o smp

Page 11: Erlang 及其 应用

纯消息驱动的系统

•多核心处理消息•调度器平衡迁移•同步和异步•无锁编程

Page 12: Erlang 及其 应用

多处理器利用技术

•线程o 调度器o 异步线程o driver 发起的线程

•精巧的锁 process_lock 快速的 mutex

•进程o PORT 管道通讯

Page 13: Erlang 及其 应用

强大的 PORT

• 仿照 Unix 的哲学 : 一切都是文件• 管道通讯类似 CGI• 对外世界的重要通道• 整合其他语言写的模块

Page 14: Erlang 及其 应用

与其他系统整合

• C 节点( EI)• Java (jinterface)• Cobra• TCP/HTTP

Page 15: Erlang 及其 应用

RPC

•内置的 RPC •自动维护节点的 up down•知道节点名称就可以通讯•轻松分拆服务

Page 16: Erlang 及其 应用

热部署功能

•不停机维护 •在线升级 系统同时跑新旧代码•发现问题在线降级•工具化 一切自动化

Page 17: Erlang 及其 应用

监控功能

• OS mon• SNMP• HTTP

Page 18: Erlang 及其 应用

代码安全

•代码可远程从网络加载 Diskless•代码可加密 强加密防止反编译•开源协议

Page 19: Erlang 及其 应用

远程维护

•强大的内置 shell• ssh sftp•日志系统

Page 20: Erlang 及其 应用

平台移植

• Windowso ( smp 支持的不好)

• *nix•关键语义屏蔽平台变化

Page 21: Erlang 及其 应用

和其他网络库的比较

• Erlang 相对于 ACE•完整的平台 工具

o 开发工具o 调优工具o 排错工具o 跟踪工具

Page 22: Erlang 及其 应用

应用障碍

• FP 语言•独特的哲学•社区小•库偏少

Page 23: Erlang 及其 应用

应用案例

• Facebook•盛大•金山•校内•很多小 startup公司

Page 24: Erlang 及其 应用

Q&A

谢谢大家