250 likes | 552 Views
Erlang 及其 应用. 余 锋 2009/03/11 http://blog.yufeng.info. What is Erlang.
E N D
Erlang及其应用 余锋 2009/03/11 http://blog.yufeng.info
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.
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).
续上页 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.
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.
Erlang的优势 高性能 多核心SMP的支持 透明分布的支持 完善的监控信息 商业产品上经过时间的验证成熟 轻量进程的支持
为什么其他语言要移植到Erlang虚拟机 语言Reia会成功吗 作者看中什么? 框架 概念 成熟度 性能 模型
Erlang语言特性 简单小巧 模式匹配 变量单次赋值 丰富的库 灵活多样的错误处理 代码热替换 天生的分布式 多核支持
Erlang的代码规模 200K行C代码几千行Erlang代码 同等的ACE框架 代码成熟度 尺寸很小适合于嵌入式 1.5M 也适合做桌面程序如p2p
Erlang ERTS是个典型的网络服务器框架 IO处理 kernel poll 如epoll kqueue 定时器处理 timewheel 逻辑处理处理 process coroutine fiber smp
纯消息驱动的系统 多核心处理消息 调度器平衡迁移 同步和异步 无锁编程
多处理器利用技术 线程 调度器 异步线程 driver发起的线程 精巧的锁 process_lock 快速的mutex 进程 PORT 管道通讯
强大的PORT 仿照Unix的哲学: 一切都是文件 管道通讯类似CGI 对外世界的重要通道 整合其他语言写的模块
与其他系统整合 C节点(EI) Java (jinterface) Cobra TCP/HTTP
RPC 内置的RPC 自动维护节点的up down 知道节点名称就可以通讯 轻松分拆服务
热部署功能 不停机维护 在线升级系统同时跑新旧代码 发现问题在线降级 工具化一切自动化
监控功能 OS mon SNMP HTTP
代码安全 代码可远程从网络加载 Diskless 代码可加密强加密防止反编译 开源协议
远程维护 强大的内置shell ssh sftp 日志系统
平台移植 Windows (smp支持的不好) *nix 关键语义屏蔽平台变化
和其他网络库的比较 Erlang 相对于 ACE 完整的平台工具 开发工具 调优工具 排错工具 跟踪工具
应用障碍 FP语言 独特的哲学 社区小 库偏少
应用案例 Facebook 盛大 金山 校内 很多小startup公司
Q&A 谢谢大家