From: Karthick Kanna Date: 2015-09-07T13:07:31+05:30 Subject: [ruby-core:70674] Re: [Ruby trunk - Feature #11507] [Open] Net::HTTP should use TCP_CORK or TCP_NOPUSH to avoid fragmenting packets --001a113f89de7d27e5051f2352e1 Content-Type: text/plain; charset=UTF-8 it will defaultly protect when opening any ip protocol, first we have to assign port no for all possible or require protocol, after that it will open without any issue.. /* * Protocols (RFC 1700) */ #define IPPROTO_IP 0 /* dummy for IP */ #define IPPROTO_UDP 17 /* user datagram protocol */ #define IPPROTO_TCP 6 /* tcp */ On Fri, Sep 4, 2015 at 3:17 PM, wrote: > Issue #11507 has been reported by Damien Merenne. > > ---------------------------------------- > Feature #11507: Net::HTTP should use TCP_CORK or TCP_NOPUSH to avoid > fragmenting packets > https://bugs.ruby-lang.org/issues/11507 > > * Author: Damien Merenne > * Status: Open > * Priority: Normal > * Assignee: > ---------------------------------------- > I discovered while implementing a soap client against a badly implemented > http server that for sending a 723 bytes, Net::HTTP sends two packets: > > ~~~ > Frame 185: 579 bytes on wire (4632 bits), 579 bytes captured (4632 bits) > on interface 0 > Point-to-Point Protocol > Internet Protocol Version 4, Src: 127.0.0.1 (127.0.0.1), Dst: 127.0.0.1 > (127.0.0.1) > Transmission Control Protocol, Src Port: 63525 (63525), Dst Port: 7001 > (7001), Seq: 210, Ack: 1, Len: 523 > [2 Reassembled TCP Segments (732 bytes): #183(209), #185(523)] > [Frame: 183, payload: 0-208 (209 bytes)] > [Frame: 185, payload: 209-731 (523 bytes)] > [Segment count: 2] > [Reassembled TCP length: 732] > [Reassembled TCP Data: > 504f5354202f20485454502f312e310d0a534f4150416374...] > Hypertext Transfer Protocol > POST / HTTP/1.1\r\n > SOAPAction: ""\r\n > Content-Type: text/xml;charset=UTF-8\r\n > Content-Length: 523\r\n > Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\n > Accept: */*\r\n > User-Agent: Ruby\r\n > Host: 172.16.129.10:7001\r\n > \r\n > [Full request URI: http://127.0.0.1:7001/] > [HTTP request 1/1] > [Response in frame: 187] > eXtensible Markup Language > ~~~ > > So Net::HTTP client performance could be improved by using the TCP_CORK > option on Linux and TCP_NOPUSH option on BSD's. > > I implemented at the time an embedded tcp server on a relatively slow MIPS > processor under Linux and using TCP_CORK greatly improved the throughput of > the server, so it might also help here. I suppose it also depends on the > network hardware. > > Implementing this simply means (on linux at least) calling > ~~~ > int state = 1; > setsockopt(fd, IPPROTO_TCP, TCP_CORK, &state, sizeof(state)); > ~~~ > before starting to write the request and > ~~~ > int state = 0; > setsockopt(fd, IPPROTO_TCP, TCP_CORK, &state, sizeof(state)); > ~~~ > after when it's written. It will prevent the kernel to send anything until > the request is completely written. From what I see, the > BasicSocket::setsockopt supports TCP_CORK so that should be quite easy. > Unfortunatly I do not have time to implement that right now but I hope I'll > be able to implement it and do some tests soon. > > > > > -- > https://bugs.ruby-lang.org/ > --001a113f89de7d27e5051f2352e1 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
it will defaultly protect when opening any ip protocol, fi= rst we have to assign port no for all possible or require protocol, after t= hat it will open without any issue..

/*
 * Protocols (RFC 1700)
 */
#define IPPROTO_IP              0               /* dummy for IP */
#define IPPROTO_UDP             17              /* user datagram protocol *=
/
#define IPPROTO_TCP             6               /* tcp */


O= n Fri, Sep 4, 2015 at 3:17 PM, <dam@cosinux.org> wrote:
Issue #11507 has been reported by Damien Meren= ne.

----------------------------------------
Feature #11507: Net::HTTP should use TCP_CORK or TCP_NOPUSH to avoid fragme= nting packets
https://bugs.ruby-lang.org/issues/11507

* Author: Damien Merenne
* Status: Open
* Priority: Normal
* Assignee:
----------------------------------------
I discovered while implementing a soap client against a badly implemented h= ttp server that for sending a 723 bytes, Net::HTTP sends two packets:

~~~
Frame 185: 579 bytes on wire (4632 bits), 579 bytes captured (4632 bits) on= interface 0
Point-to-Point Protocol
Internet Protocol Version 4, Src: 127.0.0.1 (127.0.0.1), Dst: 127.0.0.1 (12= 7.0.0.1)
Transmission Control Protocol, Src Port: 63525 (63525), Dst Port: 7001 (700= 1), Seq: 210, Ack: 1, Len: 523
[2 Reassembled TCP Segments (732 bytes): #183(209), #185(523)]
=C2=A0 =C2=A0 [Frame: 183, payload: 0-208 (209 bytes)]
=C2=A0 =C2=A0 [Frame: 185, payload: 209-731 (523 bytes)]
=C2=A0 =C2=A0 [Segment count: 2]
=C2=A0 =C2=A0 [Reassembled TCP length: 732]
=C2=A0 =C2=A0 [Reassembled TCP Data: 504f5354202f20485454502f312e310d0a534f= 4150416374...]
Hypertext Transfer Protocol
=C2=A0 =C2=A0 POST / HTTP/1.1\r\n
=C2=A0 =C2=A0 SOAPAction: ""\r\n
=C2=A0 =C2=A0 Content-Type: text/xml;charset=3DUTF-8\r\n
=C2=A0 =C2=A0 Content-Length: 523\r\n
=C2=A0 =C2=A0 Accept-Encoding: gzip;q=3D1.0,deflate;q=3D0.6,identity;q=3D0.= 3\r\n
=C2=A0 =C2=A0 Accept: */*\r\n
=C2=A0 =C2=A0 User-Agent: Ruby\r\n
=C2=A0 =C2=A0 Host: 172.16.129.10:7001\r\n
=C2=A0 =C2=A0 \r\n
=C2=A0 =C2=A0 [Full request URI: http://127.0.0.1:7001/]
=C2=A0 =C2=A0 [HTTP request 1/1]
=C2=A0 =C2=A0 [Response in frame: 187]
eXtensible Markup Language
~~~

So Net::HTTP client performance could be improved by using the TCP_CORK opt= ion on Linux and TCP_NOPUSH option on BSD's.

I implemented at the time an embedded tcp server on a relatively slow MIPS = processor under Linux and using TCP_CORK greatly improved the throughput of= the server, so it might also help here. I suppose it also depends on the n= etwork hardware.

Implementing this simply means (on linux at least) calling
~~~
int state =3D 1;
setsockopt(fd, IPPROTO_TCP, TCP_CORK, &state, sizeof(state));
~~~
before starting to write the request and
~~~
int state =3D 0;
setsockopt(fd, IPPROTO_TCP, TCP_CORK, &state, sizeof(state));
~~~
after when it's written. It will prevent the kernel to send anything un= til the request is completely written. From what I see, the BasicSocket::se= tsockopt supports TCP_CORK so that should be quite easy. Unfortunatly I do = not have time to implement that right now but I=C2=A0hope I'll be able = to implement it and do some tests soon.




--
https://bugs.ruby-lang.org/

--001a113f89de7d27e5051f2352e1--