Live data from Hacker News

High Performance TCP Proxy Server

partow.net

21–30 of 62 posts

Re: High Performance TCP Proxy Server

#22

As someone who has also written a TCP proxy (along with many others...), after thoroughly reading the page I'm still unsure of how exactly this is "high performance". It is also curious that, despite the fact that it uses a separate library for networking, the source is already quite a bit longer than some other proxies which don't. I found the explanation overly complex. Around half the code in this implementation c…

> If A closes, close B. If B closes, close A.

It's shutdown() writes on EOFs, not close, with refcounting to also do close() when EOFs were detected on both directions (I also have written a TCP proxy). But yeah, TCP proxies are trivial, would be more interesting to see something like a tunneling proxy that sends data over multiple connections to maximize performance.

Re: High Performance TCP Proxy Server

#23

Earlier quoted context omitted.

Check out the techempower framework benchmarks. Netty can do over a million http responses per second on a reasonable machine. On Linux it uses an epoll native driver and is asynchronous. The framework makes it possible to write proxies in a few lines. If you want to beat netty by a significant margin you'll probably need to use kernel bypass

ASIO does all that. And it compiles to machine code. What you're basically trying to argue is a well-written C++ application will be slower than a well-written java application. That's not going to happen -- at best they will be the same performance.

Netty certainly has a more impressive list of projects using it in real-world high-volume scenarios. That's probably what wins in this case...enough high volume end users such that you've gotten enough edge cases to tweak the software and iron out bugs.

If I had to pick something in the C/C++ space to implement a custom proxy, I would probably stick to something where I could find a similar list of established high volume real world users. Facebook's Proxygen, or some customized HAProxy maybe.

Re: High Performance TCP Proxy Server

#24

Earlier quoted context omitted.

HAProxy is 90k loc while this is 300 loc so they really are different beasts. I would say HAPRoxy is a great general purpose proxy that has most of the features you want while this proxy server is a MVP proxy you can grow off of if you want to do something that HAProxy can't provide.

Netty is a more mature foundation for this sort of thing and likely much faster

Netty was first released in 2016?

HAproxy was first released around 2001.

Probably irrelevant to the question of speed, but there is a comment in another thread about hype driven development on HN first page right now where a commenter states they prefer Netty to the alternatives apparently because the alternatives are older or more cumbersome to use, although I may have misread.

Edit: This was a hasty, dumb comment. Please accept my apologies. Netty is not new and I should have known better. For whatever irrational reason, I have a bias against Java and deliberately avoid it. I do know it helps professional programmers get things done easier and faster. I'm an HAproxy user and have probably developed an HAproxy bias.

Re: High Performance TCP Proxy Server

#27

As someone who has also written a TCP proxy (along with many others...), after thoroughly reading the page I'm still unsure of how exactly this is "high performance". It is also curious that, despite the fact that it uses a separate library for networking, the source is already quite a bit longer than some other proxies which don't. I found the explanation overly complex. Around half the code in this implementation c…

It is symmetrical, but there are nuances.

If A closes or errors out, the proxy should first push out any pending data and only then close B.

The same goes for when A sends a FIN - it should flush any data queued at application level before calling shutdown() on B's socket.

If A becomes unwritable, it should stop reading from B.

Re: High Performance TCP Proxy Server

#28
post #24

Earlier quoted context omitted.

Netty is a more mature foundation for this sort of thing and likely much faster

Netty was first released in 2016? HAproxy was first released around 2001. Probably irrelevant to the question of speed, but there is a comment in another thread about hype driven development on HN first page right now where a commenter states they prefer Netty to the alternatives apparently because the alternatives are older or more cumbersome to use, although I may have misread. Edit: This was a hasty, dumb comment.…

> Netty was first released in 2016?

Netty 2 (the current version that underlies WebSphere and Vertx) was first released in 2004. This stuff is pretty well-bulletproofed. And a lot of folks who know how to write high-performance Java are naturally going to prefer Netty to the C++ alternatives (I am ambivalent; I can do either and I'd probably just use HAProxy to begin with because life is short) because you get competitive performance while ruling out entire classes of errors.

Re: High Performance TCP Proxy Server

#29

Earlier quoted context omitted.

Netty is a more mature foundation for this sort of thing and likely much faster

Again, this is a really cool 300 loc snippet. No need to pull in the jvm if you're going to do something simple. As for performance, a reproducible benchmark is the minimum requirement to even start the conversation.

And yet by "pulling in the JVM" (which is a rounding error in 2017), it's remarkably easy to generate a proxy that actually works as people expect a TCP proxy to work. This doesn't even so much as wait for connections to drain before terminating. This "300-line snippet" (which is reliant on Asio, which is not 300 lines by any stretch) is, as near as I can tell, not viable in real-world conditions and the spirited defenses of it that put it as competitive with real-world, battle-tested solutions are profoundly weird.

(Similarly, because I don't really care about JVM versus not, HAProxy--which I'd probably use for something like this because I have better things to do with my programming time--is 90Kloc because it has stuff to do and does it right. Simple is only better if simple can actually get the job done.)

Re: High Performance TCP Proxy Server

#30
post #24

Earlier quoted context omitted.

Netty is a more mature foundation for this sort of thing and likely much faster

Netty was first released in 2016? HAproxy was first released around 2001. Probably irrelevant to the question of speed, but there is a comment in another thread about hype driven development on HN first page right now where a commenter states they prefer Netty to the alternatives apparently because the alternatives are older or more cumbersome to use, although I may have misread. Edit: This was a hasty, dumb comment.…

Netty is hardly the example of a hype driven framework. I'm not sure when it was first released but I've found references from version 2.0 in 2004. It may be older than HAProxy.

Netty is a far more robust, faster, and easier to use framework for TCP proxies than the one the author cooked up and I'm getting downvoted like crazy for saying it.

It's also used internally by Google, Twitter, and netflix. It's embedded in the GRPC library, Cassandra's database driver, Play framework, and Vert.x among many others. Check their related projects page https://netty.io/wiki/related-projects.html

Netty is a phenomenal project, and had the author known about it, I doubt he would have spent the time writing his own TCP proxy.

Post reply on HN