今天遇到httpc:request()方法报错:html
调用方法:linux
$ erl 1>inets:start(). 2>Url = "http://example.com". 3>httpc:request(get, {Url, []}, [], []).
出错信息:shell
{error,{failed_connect,[{to_address,{"example.com", 80}}, {inet,[inet],nxdomain}]}}
首先考虑是防火墙和selinux的问题,把这些给关闭了:centos
$ /etc/init.d/iptables stop $ setenforce 0
可是仍是有问题,google一番,发现这个博客:缓存
发现下面有这个问题:并发
服务器没有启动 nscd 服务,没有缓存 DNS 使用UDP 协议,即便时内网,偶尔也会丢失 erlang 对于并发查询同一个DNS 会作合并,同时只会有一个DNS 请求 erlang 的系统调用超时时间太长(5s),没有及时的重发查询,形成期间请求堆积,等DNS返回,堆积的业务同时开始处理,形成CPU波动。 解决方案: 1. 启动nscd 2. 配置inet 使用内存dns 模块缓存
在centos测试:dom
$ yum install nscd -y $ service nscd start $ chkconfig nscd on
问题解决。测试