ãã£ããã®ã¤ãã³ãããªãã³ãã¬ã¼ã ã¯ã¼ã¯ãª POE ã§ããã Comet ã§ãã£ããããã£ã¦ã¿ãããã¨ã
http://d.hatena.ne.jp/dayflower/20061116/1163663677
ãã¡ãã® POE::Component::HTTP ã«ãã Comet ãã£ãããµã¼ãã§ãããã©ã®ãããã®æ¥ç¶ã¾ã§èããããã®ã? å®é¨ã
ã¯ã©ã¤ã¢ã³ãã¨ãã¦ãHTTP::Async ã使ã£ã¦åææ¥ç¶ãå¼µãã¾ããã¹ã¯ãªãããç¨æã
#!/usr/bin/perl use HTTP::Async; use HTTP::Request; use Time::HiRes qw/time/; use strict; my $slots = shift || 20; my $async = HTTP::Async->new( slots => $slots ); my $req = HTTP::Request->new( GET => 'http://localhost:8888/view' ); while ( 1 ) { my $start = time; $async->add( $req ) for ( 1 .. $slots ); my $conn_t = time - $start; printf "c,%d,%f,%f\n", $slots, $conn_t, $conn_t / $slots; $start = undef; my $count = 0; while ( my $res = $async->wait_for_next_response ) { $start = time unless $count++; } my $res_t = time - $start; printf "r,%d,%f,%f\n", $slots, $res_t, $res_t / $slots; sleep 1; }
long poll ãã url ã«æ¥ç¶ããã¬ã¹ãã³ã¹ãè¿ã£ã¦ããã 1ç§ sleep ãã¦åæ¥ç¶ãããã¨ãããã®ã
ã¾ãã¯ã¡ã¢ãªä½¿ç¨é (VSZ)ã
æ¥ç¶æ° | VSZ |
---|---|
0 | 13412 |
10 | 14008 |
20 | 14100 |
50 | 14232 |
100 | 14760 |
200 | 15816 |
300 | 17000 |
500 | 18980 |
1000 | 24260 |
2000 | 24656 |
次ã«æ¥ç¶æ°æ¯ã®ãã³ãã¯ã·ã§ã³ãå¼µãçµããã¾ã§ã®æé (c) ã¨ãlong poll ããè¿ã£ã¦ããã¬ã¹ãã³ã¹ã®æåã®ä¸ã¤ããåãåã£ã¦ããæå¾ã®ãåãåãã¾ã§ã®æé (r)ãåä½ã¯ç§ã
type | conn | time | per_conn ------+------+-------------+------------- c | 10 | 0.00859111 | 0.000859 r | 10 | 0.000830875 | 8.3125e-05 c | 50 | 0.0460453 | 0.000921 r | 50 | 0.0282752 | 0.0005655 c | 100 | 0.0924309 | 0.000924364 r | 100 | 0.073008 | 0.0007301 c | 200 | 0.19919 | 0.0009959 r | 200 | 0.234428 | 0.00117211 c | 300 | 3.30754 | 0.0110251 r | 300 | 0.528443 | 0.0017615 ========================================= c | 500 | 0.599251 | 0.00119875 r | 500 | 1.17672 | 0.00235343 c | 1000 | 1.35176 | 0.00135175 r | 1000 | 4.64576 | 0.00464571 c | 2000 | 2.62022 | 0.00131017 r | 2000 | 9.47508 | 0.0047376
æ¥ç¶æ°ãå¢ãããªããè¨æ¸¬ãã¦ã¿ãã¨ãã©ãã conn=230 ããããå¢ã«ãæ¥ã« (c) ãæªåããç¾è±¡ãçºçã
æåã¯ã¯ã©ã¤ã¢ã³ãå´ã®åé¡ã? ã¨æã£ãã®ã ããããã§ã¯ãªãã
fedora core 5 ã®ããã©ã«ãè¨å®ã§ãSOMAXCONN ã 128 ã«ãªã£ã¦ããã
# cat /proc/sys/net/core/somaxconn 128 # perl -MSocket -e 'print SOMAXCONN' 128
ã§ãPOE::Wheel::SocketFactory ã§ã SOMAXCONN ã®å¤ããqueue ã®æ大å¤ã«ä½¿ç¨ãã¦ããã
my $listen_queue = $params{ListenQueue} || SOMAXCONN;
ãã®å¤ã大ããããããæ¥ç¶ã«æéãæããç¾è±¡ã解æ¶ãããå ·ä½çã«ã¯
# echo 4096 > /proc/sys/net/core/somaxconn
ãã¦ãæ´ã«ãã£ãããµã¼ãã®ã¹ã¯ãªããã®æ¹ã§
sub Socket::SOMAXCONN { 4096 }
ã¨ãããæ¬æ¥ã¯ POE::Wheel::SocketFactory ã®ã³ã³ã¹ãã©ã¯ã¿ã§ ListenQueue å¼æ°ã渡ãã¹ããªã®ã ããããã PoCo::Server::TCP å
ã«ããããæãå
¥ãããããå¼·å¼ã ã Socket::SOMAXCONN ãåå®ç¾©ã
ã¨ãããã¨ã§ã(c) >= 500 ã®çµæ㯠SOMAXCONN ãããã£ãå¾ã®çµæã
çµæã«ã¤ãã¦ã¯ããã£ããã¨ãã¦å¿«é©ãªã¬ã¹ãã³ã¹ãã¨æããã®ã¯ (c)==500 ãããã¾ã§ããã¹ã¦ã® (500ã¯ã©ã¤ã¢ã³ãã«å¯¾ãã) ã¬ã¹ãã³ã¹éä¿¡ã 1ç§ã¡ãã£ã¨ã§çµããã
1000 ã«ãªãã¨ãçºè¨ãã¦ããåæ ãããã¾ã§ã«ææª 5ç§æããã®ã§ãã¡ãã£ã¨éãæãã(ãã¡ãããä¸çªæåã«åãåãã¯ã©ã¤ã¢ã³ãã¯ã»ã¼ 0ç§ã ããå¹³åã 㨠2.5 ç§)
ã¾ãã500ã1000æ¥ç¶ (ã»ã¼ç¹ãã£ã±ãªã) ã 1å°ã§ã¾ããªããã°ãçµæ§ããããããªãã§ããããã
- ãµã¼ãå´ã§è¤éãªå¦çãããã¨ã¡ã¢ãªä½¿ç¨éã¯ãã£ã¨å¢ããã¯ã (ã¯ã©ã¤ã¢ã³ãæ¯ã®ãªã½ã¼ã¹ã¯å¤§ãã¦å¤ãããªããã大ä¸å¤«ã?)
- ç¹ã«éä¿¡æã«æéãæãããã¨ãããã¨ãn ã¯ã©ã¤ã¢ã³ãã«ä¸æã«éä¿¡ããã®ã§ n åã§å¹ã
ãã®ã¸ãã«ã¯æ³¨æããã»ããããããã
1å°ã§æããªããã° â Spread Toolkit で Comet チャットサーバをクラスタリング - 酒日記 はてな支店 ã§ã