malaæ°ã® Studying HTTP with Perl ãè¦ãªããæ¸ãããã¼ãã®æ¸ æ¸
- ãªã¯ã¨ã¹ãã 5000/sec ã¨ãããã¨ãã®ããã®
- 200/secã§ãããã°å¥ã«LWP使ã£ã¦ãã°ããããã¸ã§ãå®é便å©ã ãã
é並åãªhttpã¢ã¯ã»ã¹
LWP::RobotUA | robots.txtè¦ããããã®ã§è¡åãè¯ã |
URI::Fetch | ãã£ãã·ã¥ã¨ããããã¤ã³ã¿ã¼ãã§ã¼ã¹ããã |
HTTP::Lite | ä¾åã¢ã¸ã¥ã¼ã«ãªããã©ãã§ã使ããã |
LWPx::ParanoidAgent | ãã¼ã«ã«IPã¯å¼¾ããWEBéæçãµã¼ãã¹ã« |
並åãªhttpã¢ã¯ã»ã¹
AnyEvent::HTTP | ç°¡å |
Coro::LWP | ã³ã«ã¼ãã³ãé»éè¡(ãªã«ããã¦ããç解ãã¦ä½¿ãã) |
AnyEvent::Curl | curlã®ãªãã·ã§ã³ãè¦ããªãã¦ã¯ãã¡ |
- Coro::LWPã¯LWPãcoro使ç¨ã«å
¨ã¦ç½®ãæãããã注æã
- coroãã®ãã®ãç¥ãã¾ããã
Curlã£ã¦
cURLã®ãã¨ãCpanè¨æ³ã ããCurlã ãã©å®éã®Curlã¯è¨èªã
curlã£ã¦ããã³ãã³ãã©ã¤ã³ã®fetchãwgetã®ä»²éã¿ãããªãã¤ãããã
perlã§ä¸¦åå¦çãããå ´å
ã¤ãã³ãé§åï¼prefork ãæé©è§£
- I/Oå¾ ã¡
- éåæ
- éãå¦ç
- worker
- ããããã³ã°
- forkãã¦å¥ããã»ã¹
preforkã¯è«¸åé¡ããããã¤ãã³ãé§åããããã
ãã¡ãããå¦çæéãã¢ã¯ã»ã¹æéãå®ç§ã«è¨ç®åºæ¥ãã®ã§ããã°preforkã®æ¹ãããã
æ©ããã¼ãµ
HTTP::Response::Parser
- ãããã¨ãLastModifiedã®é度ã¨ãbodyãåããããã®ãã¼ãµ
- æ¢åã®éã
- PurePerlã§ããã°ã£ã¦ãXSãã
- picohttpparserï¼ã¨ã¦ãåªç§ï¼ ã使ã£ã
- æ¬ ç¹ï¼ä»ã¯ä¸å®å®ï¼é¢é£libã®ãããverupãªã©å¾ ã¡
DNS解決ãé ã
RPC
ãããã³ã«ãä½ããªãhttpã§ãããhttpã¯å åæ©ãããæ±ç¨æ§é«ããã
ãã¹ãææ³
- ã¿ã¤ã ã¢ã¦ããããããåå¿é ããµã¼ããä½ã£ã¦ããã«ã¢ã¯ã»ã¹
- ãã¨ãèªè¨¼ã¨ãã¹ããªã¼ãã³ã°ã¨ã
- ãã¼ã¯ã¼ãï¼Plack, PSGI app
ã¿ã¤ã ã¢ã¦ããµã¼ãã®ã³ã¼ã
app => sub { my $env = shift; my $req = Plack::Request->new($env); sleep 2; return [ 200, [ 'Content-Type' => 'text/plain' ], ["Hellow World after 2 sec"] ]; },
ã¯ã©ã¤ã¢ã³ãå´ã®æ¹
client => sub { my $cb = shift; my $req = HTTP::Request->new(GET => "http://localhost/hello"); my $cv = $cb->($req, sub{}, {timeout => 1}); my $res = $cv->recv; ok( !$res->is_success, "fail by timeouot" ); is( $res->code, 500, "check status code"); is( $res->{error}, WWW::Curl::Easy->new->strerror(CURLE_OPERATION_TIMEDOUT), "error str" ); }
ããã