松永です。

nodeに興味が出て、勉強のprogramを書いてるところです。
javascript自体、ecma 
scriptの仕様書を見ながら書いているレベルなので、node自体の使い方の質問では無く、javascriptの質問になっているかもしれませんが、その際は指摘していただければと思います。


書いているのは、httpへの負荷をかけるツールです。
書いたcodeを質問用に簡略化したのが、
https://github.com/vikke/node.testprograms/blob/961e54c3fbde0d53b9daafdd80a694d07539f896/http-request.js
です。
簡略化前が
https://github.com/vikke/node.testprograms/blob/2ee4953377838ced85c58ce715fb957bf1490906/http-request.js
です。

これを走らせると
--------------------------------------------------
(node) warning: possible EventEmitter memory leak detected. 21 listeners added. 
Use emitter.setMaxListeners() to increase limit.
Trace
    at Socket.<anonymous> (events.js:167:15)
    at Socket.once (events.js:188:8)
    at ClientRequest.<anonymous> 
(/home/vikke/vcswork/node.testprograms/http-request.js:52:13)
    at ClientRequest.g (events.js:184:14)
    at ClientRequest.emit (events.js:114:20)
    at http.js:1432:9
    at EventEmitter._tickCallback (node.js:245:11)
--------------------------------------------------
のようなwarningが出ます。

疑問なのが
1.
51行目で、走ると思われる並列数分setMaxListeners()しているのに、それ以上のlistenerを追加しようとしているのはなぜ?

2.
そもそも、http接続毎に生成されるhttp.ClientRequest用のsocketのconnect 
eventを、once()でつかまえようとしているのに、複数回のlistener登録が行なわれるのはなぜ?

3.
結局どう書くのがnode流なの?


使っているnodeはubuntu 12.04上にnvmで導入した0.7.8です。

以上、よろしくお願いします。

-- 
MATSUNAGA Ichiro
e-mail: [email protected]
who am i: https://plus.google.com/103000727838025680940/about

GPG fingerprint = DCEF C86E 2930 45D0 0941  E977 4DCE A95F 3914 4BED

Attachment: pgplDjFTqoyw9.pgp
Description: PGP signature

メールによる返信