Live data from Hacker News

What happens if you write a TCP stack in Python?

jvns.ca

1–10 of 125 posts

Re: What happens if you write a TCP stack in Python?

#3

Fun read. Does anyone here know how to deal with the Python being slow at sending ACK packets problem? Or is it a built-in limitation that comes with dealing with high level languages?

Implement it in C.

Also its likely more a python problem than a "high level" language problem.

Re: What happens if you write a TCP stack in Python?

#4
ARP spoofing... clever. This was an amusing read and really informative, too. There is definitely something to be said for explaining lower-level concepts (e.g. TCP handshakes) using the common tongue. IMO, not a bad way to begin learning. Someone could perform the same experiment now and use Wireshark to see the raw packets, then draw conclusions to what is happening.

Anyone know why the Python program is so slow? I'm looking at the code and my first guess would be this part[1] but I can't explain why, overall, it would be so slow that a remote host would close the connection.

[1] https://github.com/jvns/teeceepee/blob/7e93970e16fbb0c3d4bee...

Re: What happens if you write a TCP stack in Python?

#6

Fun read. Does anyone here know how to deal with the Python being slow at sending ACK packets problem? Or is it a built-in limitation that comes with dealing with high level languages?

Implement it in C. Also its likely more a python problem than a "high level" language problem.

I blame all networking issues on the GIL.

Re: What happens if you write a TCP stack in Python?

#7

Fun read. Does anyone here know how to deal with the Python being slow at sending ACK packets problem? Or is it a built-in limitation that comes with dealing with high level languages?

The answer to questions about performance is always "profile it". I mean, sure, you could probably get a crude speedup by just running it under pypy or some such, but the real answer is to profile it, see where the bottleneck is, and fix it.

As the other post suggests, this is not a problem in all high-level languages; it's possible to write very high-performance code in Haskell or Ocaml, for example. But python's semantics are e.g. that every object has its own methods that can be overridden arbitrarily, which means that every single method call pretty much has to involve a hash table lookup. 99% of Python code never uses this extreme dynamism (usually you define methods on classes, and if you want an instance with a different implementation for a particular method then you make a subclass), but it's there, and a Python interpreter that didn't respect that would behave incorrectly.

Re: What happens if you write a TCP stack in Python?

#10
I wonder if it would have a better success rate on a site other than Google's, since I've heard that Google's done extensive tuning of their TCP stack to send page data faster.

Somebody's oversubscribed $3/month shared PHP hosting might not ramp up the speed as quickly.

Post reply on HN