[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中取消息,随着 ...
随机推荐
- Bootstrap-Other:UI 编辑器
ylbtech-Bootstrap-Other:UI 编辑器 1.返回顶部 1. Bootstrap UI 编辑器 以下是 15 款最好的 Bootstrap 编辑器或者是在线编辑工具. 1. Boo ...
- OpenVPN添加本地路由方法
我只使用了第一种方法,第二种第三种没有测试. 1. 在OpenVPN配置文件中增加 OpenVPN在连接成功之后会自动增加一些路由,把默认网关改成VPN的,使所有流量都从VPN走.OpenVPN提供了 ...
- CFGym 101194D 题解
一.题目链接 http://codeforces.com/gym/101194/problem/D 二.题意 给定一个数字n和一个数字k,一个n个整数的序列,让你在里面找尽可能多的长度为k的符合“要求 ...
- 利用MessageFormat实现短信模板的匹配
其实没什么技术含量,因为老是想不起来,所以在此文做下记录. 通常我们的应用系统中都会有很多短信的发送,或者是信息邮件等的推送,而这些信息却有着相同的共性,比如只是用户名换了下. 像下面这条,除了红色字 ...
- Java下LDAP操作的资料
话说LDAP真是个诡异的protocol(或者数据库,或者服务,whatever...),没有一个特别形象的spec.这里列出一些筛选出的还可以的文档,都是oracle的: https://docs. ...
- Python 测试题目-1
l1 = [11,22,33]l2 = [22,33,44] # 1.获取内容相同的两个元素# 2.获取l1中有l2没有的元素# 3.获取l2中有l1中没有的元素# 4.获取l1 l2中内容都不通的元 ...
- 跟我学算法- tensorflow模型的保存与读取 tf.train.Saver()
save = tf.train.Saver() 通过save. save() 实现数据的加载 通过save.restore() 实现数据的导出 第一步: 数据的载入 import tensorflo ...
- 迷你MVVM框架 avalonjs 1.1发布
本版本添加了许多有用的功能,得益于用户量的增大,一些隐性BUG也暴露出来Fix掉了.强烈建议升级! 优化扫描流程: ms-skip(0) --> ms-important(1) --> m ...
- cluster DNS
[root@mhc1 dns]# pwd/root/test/k8s/kubernetes/cluster/addons/dns [root@mhc1 dns]# export DNS_SERVER_ ...
- python初步要点
[python初步要点] #! 用于告诉操作系统去哪里找Python解释器为运行您的程序. 1.print 的输出有以下2种形式,""%()的形式类似于C的printf. 要注意逗 ...