Live data from Hacker News

Writing high-performance servers in modern C++

medium.com

41–50 of 77 posts

Re: Writing high-performance servers in modern C++

#41

Earlier quoted context omitted.

Modern C++ is indeed pretty productive. It's the tooling and compile times that hold it back.

Perhaps you mean link time? If you're spending a lot of time compiling you are probably suffering from other problems. Most of C++'s issues with compilation come from needing to re-compile entire .cpp files because of a change in a depending .h file. If you properly forward your class declarations instead of including a header in a .h file, don't do template meta meta magic, and think about physical design a bit, you…

A lot of C++ compile time is simply generating and optimizing all the code. Modules don't help with this.

Modern C++ style generally requires making a whole bunch of little functions and classes and counting on them to be inlined and SROA'd away. This works remarkably well for runtime, but it exacts a big compilation performance hit simply because you're optimizing so much code.

Re: Writing high-performance servers in modern C++

#42

A lot of people state that Python/PHP/Ruby/Javascript on the dynamic language side and Java and other JVM languages on the statically typed side and much quicker to develop than C++, but being a very experienced Java programmer and a decent Javascript programmer I find that I can program just as fast with C++ as long as you use the right choices of libraries and use C++11 or greater. With libraries like Boost, fbfoll…

Does modern C++ have a decent story for writing nonblocking concurrent code yet? Something that could compete with async-await in C# or monads in functional programming?

Re: Writing high-performance servers in modern C++

#43
post #22

I don't understand the point of saying something like: > "I show how to build a modern C++ high-performance, asynchronous echo server that can be written with just 48 lines of code." The fact that it is 48 lines of code is almost meaningless. If the framework was a different design it could be done in 1 line of C++ code or 1 line of COBOL. Given the right library/framework, any application can be done with 1 line of…

> 1 line of COBOL

Offtopic, but this would be quite a challenge.

Re: Writing high-performance servers in modern C++

#44
post #42

A lot of people state that Python/PHP/Ruby/Javascript on the dynamic language side and Java and other JVM languages on the statically typed side and much quicker to develop than C++, but being a very experienced Java programmer and a decent Javascript programmer I find that I can program just as fast with C++ as long as you use the right choices of libraries and use C++11 or greater. With libraries like Boost, fbfoll…

Does modern C++ have a decent story for writing nonblocking concurrent code yet? Something that could compete with async-await in C# or monads in functional programming?

Well, threads just became a part of the standard with C++11. As to how to use them, there is a decent story, you just have to type it yourself :)

https://www.manning.com/books/c-plus-plus-concurrency-in-act...

Re: Writing high-performance servers in modern C++

#45
post #9

A lot of people state that Python/PHP/Ruby/Javascript on the dynamic language side and Java and other JVM languages on the statically typed side and much quicker to develop than C++, but being a very experienced Java programmer and a decent Javascript programmer I find that I can program just as fast with C++ as long as you use the right choices of libraries and use C++11 or greater. With libraries like Boost, fbfoll…

Do you have any pointers to learn modern C++?

If one is choosing C++ then performance is probably a part of the requirements equation.

These books discuss performant (and sometimes complex) C++ code - in the domain of computer graphics.

http://www.amazon.com/Physically-Based-Rendering-Second-Edit...

http://www.amazon.com/Real-Time-Collision-Detection-Interact...

About how to use the new threading standard: https://www.manning.com/books/c-plus-plus-concurrency-in-act...

Re: Writing high-performance servers in modern C++

#46

I love to read stuff like this, "with a bit of effort I was able to build the whole back-end for my startup using C++", then I start to think: what would it take for me to migrate off Golang to C++? I love to develop in Mac and deploy in Linux/Docker, so whatever stack I pick has to be compatible with both OS's, with this in mind I made a list of libraries I'd need to move my API to C++: * Web Server library * Web Fr…

I also run into this problem all the time. I hope that with the networking TS standardizing on basically boost Asio and the incorporation of coroutines into C++ we should start seeing some unification across all network/do client libraries in terms on non-blocking use.

Re: Writing high-performance servers in modern C++

#47
post #42

A lot of people state that Python/PHP/Ruby/Javascript on the dynamic language side and Java and other JVM languages on the statically typed side and much quicker to develop than C++, but being a very experienced Java programmer and a decent Javascript programmer I find that I can program just as fast with C++ as long as you use the right choices of libraries and use C++11 or greater. With libraries like Boost, fbfoll…

Does modern C++ have a decent story for writing nonblocking concurrent code yet? Something that could compete with async-await in C# or monads in functional programming?

await is coming, maybe even in C++ 17. Visual Studio already implements it. Way more efficient than the C# implementation too (coroutines)

Promises are already there.

Re: Writing high-performance servers in modern C++

#49

Did you test your server with 1.000.000 connections?

How about input fuzzing? Did you try crashing it and see how quickly it can recover? Unit tests? What about zero downtime upgrades? DDoS resiliency? Can it utilize all cores on a machine? Scalable? What are the median and max response times under load?

Oh it's just a quick demo? Nevermind.

Re: Writing high-performance servers in modern C++

#50
post #38

I stopped reading after reading the first line of code containing a virtual function and smart pointers. Nothing is performance oriented in this post. It's just a plain old dummy TCP server like anyone would write.

I half agree; it's easy to be cynical. Virtual functions can be a terrible idea... if they are in a hot path.

Is EchoHandler::read such a path? Maybe, you really can't say without profiling. If anything using std::string is the red flag for me.

Post reply on HN