Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Erlang及其应用

2,439 views

Published on

Published in: Technology, News & Politics
  • Be the first to comment

Erlang及其应用

  1. 1. Erlang 及其应用 余锋 2009/03/11 http://blog.yufeng.info
  2. 2. What is Erlang <ul><li>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 . </li></ul>
  3. 3. What sort of applications is Erlang particularly suitable for <ul><li>Distributed, reliable, soft real concurrent systems. </li></ul><ul><li>Telecommunication systems, e.g. controlling a switch or converting protocols. </li></ul><ul><li>Servers for Internet applications, e.g. a mail transfer agent, an IMAP-4 server, an HTTP server or a wap stack </li></ul><ul><li>Telecommunication applications, e.g. handling mobility in a mobile network or providing unified messaging. </li></ul><ul><li>Database applications which require soft realtime behaviour. </li></ul><ul><li>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: </li></ul><ul><li>Erlang provides a simple and powerful model for error containment and fault tolerance (supervised processes). </li></ul>
  4. 4. 续上页 <ul><li>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. </li></ul><ul><li>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. </li></ul><ul><li>The OTP libraries provide support for many common problems in networking and telecommunications systems. </li></ul><ul><li>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. </li></ul>
  5. 5. What is OTP? <ul><li>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 &quot;Erlang&quot; are actually using &quot;Erlang/OTP&quot;, i.e. the language and the libraries. OTP is also open source. </li></ul>
  6. 6. Erlang 的 优势 <ul><ul><li>高性能 </li></ul></ul><ul><ul><li>多核心 SMP 的支持 </li></ul></ul><ul><ul><li>透明分布的支持 </li></ul></ul><ul><ul><li>完善的 监控信息 </li></ul></ul><ul><ul><li>商 业产品上经过时间的验证成熟 </li></ul></ul><ul><ul><li>轻量进程的支持 </li></ul></ul>
  7. 7. 为什么其他语言要移植到 Erlang 虚 拟机 <ul><ul><li>语言 Reia 会成功 吗 </li></ul></ul><ul><ul><li>作者看中什么? </li></ul></ul><ul><ul><ul><li>框架 </li></ul></ul></ul><ul><ul><ul><li>概念 </li></ul></ul></ul><ul><ul><ul><li>成熟度 </li></ul></ul></ul><ul><ul><ul><li>性能 </li></ul></ul></ul><ul><ul><ul><li>模型 </li></ul></ul></ul>
  8. 8. Erlang 语言特性 <ul><li>简单小巧 </li></ul><ul><li>模式匹配 </li></ul><ul><li>变量单次赋值 </li></ul><ul><li>丰富的库 </li></ul><ul><li>灵活多样的错误处理 </li></ul><ul><li>代码热替换 </li></ul><ul><li>天生的分布式 </li></ul><ul><li>多核支持 </li></ul>
  9. 9. E rlang 的代 码规模 <ul><ul><li>200K 行 C 代 码 几千行 Erlang 代 码 </li></ul></ul><ul><ul><ul><li>同等的 ACE 框架 </li></ul></ul></ul><ul><ul><li>代 码成熟度 </li></ul></ul><ul><ul><li>尺寸很小 适合于嵌入式 </li></ul></ul><ul><ul><ul><li>1.5M </li></ul></ul></ul><ul><ul><li>也适合做桌面程序 如 p2p </li></ul></ul>
  10. 10. Erlang ERTS 是个典型的网 络服务器框架 <ul><ul><li>IO 处理 </li></ul></ul><ul><ul><ul><li>kernel poll 如 epoll kqueue </li></ul></ul></ul><ul><ul><li>定 时器处理 </li></ul></ul><ul><ul><ul><li>timewheel </li></ul></ul></ul><ul><ul><li>逻辑处理处理 </li></ul></ul><ul><ul><ul><li>process </li></ul></ul></ul><ul><ul><ul><ul><li>coroutine </li></ul></ul></ul></ul><ul><ul><ul><ul><li>fiber </li></ul></ul></ul></ul><ul><ul><ul><li>smp </li></ul></ul></ul>
  11. 11. 纯消息驱动的系统 <ul><li>多核心处理消息 </li></ul><ul><li>调度器平衡迁移 </li></ul><ul><li>同步和异步 </li></ul><ul><li>无锁编程 </li></ul>
  12. 12. 多 处理器利用技术 <ul><ul><li>线程 </li></ul></ul><ul><ul><ul><li>调度器 </li></ul></ul></ul><ul><ul><ul><li>异步 线程 </li></ul></ul></ul><ul><ul><ul><li>driver 发起的线程 </li></ul></ul></ul><ul><ul><li>精巧的 锁 </li></ul></ul><ul><ul><ul><ul><li>process_lock </li></ul></ul></ul></ul><ul><ul><ul><ul><li>快速的 mutex </li></ul></ul></ul></ul><ul><ul><li>进程 </li></ul></ul><ul><ul><ul><li>PORT 管道通 讯 </li></ul></ul></ul>
  13. 13. 强大的 PORT <ul><ul><li>仿照 Unix 的哲学 : 一切都是文件 </li></ul></ul><ul><ul><li>管道通 讯类似 CGI </li></ul></ul><ul><ul><li>对外世界的重要通道 </li></ul></ul><ul><ul><li>整合其他语言写的模块 </li></ul></ul>
  14. 14. 与其他系统整合 <ul><li>C 节点( EI) </li></ul><ul><li>Java (jinterface) </li></ul><ul><li>Cobra </li></ul><ul><li>TCP/HTTP </li></ul>
  15. 15. RPC <ul><li>内置的 RPC </li></ul><ul><li>自动维护节点的 up down </li></ul><ul><li>知道节点名称就可以通讯 </li></ul><ul><li>轻松分拆服务 </li></ul>
  16. 16. 热部署功能 <ul><li>不停机维护 </li></ul><ul><li>在线升级 系统同时跑新旧代码 </li></ul><ul><li>发现问题在线降级 </li></ul><ul><li>工具化 一切自动化 </li></ul>
  17. 17. 监控功能 <ul><li>OS mon </li></ul><ul><li>SNMP </li></ul><ul><li>HTTP </li></ul>
  18. 18. 代码安全 <ul><li>代码可远程从网络加载 Diskless </li></ul><ul><li>代码可加密 强加密防止反编译 </li></ul><ul><li>开源协议 </li></ul>
  19. 19. 远程维护 <ul><li>强大的内置 shell </li></ul><ul><li>ssh sftp </li></ul><ul><li>日志系统 </li></ul>
  20. 20. 平台移植 <ul><ul><li>Windows </li></ul></ul><ul><ul><ul><li>( smp 支持的不好) </li></ul></ul></ul><ul><ul><li>*nix </li></ul></ul><ul><ul><li>关 键语义屏蔽平台变化 </li></ul></ul>
  21. 21. 和其他网络库的比较 <ul><li>Erlang 相对于 ACE </li></ul><ul><li>完整的平台 工具 </li></ul><ul><ul><li>开发工具 </li></ul></ul><ul><ul><li>调优工具 </li></ul></ul><ul><ul><li>排错工具 </li></ul></ul><ul><ul><li>跟踪工具 </li></ul></ul>
  22. 22. 应用障碍 <ul><li>FP 语言 </li></ul><ul><li>独特的哲学 </li></ul><ul><li>社区小 </li></ul><ul><li>库偏少 </li></ul>
  23. 23. 应用案例 <ul><li>Facebook </li></ul><ul><li>盛大 </li></ul><ul><li>金山 </li></ul><ul><li>校内 </li></ul><ul><li>很多小 startup 公司 </li></ul>
  24. 24. Q&A <ul><li>谢谢大家 </li></ul>

×