教父的告白
一切都是纸老虎
posts - 82,  comments - 7,  trackbacks - 0
A Million-user Comet Application with Mochiweb, Part 1
在MacOSX平台上遇到的一些问题:

一. IPv6导致的问题
在MacOS下测试时报错econnrefused,mochi-urls.txt文件的url不能用localhost,得用127.0.0.1才行

在Erlang的邮件列表中找到了解释:
We have seen the same issue with CouchDB. What we found out
is that in our case localhost was not only resolving to 127.0.0.1 (IPv4)
but also ::1 (IPv6) and that http:request() would try to connect to
::1 where no service was listening.

Erlang的http模块缺省是打开IPv6模式的,当测试程序通过http模块连接localhost时,连接的地址是IPv6的::1地址,但是mochi没有在此监听,所以连接出错 {error,econnrefused}

解决方法两种:
1. 将mochi-urls.txt中的地址都改成127.0.0.1
2. 在http:request(…)运行之前调用http:set_options([{ipv6,disabled}]),关闭测试程序的IPv6模式,使用IPv4模式

理论上还有一种方法:让mochi服务器开启IPv6模式监听,这个我不知道这么开,
参考
You should teach Yaws to listen also on IPv6 - “localhost” resolves not
only to IPv4 127.0.0.1, but also to IPv6 ::1.


二. 进程能打开的文件描述符数量的限制
MacOSX下缺省能同时打开的文件描述符最大数是256个,使用 ulimit -a命令查看
$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) 6144
file size               (blocks, -f) unlimited
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 256
pipe size            (512 bytes, -p) 1
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 266
virtual memory          (kbytes, -v) unlimited
使用ulimit -n XXXX设置,但最大数量还是不能超过10240

查看内核每进程最大文件数:
$ sysctl kern.maxfiles kern.maxfilesperproc
kern.maxfiles: 12288
kern.maxfilesperproc: 10240

增大每进程最大文件数:
$ sudo sysctl -w kern.maxfilesperproc=20480 kern.maxfiles=22528

然后设置
$ ulimit -n 20480
注意ulimit只在每个shell窗口生命周期内有效,当新开一个shell后,得再次设置
sysctl做的修改没有这个问题

三、调节IP端口号范围,不然最多只能有15K个连接
缺省动态端口号从49152开始,改成2000后最多可以有63K个连接
sysctl -w net.inet.ip.portrange.hifirst=2000 net.inet.ip.portrange.first=2000
posted on 2009-09-24 00:59 暗夜教父 阅读(397) 评论(0)  编辑 收藏 引用 所属分类: erlang

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理



<2009年9月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

常用链接

留言簿(2)

随笔分类

随笔档案

文章分类

文章档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜