在好例子网,分享、交流、成长!
您当前所在位置:首页Others 开发实例一般编程问题 → Erlang In Anger

Erlang In Anger

一般编程问题

下载此实例
  • 开发语言:Others
  • 实例大小:2.84M
  • 下载次数:3
  • 浏览次数:54
  • 发布时间:2022-01-27
  • 实例类别:一般编程问题
  • 发 布 人:孔佑
  • 文件格式:.pdf
  • 所需积分:2
 相关标签: Erlang

实例介绍

【实例简介】Erlang In Anger

【实例截图】

from clipboard


【核心代码】

Erlang In Anger.pdf

Contents
Introduction 1
I Writing Applications 4
1 How to Dive into a Code Base 5
1.1 Raw Erlang . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2 OTP Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.2.1 Library Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2.2 Regular Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2.3 Dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.3 OTP Releases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.4 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2 Building Open Source Erlang Software 12
2.1 Project Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.1.1 OTP Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.1.2 OTP Releases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.2 Supervisors and start_link Semantics . . . . . . . . . . . . . . . . . . . . . . 15
2.2.1 It’s About the Guarantees . . . . . . . . . . . . . . . . . . . . . . . . 15
2.2.2 Side Effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.2.3 Example: Initializing without guaranteeing connections . . . . . . . 16
2.2.4 In a nutshell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.2.5 Application Strategies . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3 Planning for Overload 20
3.1 Common Overload Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.1.1 error_logger Explodes . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.1.2 Locks and Blocking Operations . . . . . . . . . . . . . . . . . . . . . 22
3.1.3 Unexpected Messages . . . . . . . . . . . . . . . . . . . . . . . . . . 23
i
CONTENTS ii
3.2 Restricting Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.2.1 How Long Should a Time Out Be . . . . . . . . . . . . . . . . . . . . 24
3.2.2 Asking For Permission . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.2.3 What Users See . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.3 Discarding Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.3.1 Random Drop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.3.2 Queue Buffers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.3.3 Stack Buffers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.3.4 Time-Sensitive Buffers . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.3.5 Dealing With Constant Overload . . . . . . . . . . . . . . . . . . . . 29
3.3.6 How Do You Drop . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.4 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
II Diagnosing Applications 33
4 Connecting to Remote Nodes 34
4.1 Job Control Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
4.2 Remsh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
4.3 SSH Daemon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
4.4 Named Pipes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4.5 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
5 Runtime Metrics 39
5.1 Global View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
5.1.1 Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
5.1.2 CPU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
5.1.3 Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
5.1.4 Ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
5.2 Digging In . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
5.2.1 Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
5.2.2 OTP Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
5.2.3 Ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
5.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
6 Reading Crash Dumps 54
6.1 General View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
6.2 Full Mailboxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
6.3 Too Many (or too few) Processes . . . . . . . . . . . . . . . . . . . . . . . . 57
6.4 Too Many Ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
6.5 Can’t Allocate Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
CONTENTS iii
6.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
7 Memory Leaks 60
7.1 Common Sources of Leaks . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
7.1.1 Atom . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
7.1.2 Binary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
7.1.3 Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
7.1.4 ETS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
7.1.5 Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
7.1.6 Nothing in Particular . . . . . . . . . . . . . . . . . . . . . . . . . . 64
7.2 Binaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
7.2.1 Detecting Leaks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
7.2.2 Fixing Leaks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
7.3 Memory Fragmentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
7.3.1 Finding Fragmentation . . . . . . . . . . . . . . . . . . . . . . . . . . 67
7.3.2 Erlang’s Memory Model . . . . . . . . . . . . . . . . . . . . . . . . . 68
7.3.3 Fixing Memory Fragmentation with a Different Allocation Strategy . 74
7.4 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
8 CPU and Scheduler Hogs 76
8.1 Profiling and Reduction Counts . . . . . . . . . . . . . . . . . . . . . . . . . 76
8.2 System Monitors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
8.2.1 Suspended Ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
8.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
9 Tracing 80
9.1 Tracing Principles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
9.2 Tracing with Recon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
9.3 Example Sessions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
9.4 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Conclusion 87
List of Figures
1.1 Dependency graph of riak_cs, Basho’s open source cloud library. The graph
ignores dependencies on common applications like kernel and stdlib. Ovals
are applications, rectangles are library applications. . . . . . . . . . . . . . . 9
7.1 Erlang’s Memory allocators and their hierarchy. Not shown is the special su-
per carrier, optionally allowing to pre-allocate (and limit) all memory avail-
able to the Erlang VM since R16B03. . . . . . . . . . . . . . . . . . . . . . . 69
7.2 Example memory allocated in a specific sub-allocator . . . . . . . . . . . . . 70
7.3 Example memory allocated in a specific sub-allocator . . . . . . . . . . . . . 71
7.4 Example memory allocated in a specific sub-allocator . . . . . . . . . . . . . 72
9.1 What gets traced is the result of the intersection between the matching pids
and the matching trace patterns . . . . . . . . . . . . . . . . . . . . . . . . . 82

标签: Erlang

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警