Live data from Hacker News

Building a Website with C++

blog.sourcerer.io

71–80 of 122 posts

Re: Building a Website with C++

#71
I run https://byuu.org using C++. Not just for page generation, but also for the server itself. It's all a single package, so no CGI is involved. Although I do use nginx as an HTTP->HTTPS proxy because TLS is scary. It's handled being linked on the front page of a few major sites with no issues.

In my case, I just prefer coding in that language over PHP et al. It's on a $2.50/mo VPS and I can spawn a new instance in five minutes if need be. Every memory access (for strings, vectors, etc) go through containers with bounds checking. The server/webapp itself runs as its own unprivileged user. If the server crashes, it'll stay offline and give me a core dump, which should let me find and fix the bug in my library.

The code's open, too: https://gitlab.com/higan/higan/blob/master/nall/http/server....

It's certainly not 100% perfect security, but what really is? Between Heartbleed, Meltdown, Spectre, weekly Wordpress exploits, etc ... I don't think the risk is particularly higher.

(aside: the forum runs on PHP on another VPS instance; separation of security concerns.)

Re: Building a Website with C++

#72
post #37

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

C++ advocates often talk about the performance gains. The problem with that is that what C++ buys you is not better performance or even predictable performance, but repeatable performance, which is not that useful for anything not hard-realtime.

For typical large OO codebase some kind of tracing GC is almost always better than various reference counting and tracking schemes. For the unpredictability the problem has to do with the fact that even simplest C++ statement might cause the compiler to generate several kilobytes of inlined code.

Re: Building a Website with C++

#73
post #72

Earlier quoted context omitted.

I 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…

C++ advocates often talk about the performance gains. The problem with that is that what C++ buys you is not better performance or even predictable performance, but repeatable performance, which is not that useful for anything not hard-realtime. For typical large OO codebase some kind of tracing GC is almost always better than various reference counting and tracking schemes. For the unpredictability the problem has t…

C++ only has repeatable performance if used in certain ways.

> various reference counting and tracking schemes.

Reference counting doesn't always have repeatable performance.

Maybe for a program image started from scratch on exactly the same non-real-time input. But then almost anything has repeatable performance for that, including ordinary mark-and-sweep garbage collection.

Re: Building a Website with C++

#74
post #37

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

> c++ web site would be

No "would" about it C++ web sites are real and have been around for a long time. I'm thinking of sites running on Windows using "ISAPI".

Re: Building a Website with C++

#76
post #71

I run https://byuu.org using C++. Not just for page generation, but also for the server itself. It's all a single package, so no CGI is involved. Although I do use nginx as an HTTP->HTTPS proxy because TLS is scary. It's handled being linked on the front page of a few major sites with no issues. In my case, I just prefer coding in that language over PHP et al. It's on a $2.50/mo VPS and I can spawn a new instance in…

I too like to dabble in masochism

Re: Building a Website with C++

#77
post #52

Earlier quoted context omitted.

Yeah... this example code is bad. Not to mention that CGI is slow, problematic, and chock full of potential security issues. At the very least, spawning a process per request is a DOS attack waiting to happen, even if the code were immaculate.

Classic CGI is not the best performing interface, yes. But there's a big difference in launching a complete interpreter for every request, and running a small purpose-built native program. And remember that people did manage the former 20 years ago, sites like Slashdot were running CGI Perl scripts back then. I'm not sure about the "chock full of potential security issues". You have to be careful with trusting enviro…

Forking a process per request is expensive, interpreter or not.

Slashdot used apache mod_perl back then. It never forked a process per request.

Re: Building a Website with C++

#78
post #71

I run https://byuu.org using C++. Not just for page generation, but also for the server itself. It's all a single package, so no CGI is involved. Although I do use nginx as an HTTP->HTTPS proxy because TLS is scary. It's handled being linked on the front page of a few major sites with no issues. In my case, I just prefer coding in that language over PHP et al. It's on a $2.50/mo VPS and I can spawn a new instance in…

I too like to dabble in masochism

I also write my own cryptography implementations: https://gitlab.com/higan/higan/blob/master/nall/elliptic-cur...

It's fun. We learn and better ourselves by making mistakes. My idols are the folks breaking through the security of the Switch et al. They had to learn somewhere: by doing things everyone else told them not to.

Don't worry, I would never use this stuff in production at a company.

Re: Building a Website with C++

#79

Interested parties desiring production quality security and significanlty better performance than CGI, check out the C++11 library Restbed https://github.com/corvusoft/restbed Restbed replaces Apache, or put another way puts the web server inside your application, so your C++ app is its own server. It is easy to create REST APIs with executable as small as 100K, and that is all you need - no Apache or Nginx other web…

Looks great but it's AGPL unless you buy a license.

Re: Building a Website with C++

#80

Earlier quoted context omitted.

I 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…

> c++ web site would be No "would" about it C++ web sites are real and have been around for a long time. I'm thinking of sites running on Windows using "ISAPI".

Is their performance demonstrably better than other sites? Parent wasn't saying that c++ sites don't exist, just speculating that it doesn't necessarily make the site clearly faster to browse. I'd speculate the same, but would appreciate if there's hard data around to educate me, I'm genuinely curious what the benefits of going c++ are.
Post reply on HN