Live data from Hacker News

Writing high-performance servers in modern C++

medium.com

71–77 of 77 posts

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

#71
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.

Yes, you can optimize it to whatever, but the point of mentioning that it is only a small number lines, it informs the reader they aren't going to get lost in a tone of code.

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

#72
post #68

Earlier quoted context omitted.

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.

There is _absolutley_ no value for a language to provide handy built-in functions that are trivially made available by a library.

If we were talking about language constructs/semantics or flow-control abilities, I'd have a very different opinion - but not having a json decoder builtin, is no reason to use or not use a language.

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

#73
post #72

Earlier quoted context omitted.

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.

There is _absolutley_ no value for a language to provide handy built-in functions that are trivially made available by a library. If we were talking about language constructs/semantics or flow-control abilities, I'd have a very different opinion - but not having a json decoder builtin, is no reason to use or not use a language.

Don't dodge the question. Use any available library you want, just type the code that will compile.

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

#74

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 have settled on Lua and C/C++ as my principle language/environment and it is a real joy. I think anyone who is 'into' C++ and hasn't yet grok'ed what Lua can do for them is going to have a good time if they dig deeper. Lua can do anything those other languages can do. And you can write C++ for the hard stuff.

I'm sort of surprised it doesn't come up more in this environment, but modern C++, Lua, and LuaJIT .. these things appear, to me, far more valuable than given by the hoipolloi ..

The point is, an investment in C++ does not mean you can't 'have all the fun toys too', because .. you can. And boy do they kick ass.

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

#75
post #33

Earlier quoted context omitted.

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…

You can usually get a noticeable speedup using unity builds, even when using something like Incredibuild. That suggests that more source files is not the answer. (I am not going to speculate as to why things are this way; it simply appears to be the case.) I'm not sure it makes a great deal of sense to separate compilation time from link time anyway (and you should also consider device reboot or program startup time…

Often with large C++ codebases the link step can be the bottleneck. Not only it can't be easily parallelized for a single target, but even if you have multiple independent binary targets, the high memory usage of the link step makes it hard to run multiple lds at the same time.

I have seen optimized builds run faster than debug builds simply because many symbols where being removed during optimization speeding up the link step.

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

#76
post #19

Earlier quoted context omitted.

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…

But when you do need generics and use templates, you are forced to write lots of code in .h files. There is very little you can do in that case to speed up build times, without resorting to devious things like PIMPL.

Unfortunately, even PIMPL won't help with templated code, unless you resort to manual template instantiation which is tedious.

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

#77
post #68

Earlier quoted context omitted.

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.

All right, then: This one is complete (compiles, runs, iterates through the data, accessing only fields "x" and "y"):

  #include 
  #include 
  
  int main()
  {
  	std::ifstream input_file("data.json");
  	nlohmann::json data;
  	data 
Post reply on HN