News for hackers. Stuff that matters.
Re:Why not C++? by jcoffland on Saturday March 05, 2016 @03:11PM (#11230850)
This is exactly what I'm talking about. If you want to reach really high transactions rates then you cannot use one thread per transaction.
Re:Why not C++? by thrownaway2424 on Saturday March 05, 2016 @03:20PM (#11230891)
I won't argue that async software thread per hardware thread style will have better maximum performance than a thread-per-request style, but I think that difference will not be material in most applications (the difference between the two styles of C++ server programming being far smaller than the difference between, say, a Go program and a C++ program), and the cost paid in code readability is pretty high. All that async continuation passing makes your code a twisty maze, and that style is fraught with lifetime problems that are the very thing most C++ haters are complaining about. In synchronous style all the allocations are scoped by nature. In async style the programmer has to assign ownership of everything to some master continuation that will delete them all in the final callback. That adds a lot of code.
Re:Why not C++? by jcoffland on Saturday March 05, 2016 @03:32PM (#11230953)
You are right about the added difficulty of resource ownership in the face of asynchronous code. This is a trade off. lambda functions in C++11 can help with this. They make it possible to pass resource allocations (smart pointers) through to callbacks.
Re:Why not C++? by zzzcpan on Saturday March 05, 2016 @03:32PM (#11230954)
> All that async continuation passing makes your code a twisty maze

On the contrary, it gives your code clarity, consistency and predictability.

> some master continuation that will delete them all in the final callback

Even nginx in plain C is not doing that, but simply creates destructors on allocation to avoid tracking stuff manually.

Just don't jump into the first thing you read somewhere, remember one simple rule: if it feels harder than threads - you are doing it wrong.

Re:Why not C++? by SamReidHughes on Saturday March 05, 2016 @08:39PM (#11232074)
> On the contrary, it gives your code clarity, consistency and predictability.

Well, when a product I worked on gradually migrated from event loops with callbacks to threads, clarity, consistency, and predictability made big improvements. Some callback usage would have been better with C++11 or C++14, but it's still way worse than what you can do simply by having variables go in and out of scope on a stack.