Live data from Hacker News

High Performance TCP Proxy Server

partow.net

11–20 of 62 posts

Re: High Performance TCP Proxy Server

#11
Very nice, but this is more of a demo code for boost::asio than something that is production-worthy.

For example, it doesn't relay FINs between connections, doesn't disable Nagle algorithm on the upstream socket, doesn't wait for pending writes to complete before tearing down the connection, doesn't handle congestion at all (potentially leading to unbound memory use), etc.

Re: High Performance TCP Proxy Server

#12

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.

Not sure if the 300 loc is really a fair comparison, as it is using ASIO (https://think-async.com/) under the covers, which is far more than 300 loc.

Re: High Performance TCP Proxy Server

#13
post #7

Earlier quoted context omitted.

Can you expand on your reasons for making that claim - perhaps with some benchmarks?

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

C++ 17 Networking TS is based on ASIO. It will be very interesting if netty performs better than ASIO based code for the same task.

Re: High Performance TCP Proxy Server

#14

As a sidenote if you don't have a requirement to compile with C++03 I would recommend using the standalone asio library free from boost[1]. The only things you need to modify are the includes and namespaces. [1] http://think-async.com/Asio/Download

Why would you recommend the upstream Asio library instead of the one in Boost?

Re: High Performance TCP Proxy Server

#15
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 could probably be removed by the realisation that, after a connection is established, both ends are completely symmetric: all it needs to do is try to read from A and write to B, then try to read from B and write to A. If A closes, close B. If B closes, close A.

Re: High Performance TCP Proxy Server

#16
post #7

Earlier quoted context omitted.

Can you expand on your reasons for making that claim - perhaps with some benchmarks?

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.

Re: High Performance TCP Proxy Server

#17

As a sidenote if you don't have a requirement to compile with C++03 I would recommend using the standalone asio library free from boost[1]. The only things you need to modify are the includes and namespaces. [1] http://think-async.com/Asio/Download

Why would you recommend the upstream Asio library instead of the one in Boost?

Because it has zero dependencies -- There's no reason to pull in boost::shared_ptr when you can use std::shared_ptr

Re: High Performance TCP Proxy Server

#18

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.

I was trying to say in a nice way that it's unlikely you've created something as fast as netty because a lot of people spent a lot of time optimizing it.

Netty is also a lot easier to extend and more portable

Re: High Performance TCP Proxy Server

#19
post #13

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

C++ 17 Networking TS is based on ASIO. It will be very interesting if netty performs better than ASIO based code for the same task.

They both use epoll underneath. Netty will likely perform better because it has a robust thread pool implementation.
Post reply on HN