4 ms·
> In this article, I’ll explain how you can use C++ to develop a website and some concrete reasons why you might consider doing so. I only saw one reason: perf
by dahart 9y ago
> In this article, I’ll explain how you can use C++ to develop a website and some concrete reasons why you might consider doing so.
I only saw one reason: performance. Did I miss some? Do people have other good use cases that justify paying the dev cost of using C++ for a web server? I'd guess with caching and a decent backend, it would be fairly hard to demonstrate a true need for performance that requires C++, but I'm sure there are a few demanding applications out there that need it.
Since a web page's throughput is usually network bottlenecked and not CPU bound, I'm curious (just for fun) what the max possible performance benefit of going C++ is, especially behind a CGI interface?
There's probably a small latency benefit at all times, and I'd guess there's a throughput benefit that is only visible if you're doing more than a few thousand requests per second..?
- pjmlp 9y agoYou missed IoT. Preferably one would use some kind of network protocol with a native management console, but nowadays it is fashionable to have a mini webserver exposing a Web UI instead.
- dahart 9y ago> You missed IoT. I did? I just read the article again, and I don't see any mention of IOT or small or embedded devices aside from Docker, can you point me to what you saw? The article is assuming Apache is running...
- pjmlp 9y agoI was replying to your question, which I should have quoted. > Do people have other good use cases that justify paying the dev cost of using C++ for a web server?
- goldenkey 9y agoMost router admin panels are probably written in C++
- dahart 9y ago> Most router admin panels are probably written in C++ What makes you say that? The modern routers I've used all run a full embedded Linux like BusyBox, and they have no need for compiled high performance panels. It'd be more expensive and less portable to write the admin panel in C++, and I can't really think of any strong benefits that would make it worth using C++. I would have assumed they run a scripting language. But I'm checking some of the OS projects now instead of assuming. Poking around, I see that Tomato is a busybox distribution, all the Linux tools including httpd are C (not C++), and the admin panal pages are .asp (written in VBScript). DD-wrt appears to have PHP admin panels. Looks like Asuswrt-Merlin uses .asp. M0n0wall is all php. Let me know if you find one with admin panels in C++, I'm interested.
- kijiki 9y agoMany are written in shell, terrifyingly, usually running as root.
- flatline 9y agoA large existing C++ code base is one good reason. It’s possible to write wrappers for most of the more web-friendly languages but they are a pain to debug and maintain for any complex API. So if you need a relatively lightweight web front-end for a complex C++ backend something like this may be a good choice. I still wouldn’t go the cgi route, or use makefiles for that matter.
- ecshafer 9y agoI doubt the performance of a c++ web site would be better than c#/java or some other compiled languages for most non-trivial web sites. Once things like jits come into play, and you see large projects (1million+ loc) the performance advantage of c++ often disappears or it becomes less performant for things like web sites. Most companies do not have the time nor ability to do all those optimizations that theoretically exist that would make c++ more performant. This isn't even counting the dev time difference
- quickben 9y agoThe performance would be notable. However, hardware is cheap these days.
- dahart 9y ago> The performance would be notable. Can you quantify & explain what you mean by notable? I've written a lot of C++ and also a lot of scripted web services like node.js and flask (python). For most normal websites, I doubt that you could make significant and noticeable performance improvements to a decent scripted backend by switching to c++, from the user's point of view. A latency savings of a millisecond or two across the board I could buy, but making it obviously faster to a user, I'm skeptical, unless the site has non-traditional high performance requirements.
- Iwan-Zotow 9y agoWhat exactly is the "performance" you're talking about? How you define it?
- dahart 9y ago> What exactly is the "performance" you're talking about? How do you define it? You can see that that was precisely my question, right? Did you mean to reply to the parent comment? The article says the reason to use C++ over rails or node or another scripting language is "performance", the parent comment to mine said that the performance difference would be "notable". I'm asking exactly what you're asking -- what is performance, what is notable? On top of that, I did define performance loosely in my comment -- as something that is noticeably faster to the user. If a user running Chrome can feel the difference on a site, and the only difference is the language it was written in, then I could buy that C++ gives better "performance". I suspect it's rather difficult to write a custom C++ web server and make it load or run any faster, from the point of view of the person on the other end, than a generic rails/flask/nodejs web site, for most sites.
- candiodari 9y agoWouldn't this have very similar performance characteristics to something like serverless functions on Amazon/Google cloud ? (assuming using same language)