Drogon – C++14/17-based rapid HTTP and web application framework
github.com
github.com
The documentation is very thorough and gives a good overview. Every library should be like this.
That being said, I have written a lot of HTTP servers and clients in C++ so I have some opinions on the design of this library.
Modern C++ really tries to avoid preprocessor macros for the reason that it's really hard to know what is going on. Macros can do anything. So I would suggest you get rid of the code generation including dragon_ctl. Write a library that doesn't need code generation. C++17 has all the tools needed to do this.
Personally, I use cpp-httplib to set up a web service for some old but highly relevant Fortran libraries. I am quite happy with this framework but it is always good to get to know other players in this league.
How do people do it?
Any particular reasons why?
C++ is used because there's a lot of heavy lifting in message handling, transformation, and latency has a big impact on business. Any "glue" layer between a computing backend and a presentation backend adds expensive milliseconds to provide a response. If you just want to handle concurrency without care for much else, your usual dynamically typed language will do, and you solve your problems scaling horizontally.
But latency is something that can't be solved scaling horizontally.
Java or Python are used for less critical stuff (admin/management panels and such), but anything transactional is 99% of the time C++.
That said, the framework had terrible interfaces and it implied linking to a multi-GiB .so library, but in the end relatively few servers could handle 50k (relatively complex) tps with less than 20ms latency. I can barely get 20ms with a hello world django app on my laptop.
No.
https://vo.codes uses a Rust HTTP web framework. It's not C++, but it's the exact same use case. High performance compute.
It's not unheard of for ordinary CRUD websites, either. IIRC, the first version of OkCupid was written in C++.
Didn’t Instagram manage to scale Python?
For small teams, wouldn’t the performance of Rust be offset by the productivity lost by not using Python, for example?
Assuming expert programmers in each language.
But then when you look at memory overhead and scale out, the number of servers/instances needed is both more and for a longer time. This has a cost.
The difference is, getting developers proficient in Python is much easier, and if you cannot get people to make your things, it's kind of a problem. If the majority of the program is inside the library, the performance difference starts to go away in many cases.
I worked at a company once that had a really decent HTTP server library... That they put in every program.
You'd launch an app, and to debug it, you'd access http://localhost:9001. From there, you could go to URLs for different libraries in the app. Like, if you had a compression library, you could go http://localhost:9001/compression. It would show stats about the recent work it had done, how long it took, how much CPU, RAM, disk it used. The state of variables now, etc. You could click a button to get it to dump its cache, etc.
If you were running a service on a remote machine, accessing it over HTTP to control it was just awesome. http://r2d2:9001/restart. http://r2d2:9001/quit. http://r2d2:9001/logfile.
Oh, and the services running on that remote machine would register with a system-level monitor. So, if you went to http://r2d2/services, you could see a list of links to connect to all of the running services.
...and every service registered with a global monitor for that service. So, if you knew a Potato process was running somewhere, but you weren't sure which machine it was on, you could find it by going to http://globalmonitor/Potato, and you'd see a list of machines it was running on.
Just all kinds of awesomeness were possible. Can not recommend enough.
And, I mean like, programs with a GUI. Like, picture a game. Except on my second monitor, I had Chrome open, talking to the game's engine. I could use things like WebSockets to stream data to the browser. Like, every time the game engine rendered a shot, I could update it (VNC-style) in the browser window. Except annotated with stats, etc. It was just the most useful way to organize different debug information.
And what was great was that writing a library, and wanting to output information, you wouldn't write it to std out... You'd make HTML content, and write to it. Want to update it? Clear the buffer and write to it again. As a user, if you ever want to read the buffer, you just browse it. Want to update it? Refresh the window. Or better yet, stream it over a websocket. Like Std Out on steroids. If you need to combine the output from a few libraries in a new window, you just write a bit more HTML in your code, and you're doin' it.
It's just another example, in my mind, of the power of libraries. We all get used to thinking of frameworks (IIS, Apache) as the only way to solve a problem, that we forget to even think about putting things together in new and unexpected ways. HTTP as a library - HELL YES.
Using HTML to debug programs, live, is highly under-utilized.
In your scenario it sounds like an easy way to make a big step forward, though I don't think that takes it far enough.
I proposed an idea, and you proceeded to tell me "There is no inherent reason why [my idea] is the best way to go." I think that's a pretty rough way to respond to someone suggesting an idea that might be useful under some circumstances. It's a possibly new tool in your tool-belt. I didn't mean to suggest that a hammer "is the best way to go" for any job. But sometimes the problem is a nail, and a hammer is the best tool.
You highlighted the value of "debugging a program live," which is true, but I thought you meant using a sophisticated debugger (gdb / Visual Studio, etc). For instance, Microsoft Visual Studio has (or used to have) the ability to have plug-ins to help you visualize complex structures in memory of the running process, for instance showing a Bitmap as an actual image on your screen. I thought that's what you meant, or just using gdb or some other sophisticated debugger. But yes, that was my misunderstanding.
Shared memory is nice, and I've used it before, but it required me to store all of my interesting objects in shared memory structures. Which meant changing how my application was written. Yes, sometimes I could see that being amazing. Or I suppose you make a large copy of them.
I've also done the trick where, if I hit a URL on my app, then it took the point clouds, pixels, etc, and provided a rendered PNG image of them. But it could do it without requiring me to restructure my program's memory layout (other than a few multi-threading locks, when needed.) And I've done that over WebSockets, with interactive rendering rates, basically like a VNC. And what was nice about that, again, was that I could run a process on one machine, and debug it (through HTML) from another. And grant that ability to other users, without having to tell them how to install a debugger app, and giving that app access to connect over the network, and etc.
The ports thing was in reference to the ability of Microsoft Visual Studio (and presumably other debuggers) to do remote debugging, attaching themselves to a process running on another computer. So, you have to be able to connect to that process. Whereas my proposal could work on normal HTTP / HTTPS ports, and with authentication, could enable a user to access debug views.
Anyway, yes, I very much agree with you that debugging a program live is highly underrated, and I think it's good if people share different ways to do that.
In C++ you could link-in a golang webserver, with cgo, or use Spring/Vertx using JNI, but you probably won't.
Given how capable even cheap cloud hardware is now, optimizing for developer productivity is better than choosing the "very fast" C or Rust framework which no one understands how to program for. Also, C/Rust etc, being harder languages to learn and lower level, tend to be both harder to hire for and also end up with more bugs than the higher level languages.
And that is something that I generally am OK with, to a point. If your application isn’t performance sensitive, have at ‘er and use whatever you feel is going to be the most productive, even if it potentially has higher opex.
Bugs is an interesting thing. There’s two flavours of bugs, basically: requirement errors and implementation errors. High vs low level languages don’t do much to alleviate the first category of bugs at all (e.g. not thinking through how “random shuffle” should work in a music player). High level languages can help reduce the number of coding errors compared too lower level languages, but they do have their own quirks (eg using an empty list as a default argument in Python)
Ultimately, though, it’s all about working within the constraints you’re given, whether time-to-market, development costs, opex costs, system performance, etc. I’m intrigued by this framework because I have a high performance image processing system written in C++17 and there’s been some discussion recently about an HTTP API for it. Why is it in C++ to begin with? It’s on a somewhat resource constrained board (Jetson Nano) and has to run at at least 70fps for what it’s doing. 14 milliseconds to grab the image from the camera, run it through TensorRT, and do something useful with the output. I would have considered Rust as well, but a good chunk of this is leveraging existing C++ libraries (OpenCV, FLIR Spinnaker, TensorRT, etc) and fighting with wrappers and weird impedance mismatches is not my idea of a good time.
While I absolutely agree, it all depends on a scale. If you're using for example 10 cloud instances, x2 performance improvement will not justify extra person-months spent on developing more performant solution. On the other hand if you run 1000000 servers even 1% performance boost might be worth that effort.
There's a big number of companies who have between 4 and 20 machines for serving Python, Node or PHP apps and spend a lot of efforts managing them with overkill solutions like kubernetes or whatever when it could be a single machine or two using more frugal languages.
And "junkie" is a very harmful term to use and implies a moral failing of the drug user.
https://www.techempower.com/benchmarks/#section=data-r19&hw=...
Hope it generates some interest among programming community to also look at modern C++ as viable web development platform.
What language is?
If only sticking to deadlines was as easy as changing your programming language!
Alas.
1. Support non-blocking I/O based asynchronously reading and writing database (PostgreSQL and MySQL(MariaDB) database);
2. Support asynchronously reading and writing sqlite3 database based on thread pool;https://github.com/an-tao/drogon/blob/master/orm_lib/src/DbC...
Since this project was submitted by project creator, it deserves "Show HN" status (https://news.ycombinator.com/showhn.html).