Subject: | Use keep_alive in lwp-request |
Using keep-alive in lwp-request is useful if the requested URL is
redirected. Here's a call to such an URL with strace logging of
connect() system calls:
$ strace -econnect /opt/perl-5.14.2/bin/lwp-request -eS
http://www.microsoft.com
connect(3, {sa_family=AF_FILE, path="/var/run/nscd/socket"}, 110) = -1
ENOENT (No such file or directory)
connect(3, {sa_family=AF_FILE, path="/var/run/nscd/socket"}, 110) = -1
ENOENT (No such file or directory)
connect(3, {sa_family=AF_INET, sin_port=htons(53),
sin_addr=inet_addr("10.0.11.1")}, 16) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(80),
sin_addr=inet_addr("65.55.57.27")}, 16) = -1 EINPROGRESS (Operation now
in progress)
connect(3, {sa_family=AF_INET, sin_port=htons(80),
sin_addr=inet_addr("65.55.57.27")}, 16) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(53),
sin_addr=inet_addr("10.0.11.1")}, 16) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(80),
sin_addr=inet_addr("65.55.57.27")}, 16) = -1 EINPROGRESS (Operation now
in progress)
connect(3, {sa_family=AF_INET, sin_port=htons(80),
sin_addr=inet_addr("65.55.57.27")}, 16) = 0
GET http://www.microsoft.com
302 Found
...
If keep_alive is used, then the number of connect() syscalls is reduced:
$ strace -econnect perl5.14.2 ~/trash/lwp-request -eS
http://www.microsoft.com
connect(3, {sa_family=AF_FILE, path="/var/run/nscd/socket"}, 110) = -1
ENOENT (No such file or directory)
connect(3, {sa_family=AF_FILE, path="/var/run/nscd/socket"}, 110) = -1
ENOENT (No such file or directory)
connect(3, {sa_family=AF_INET, sin_port=htons(53),
sin_addr=inet_addr("10.0.11.1")}, 16) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(80),
sin_addr=inet_addr("65.55.57.27")}, 16) = -1 EINPROGRESS (Operation now
in progress)
connect(3, {sa_family=AF_INET, sin_port=htons(80),
sin_addr=inet_addr("65.55.57.27")}, 16) = 0
GET http://www.microsoft.com
302 Found
...
Here's a diff which implements unconditional use of keep-alive:
https://github.com/eserte/libwww-perl/commit/ec45894ff69014218ce6decca49ddf734fdb3fae
Regards,
Slaven