[Erlang29]进程收到不是期望的消息时怎么办?
handle_info({add,X},Sum) ->
      {noreply,Sum+X};
{add,X}------->{plus,X}
在A进程中存着大量的{plus,X}信息,使得这个进程的内存占用也变得异常的大。
1.你可以记录这些消息:
1a.) as info
1b.) as warning
1c.) as error
2.对消息进行记数,然后对记数做怎样的处理?
3.直接忽略它们,不做trace?
4.让server直接crash掉?
I tend to go the log route. There isn't a super good reason, but the way
I think about it is a bit of probability. When do I send messages to the wrong process? A few ideas are: - Manual debugging
- Typoes
- A Refactoring gone bad
- Initial design got messed up
- Erroneous third-party code that doesn't come from my precise
development right away. Then the question is what are the consequences I want. - Manual debugging: do nothing, I'm poking around
- Typoes: I have to know about these ASAP
- Refactoring gone bad: I have to know about these ASAP
- Initial design got messed up: Something has to be loud and bad
- Third party code: I want the third party to suffer. For these reasons, I tend to take the following approach: - In handle_call/3, I log the event with a string a bit like
"mod=MYMOD at=handle_call warning=unexpected_call msg=~p" and then
return `{noreply, State}` to force the caller to crash after a
timeout. It's their fault, not mine.
- In other callbacks, just log similar messages, replacing
at=handle_call with at=handle_cast|info and
warning=unexpected_cast|info. I can, from time to time, look at logs for 'warning=unexpected_*' in
logs and see if something is going weird. If it's something happening rarely, I'm gonna have traces, but without
the weird failures (unless it's a call). If it's something frequent,
bugs will either show themselves differently, the log volume will be
very high, and so on. It tends to give me what I need given the circumstances. It's not always
as loud as I'd expect (except for calls, which is ideal), but it tends
to give me enough visibility for the occasional stray message, without
compromising service levels.
handlle_call(Msg,_From,State) ->
log:("mod=~p at=handle_call warning=unexpected_call msg=~p",[?MOdule,Msg]),
{noreply, State};
强制调用者Crash,这是他们的错,不能怪我.然后反复查看Log中是不是存在'warning=unexpected_*'信息。
Running Dialyzer on my codebase:

[Erlang29]进程收到不是期望的消息时怎么办?的更多相关文章
- Linux进程间通信--进程,信号,管道,消息队列,信号量,共享内存
		Linux进程间通信--进程,信号,管道,消息队列,信号量,共享内存 参考:<linux编程从入门到精通>,<Linux C程序设计大全>,<unix环境高级编程> ... 
- android 进程/线程管理(四)----消息机制的思考(自定义消息机制)
		关于android消息机制 已经写了3篇文章了,想要结束这个系列,总觉得少了点什么? 于是我就在想,android为什么要这个设计消息机制,使用消息机制是现在操作系统基本都会有的特点. 可是andro ... 
- WPF 加载 WINFORM控件 异常: 调度程序进程已挂起,但消息仍在处理中
		在加载TradeAtServer的统计中的 单个合约盈亏情况 异常:,调度程序进程已挂起,但消息仍在处理中 发现可能是属性设置引发的问题 比如DateTimePikcer.Value+= set, g ... 
- BCB 如何让Application收到SendMessage发送来的消息
		一般,都是通过添加一个ApplicationEvent组件就可以接收到PostMessage发来的消息,那么如何收到SendMessage发来的消息呢? https://stackoverflow.c ... 
- 在Boss直聘上投简历时,怎样保证有新消息时能及时收到
		最近在Boss直聘上投简历,偶尔会有HR给我发消息,不想在电脑上错过这些消息,但我又不能时时刻刻盯着这个页,怎么办呢? 这时,我想起来,之前做过的Chrome插件,如果检测到Boss直聘上新消息数大于 ... 
- 【Azure 服务总线】详解Azure Service Bus SDK中接收消息时设置的maxConcurrentCalls,prefetchCount参数
		(Azure Service Bus服务总线的两大类消息处理方式: 队列Queue和主题Topic) 问题描述 使用Service Bus作为企业消息代理,当有大量的数据堆积再Queue或Topic中 ... 
- WCF服务调用超时错误:套接字连接已中止。这可能是由于处理消息时出错或远程主机超过接收超时或者潜在的网络资源问题导致的。本地套接字超时是“00:05:30”(已解决)
		问题: 线上正式环境调用WCF服务正常,但是每次使用本地测试环境调用WCF服务时长就是出现:套接字连接已中止.这可能是由于处理消息时出错或远程主机超过接收超时或者潜在的网络资源问题导致的.本地套接字超 ... 
- Nginx 关于进程数 与CPU核心数相等时,进程间切换的代价是最小的-- 绑定CPU核心
		在阅读Nginx模块开发与架构模式一书时: "Nginx 上的进程数 与CPU核心数相等时(最好每个worker进程都绑定特定的CPU核心),进程间切换的代价是最小的;" &am ... 
- activeMQ消费消息时网络流量异常大的问题
		http://www.cnblogs.com/baibaluo/archive/2012/12/24/2748468.html#2590289 公司有一个应用,多个线程从activeMQ中取消息,随着 ... 
随机推荐
- ThreadCachedInt
			folly/ThreadCachedInt.h High-performance atomic increment using thread caching. folly/ThreadCachedIn ... 
- Solr分组聚合查询之Group
			摘要: Solr对结果的分组处理除了facet还可以使用group.Solr的group是根据某一字段对结果分组,将每一组内满足查询的结果按顺序返回. Group对比Facet Group和Facet ... 
- js 取元素相对页面的高度和宽度
			function pos(elem) { var x = elem.offsetLeft, y = elem.offsetTop; while (elem = elem.offsetPa ... 
- 「小程序JAVA实战」小程序的分享和下载功能(69)
			转自:https://idig8.com/2018/09/25/xiaochengxujavashizhanxiaochengxudefenxianghexiazaigongneng68/ 在小程序上 ... 
- auto_ptr 浅析(转)
			auto_ptr是C++标准库中(<utility>)为了解决资源泄漏的问题提供的一个智能指针类模板(注意:这只是一种简单的智能指针) auto_ptr的实现原理其实就是RAII,在构造的 ... 
- 跨域资源共享/option 请求产生原因
			https://blog.csdn.net/hfahe/article/details/7730944 
- 让 IE6支持max-height
			min-height min-height:100px; _height:100px max-height max-height:200px; overflow:auto;/*超出部分显示滚动条*/ ... 
- js中创建table表格
			<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ... 
- PHP与Imagemagick
			Imagemagick:相关站点: ImageMagick中文站:http://www.imagemagick.com.cn/ ImageMagick英文站:http://www.imagemagic ... 
- Docker RestApi Create mysql Container
			docker 提供了创建容器的rest api http://192.168.150.6:8888/containers/create?name=demo-mysql docker mysql容器的参 ... 
