[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中取消息,随着 ...
随机推荐
- Partition does not start on physical sector boundary
今天给一块硬盘分区,用fdisk按照默认步骤执行,遇到这个问题: [root@bogon ~]# fdisk /dev/sdfDevice contains neither a valid DOS p ...
- PHP分多步骤填写发布信息的简单方法实例代码
1.php 复制代码 代码如下: <form name=form1 id=form1 method=post action=2.php> 基本信息1:<input type=text ...
- 手工编写servlet
index.jsp: <%@ page language="java" import="java.util.*" contentType="te ...
- curl获取响应时间
1.开启gzip请求curl -I http://www.sina.com.cn/ -H Accept-Encoding:gzip,defalte 2.监控网页的响应时间curl -o /dev/nu ...
- ES6系列_2之新的声明方式
在ES5中我们在声明时只有一种方法,就是使用var来进行声明,ES6对声明的进行了扩展,现在可以有三种声明方式. (1)var:它是variable的简写,可以理解成变量的意思. (2)let:它在英 ...
- plsql 中文乱码
plsql 中文乱码, 中文还是用ZHS16GBK insert into tt(id,name) values('2','张三'); select * from nls_database_param ...
- 使用openal与mpg123播放MP3,附带工程文件(转)
使用openal与mpg123播放MP3,附带工程文件 使用openal和mpg123播放MP3文件 使用静态编译,相关文件都在附件里 相关工程文件:openal_mpg123_player.7z 使 ...
- python 发送带附件的 邮件
from email.MIMETextimportMIMETextfrom email.MIMEMultipartimportMIMEMultipartimport smtplib mail_host ...
- python初步要点II
[python初步要点II] 1.is & is not 操作符用于测试2个对象是否指向同一个对象,即 id(a) == id(b). 2.整形和字符串对象是不可变对象,python会高效地缓 ...
- ORACLE BI Publisher Enterprise
二.带参数 BEGIN:{$FIRST_DAY_OF_MONTH()$} END:{$SYSDATE()$} 三\加下拉菜单值