Live data from Hacker News

Writing high-performance servers in modern C++

medium.com

21–30 of 77 posts

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

#21
post #3

Earlier quoted context omitted.

Yeah, and no mention about boost::async, which is in Boost, ie almost standard.

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.

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

#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 code (taking a bit of poetic licence here, but hopefully you see my point).

As a discussion about using Wangle in C++, the article has far more merit.

Perhaps I am just being overly pedantic.

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

#23

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…

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

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

#24
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…

I agree. Especially because this sort of code seems to be the whole purpose of this framework. I would expect it to take fewer LOC.

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

#25
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…

> 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 code (taking a bit of poetic licence here, but hopefully you see my point).

I think it's fine to state that; are you ever going to write C++ code with zero included libraries? Probably not. If you write some string manipulation code and you boast that you did it in 10 lines are you going to count it against them that they included std::string?

I think saying how many lines of code it took, using the Wrangle framework, shows that it can be powerful and easy to use versus many of the libraries you end up seeing in C++.

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

#26
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…

If those frameworks/libraries are battle tested and not one off solutions for the project then I do think it has merit.

Imagine building an overpass out of 3 prefabricated concrete pieces; two columns that serve as the base pedestals and 1 beam that spans them. The 48 lines of glue code to me are the nuts and bolts used to tie the pieces together. If the nuts and bolts are structurally sound then I would say our overpass has merit..?

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

#27
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…

[deleted]

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

#28
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…

I'm far more interested in what those 48 lines of source actually compiles to, or how much framework code is involved. I've found that the more of the latter there is, the more difficult debugging tends to be.

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

#29

Earlier quoted context omitted.

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

Tooling is getting better, CMake is awesome. Modules would reduce compile times significantly but it seems C++17 won't include them, so we'd have to wait a bit longer.

[deleted]

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

#30
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 Framework-ish library

* JSON library for REST interface

* Database client library for my database

* Integration testing

After reading these useful blog posts I guess I'll pick:

* Web Server => Facebook's Proxygen

* Web Framework-ish library => Facebook's Wangle, but it doesn't seem to work in Mac, that's already a problem, I don't like having to have two dev environments.

* JSON library => looks like Facebook's Folly seems to have something for it, let's hope it uses modern c++ constructs and not some obscure templating magic to make it faster than other implementations.

* Database client library for RethinkDB: RethinkDB has no official driver and the only community driver public repository has only 22 starts and no CI setup on Github, I'm reluctant to trust this code, this is already a deal breaker to me.

* Integration testing => Wangle's documentation is scarce, there wiki is empty and the repo doesn't have a single code sample to take a look at. I can't go to production without testing, another deal breaker.

Yes, I agree, I don't have to pick RethinkDB. MySQL and PostgreSQL c++ drivers are very mature to use in production apps.

Of course they are, but:

* Do these drivers use modern C++ constructs?

* Would these drivers block proxygen/wangle IO loop(in case they have one?)

* Would I have to use callbacks to make achieve full IO speed? I hate callbacks, there is a reason I abandoned Node.js a long ago.

* How do I put all these dependencies together?

As with Golang, as much as I hate it's lack of generics and proper inheritance:

* Web server: Standard library `net/http`

* Web framework-ish: I don't really need a framework/pipeline for it, there are some neat web routers out there that just help me do the job.

* JSON library: Standard library `encoding/json`

* Database client library: gorethink and almost all the Golang database clients out there have significant adoption with over 700 stars on Github.

* Integration testing: Standard library `net/http/httptest`

Unlike D, C++ and Rust; the Golang ecosystem is unified, I know I'm able to pick a client library and it'd work with whatever stack I have in place because there's only one scheduler and therefore only one way to do IO, plus it's non-blocking without callbacks. I'm not a fan of vendoring dependencies, but it simply works.

In conclusion, I love C++ and even with all the significant progress made in C++11 and C++14, I'm still stucked with Go because it just works.

Post reply on HN