# Speeding up TCP

**URL:** <https://www.ruby-forum.com/t/speeding-up-tcp/185499>\
**Category:** Ruby\
**Created:** [March 21, 2010, 7:19pm UTC](https://www.ruby-forum.com/t/speeding-up-tcp/185499 "2010-03-21T19:19:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![seanwarburton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@seanwarburton](https://www.ruby-forum.com/u/seanwarburton)\
**Post date:** [March 21, 2010, 7:19pm UTC](https://www.ruby-forum.com/t/speeding-up-tcp/185499/1 "2010-03-21T19:19:25Z")

</div>

I have a script that opens a TCP socket and then sends an XML request  
using SSL over the socket, it then receives an answer back from the  
server. The whole send and receive is taking between 160 and 175  
milliseconds total (not including opening the socket) but I know others  
using PHP and Perl have this down to around 130 milliseconds and I  
wonder if Ruby has any tricks up its sleeve that would speed thing up a  
little.

---

<div class="post-metadata">

**Author:** ![seanwarburton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@seanwarburton](https://www.ruby-forum.com/u/seanwarburton)\
**Post date:** [March 21, 2010, 7:44pm UTC](https://www.ruby-forum.com/t/speeding-up-tcp/185499/2 "2010-03-21T19:44:14Z")

</div>

On Mar 21, 2010, at 1:19 PM, Sean W. wrote:

> I have a script that opens a TCP socket and then sends an XML request  
> using SSL over the socket, it then receives an answer back from the  
> server. The whole send and receive is taking between 160 and 175  
> milliseconds total (not including opening the socket) but I know others  
> using PHP and Perl have this down to around 130 milliseconds and I  
> wonder if Ruby has any tricks up its sleeve that would speed thing up a  
> little.

Show us your code. It’s impossible to say that the performance issue is  
with network and not with other processing you are performing on the  
data from what little you’ve said.

Barring that, take a look at the Eventmachine library (available as a  
gem). It allows you to build clients and servers using non-blocking I/O.

cr

---

<div class="post-metadata">

**Author:** ![seanwarburton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@seanwarburton](https://www.ruby-forum.com/u/seanwarburton)\
**Post date:** [March 22, 2010, 12:26am UTC](https://www.ruby-forum.com/t/speeding-up-tcp/185499/3 "2010-03-22T00:26:56Z")

</div>

On Sun, Mar 21, 2010 at 2:43 PM, Chuck R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> On Mar 21, 2010, at 1:19 PM, Sean W. wrote:
> 
> > I have a script that opens a TCP socket and then sends an XML request  
> > using SSL over the socket, it then receives an answer back from the  
> > server. The whole send and receive is taking between 160 and 175  
> > milliseconds total (not including opening the socket) but I know others  
> > using PHP and Perl have this down to around 130 milliseconds and I  
> > wonder if Ruby has any tricks up its sleeve that would speed thing up a  
> > little.

130ms from the same client to the same server over the same network?

> Show us your code. It’s impossible to say that the performance issue is with network and not with other processing you are performing on the data from what little you’ve said.

+1 🙂

---

<div class="post-metadata">

**Author:** ![seanwarburton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@seanwarburton](https://www.ruby-forum.com/u/seanwarburton)\
**Post date:** [March 24, 2010, 5:22pm UTC](https://www.ruby-forum.com/t/speeding-up-tcp/185499/4 "2010-03-24T17:22:17Z")

</div>

Sean W. wrote:

> I have a script that opens a TCP socket and then sends an XML request  
> using SSL over the socket, it then receives an answer back from the  
> server. The whole send and receive is taking between 160 and 175  
> milliseconds total (not including opening the socket) but I know others  
> using PHP and Perl have this down to around 130 milliseconds and I  
> wonder if Ruby has any tricks up its sleeve that would speed thing up a  
> little.

using eventmachine might help.  
-rp

---

<div class="post-metadata">

**Author:** ![seanwarburton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@seanwarburton](https://www.ruby-forum.com/u/seanwarburton)\
**Post date:** [March 22, 2010, 9:58am UTC](https://www.ruby-forum.com/t/speeding-up-tcp/185499/5 "2010-03-22T09:58:38Z")

</div>

Sean W. wrote:

> I have a script that opens a TCP socket and then sends an XML request  
> using SSL over the socket, it then receives an answer back from the  
> server. The whole send and receive is taking between 160 and 175  
> milliseconds total (not including opening the socket) but I know others  
> using PHP and Perl have this down to around 130 milliseconds and I  
> wonder if Ruby has any tricks up its sleeve that would speed thing up a  
> little.

Show your code as others have said. Using tcpdump or wireshark, measure  
exactly how much of this delay is for the far-end server processing and  
responding.

If the far-end server is taking less than 100ms to respond, you could  
try the TCP\_NODELAY or TCP\_CORK socket options on the ruby client side.

---

<div class="post-metadata">

**Author:** ![seanwarburton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@seanwarburton](https://www.ruby-forum.com/u/seanwarburton)\
**Post date:** [March 25, 2010, 9:44am UTC](https://www.ruby-forum.com/t/speeding-up-tcp/185499/6 "2010-03-25T09:44:06Z")

</div>

Try disabling naggle algorithm.

On Wed, Mar 24, 2010 at 9:52 PM, Roger P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Sean W. wrote:
> 
> > I have a script that opens a TCP socket and then sends an XML request  
> > using SSL over the socket, it then receives an answer back from the  
> > server. The whole send and receive is taking between 160 and 175  
> > milliseconds total (not including opening the socket) but I know others  
> > using PHP and Perl have this down to around 130 milliseconds and I  
> > wonder if Ruby has any tricks up its sleeve that would speed thing up a  
> > little.

using eventmachine might help.

> ## -rp
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

–  
Let them talk of their oriental summer climes of everlasting  
conservatories; give me the privilege of making my own summer with my  
own coals.

[http://gnufied.org](http://gnufied.org)
