Live data from Hacker News

Writing high-performance servers in modern C++

medium.com

61–70 of 77 posts

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

#61

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…

I would love you to show us the C++ equivalent of this trivial PHP code:

    x . ',' . $obj->y . "\n";
    }
That's the entire script.

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

#62
post #9

Earlier quoted context omitted.

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

Some resources: The Definitive C++ Book Guide and List : http://stackoverflow.com/questions/388242/the-definitive-c-b... I like the breakdown of books by their goals in this FAQ : https://isocpp.org/wiki/faq/how-to-learn-cpp I would say 'C++ Primer 5th Edition' and 'The C++ Programming Language 4th Edition' are good. And of course, Effective Modern C++, although the other Effective series books from Meyers are a must…

Hi there, I'm interested in learning C++ but is it worth waiting for the C++17 spec to be finalised first? Will there be any significant changes in C++17?

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

#63
post #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.

Title needs to be edited to: How to quickly write a basic, modern C++ using Wangle.

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

#64

Earlier quoted context omitted.

Folly, the library underneath wangle, is running on top of boost::asio, so this is basically an abstraction on asio two layers up.

Folly does not use boost::asio, but rather libevent: libevent is an excellent cross-platform eventing library. Folly's async provides C++ object wrappers for fd callbacks and event_base, as well as providing implementations for many common types of fd uses. https://github.com/facebook/folly/blob/master/folly/io/async... grepping the codebase for `asio` brings up nothing.

Interesting. Thanks for the correction. I had seen the boost dependency and assumed it was using asio under the hood I guess.

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

#65
post #62

Earlier quoted context omitted.

Some resources: The Definitive C++ Book Guide and List : http://stackoverflow.com/questions/388242/the-definitive-c-b... I like the breakdown of books by their goals in this FAQ : https://isocpp.org/wiki/faq/how-to-learn-cpp I would say 'C++ Primer 5th Edition' and 'The C++ Programming Language 4th Edition' are good. And of course, Effective Modern C++, although the other Effective series books from Meyers are a must…

Hi there, I'm interested in learning C++ but is it worth waiting for the C++17 spec to be finalised first? Will there be any significant changes in C++17?

Don't wait. Learning C++11 will put you ahead of the majority of C++ programmers. Learning C++14 put you on the bleeding edge.

After sitting down and getting everything actually working between 2000-2010, C++ now seems to be on a steady path of improvement with major releases every three years with no plans to stop.

So, it's not a matter of waiting for things to finalize. It just deciding to go ahead and climb on board the moving train.

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

#66
post #42

Earlier quoted context omitted.

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?

A networking library based on Asio has been proposed for C++17. In the meantime, use Asio. http://think-async.com/

http://think-async.com/Asio/AsioStandalone

!! I've always heard that Asio is great, but never bothered to look because I don't like introducing Boost's 450 megs of compiler-test-suite-worthy C++ to my >45kb programs. But, as a stand-alone library. That's interesting!

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

#67
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?

I'd recommend to take a look at Seastar: http://www.seastar-project.org/

Briefly: "Seastar is event-driven and supports writing non-blocking, asynchronous server code in a straightforward manner that facilitates debugging and reasoning about performance." -- http://www.scylladb.com/2015/02/20/seastar/

Concurrency model: "Seastar futures/promises/continuations (f-p-c) are a subset of reactive programming.

Seastar performance derives from the sharded, cooperative, non-blocking, micro-task scheduled design, and f-p-c are a friendlier way of feeding tasks to the scheduler.

Seastar’s f-p-c do have some optimizations relative to other f-p-c designs. They trade off thread safety, which is unneeded due to the sharded design, for scheduling efficiency, and have a very low memory footprint." -- http://www.seastar-project.org/faq/

If you'd like to find out more, here are a few links with more information (including examples and tutorials):

- https://github.com/scylladb/seastar/wiki

- https://github.com/scylladb/seastar/blob/master/doc/tutorial...

- http://www.seastar-project.org/futures-promises/

- http://blog.cloudius-systems.com/2015/04/29/seastar-tutorial...

- http://www.slideshare.net/TzachLivyatan/seastar-sayeret-lamb...

In terms of practical applications, ScyllaDB (fully compatible--and significantly faster--drop-in replacement of Apache Cassandra) relies on Seastar: http://www.scylladb.com/

ScyllaDB has been discussed here before: https://news.ycombinator.com/item?id=10262719

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

#68

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…

I would love you to show us the C++ equivalent of this trivial PHP code: x . ',' . $obj->y . "\n"; } That's the entire script.

Take a look at JSON for Modern C++: https://github.com/nlohmann/json

Perhaps this example (benchmark, actually) is close enough: https://github.com/nlohmann/json/blob/master/benchmarks/benc...

Note that the above also performs mini-benchmark with multiple iterations, dumping parsed data to another file, and finishes with a clean-up of the aforementioned dump target file.

The core (read, parse, write) can be simplified to:

  std::ifstream input_file("data.json");
  nlohmann::json data;
  data 

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

#69
post #51
post #23

Earlier quoted context omitted.

It's refreshing to hear other people think the same thing. Most of development time isn't spent physically going code. By picking C you get a high performance layer which can save a lot in infrastructure headaches and has the best performance analysis tools like vtune. That said I've found nodejs slightly nicer for distr

Just curious, how is nodejs nicer for distribution than a binary file?

Ah bummer, looks like my response was cut off :(

If you can bundle all your dependencies into a static file you're right, C/C++ is actually better as you have no install requirements.

However in terms of maintaining your dependencies, nodejs can be pretty great with package management coming with the npm tool. When you want to share your code with the world, and for someone else to actually use it, nodejs is easier.

In C/C++ you can use CMake to have external dependencies on git projects which is the best I've seen that you can do. If you know of any other tools that help with these problems please tell!

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

#70
post #68

Earlier quoted context omitted.

I would love you to show us the C++ equivalent of this trivial PHP code: x . ',' . $obj->y . "\n"; } That's the entire script.

Take a look at JSON for Modern C++: https://github.com/nlohmann/json Perhaps this example (benchmark, actually) is close enough: https://github.com/nlohmann/json/blob/master/benchmarks/benc... Note that the above also performs mini-benchmark with multiple iterations, dumping parsed data to another file, and finishes with a clean-up of the aforementioned dump target file. The core (read, parse, write) can be simplifie…

No no no, this won't compile. Write the complete code, with all the includes, main function, etc. And write it correctly, iterating over the data, accessing the object fields.
Post reply on HN