LWP::UserAgent Change socket attributes
Bernard CLABOTS via libwww <[email protected]> Fri, 29 May 2020 08:24:03 +0000 (UTC)
| Newsgroups | gmane.comp.lang.perl.modules.lwp |
|---|---|
| Message-ID | <[email protected]> |
------=_Part_2442343_321909817.1590740643484
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Hi All,
=C2=A0=C2=A0 I'm really new to perl and as usual in our business world I ha=
ve to be productive while I still learn.
=C2=A0=C2=A0 I'm running checks in IOT over REST API's and I saw that my sc=
ript using the LWP::UserAgent::Determined is generating loads of useless sy=
n in case of outages:
If I have a small glitch on the connection of a few minutes, I start sendin=
g thousands of SYN's as my devices are unreachable and every attempt genera=
tes 6 retries (only 5 are visible as the $ua->timeout is set to 60)...
=C2=A0=C2=A0 I searched a few hours and I figured out it was a unix socket =
feature.
=C2=A0=C2=A0 A few hours later, I found a topic on this website concerning =
the socket settings (https://www.nntp.perl.org/group/perl.libwww/2005/12/ms=
g6480.html). I tried and, naturally, it is no longer working, as the LWP::U=
serAgent(::Determined) is now relying on IO::Socket, as I finally read else=
where.
I understand that I can play with the $ua->timeout attribute to achieve the=
same, but that would also affect long running request and potentially have=
devastating consequences (I would need to reduce the timeout to 14seconds =
instead of 60 to achieve the same effect as SYNCNT 2).
=C2=A0=C2=A0 Now, I tried to implement the same method as in the post above=
with the IO::Socket, but it doesn't work. I can't find anything similar to=
"Implementor" (I understand what I want to achieve but my perl grammar is =
way too basic to know how to):
use IO::Socket;
{
package MySocket;
use base 'IO::Socket';
#IO::Socket::implementor(AF_INET =3D> __PACKAGE__); <<<<<<????
package MySocket::INET;
use base 'IO::Socket::INET';
use Socket qw(IPPROTO_TCP TCP_SYNCNT);
=C2=A0=C2=A0=C2=A0 sub new {
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 my $class =3D shift;
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 my $sock =3D $class->SUPER::new(@_);
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if ($sock) {
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 setsockopt($so=
ck, IPPROTO_TCP, TCP_SYNCNT, 2);
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return $sock;
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }
}
I don't know how I could perform some sort of closure so that in my context=
the IO::Socket::INET->new() becomes my function, and therefore, when I ope=
n an HTTP socket it would have the features I have set.
I believe it is pretty common that people want to modify the socket setting=
despite using high layer abstractions... Maybe you can direct me to some d=
ocumentation?
Thanks a lot!
Regards,
Bernard C
------=_Part_2442343_321909817.1590740643484
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<html><head></head><body><div class=3D"yahoo-style-wrap" style=3D"font-fami=
ly:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:16px;"><div dir=
=3D"ltr" data-setdir=3D"false"><div>Hi All,<br> I'm really new =
to perl and as usual in our business world I have to be productive while I =
still learn.<br><br> I'm running checks in IOT over REST API's =
and I saw that my script using the LWP::UserAgent::Determined is generating=
loads of useless syn in case of outages:<br>If I have a small glitch on th=
e connection of a few minutes, I start sending thousands of SYN's as my dev=
ices are unreachable and every attempt generates 6 retries (only 5 are visi=
ble as the $ua->timeout is set to 60)...<br><br> I searched =
a few hours and I figured out it was a unix socket feature.<br><br> &n=
bsp; A few hours later, I found a topic on this website concerning the sock=
et settings (https://www.nntp.perl.org/group/perl.libwww/2005/12/msg6480.ht=
ml). I tried and, naturally, it is no longer working, as the LWP::UserAgent=
(::Determined) is now relying on IO::Socket, as I finally read elsewhere.<b=
r><br>I understand that I can play with the $ua->timeout attribute to ac=
hieve the same, but that would also affect long running request and potenti=
ally have devastating consequences (I would need to reduce the timeout to 1=
4seconds instead of 60 to achieve the same effect as SYNCNT 2).<br><br>&nbs=
p; Now, I tried to implement the same method as in the post above wit=
h the IO::Socket, but it doesn't work. I can't find anything similar to "Im=
plementor" (I understand what I want to achieve but my perl grammar is way =
too basic to know how to):<br><br>use IO::Socket;<br><br>{<br>package MySoc=
ket;<br>use base 'IO::Socket';<br>#IO::Socket::implementor(AF_INET =3D> =
__PACKAGE__); <<<<<<????<br><br>package MySocket::INET;<b=
r>use base 'IO::Socket::INET';<br>use Socket qw(IPPROTO_TCP TCP_SYNCNT);<br=
><br> sub new {<br> m=
y $class =3D shift;<br> my $sock =3D $c=
lass->SUPER::new(@_);<br> if ($sock)=
{<br> setsocko=
pt($sock, IPPROTO_TCP, TCP_SYNCNT, 2);<br> &nb=
sp; }<br> retur=
n $sock;<br> }<br>}<br><br>I don't know how I=
could perform some sort of closure so that in my context the IO::Socket::I=
NET->new() becomes my function, and therefore, when I open an HTTP socke=
t it would have the features I have set.<br><br>I believe it is pretty comm=
on that people want to modify the socket setting despite using high layer a=
bstractions... Maybe you can direct me to some documentation?<br><br>Thanks=
a lot!<br><br>Regards,<br>Bernard C</div><div><br></div></div></div></body=
></html>
------=_Part_2442343_321909817.1590740643484--