189 points · by an-tao · 7y ago · 105 comments
a) Show me the code to start with, don't send me digging for it. A SimpleController example as the very first thing would help give a feel for the project, and makes me more likely to consider the project.
b) If there's an easier way (like the drogon_ctl utility at the start of Quickstart [0]), show that first, and the more detailed way second.
Other than that, it looks great. I've used libmicrohttpd a few times, so a bit less of an overhead always looks great.
But one thing that surprises me is that folks are essentially sleeping on HTTP/2. HTTP/2 is just a hell of a lot better in most every dimension. It's better for handshake latency, it's better for bandwidth in most cases, it's better for eliminating excess SSL overhead and also, it's kinda easier to write client libraries for, because it's so much simpler (although the parallel and concurrent nature of connections will challenge a lot of programmers).
It's not bad to see a new contender in this space, but it's surprising that it isn't http/2 first. Is there a good reason for this? It's busted through 90% support on caniuse, so it's hard to make an argument that adoption holds it back.
The migration to IP6 shows how quick the industry is moving to new protocols.
Now if HAProxy makes multiple connections to the backend each one gets served by its own thread+socket and that's going to load much faster because at the very least it's going to get more attention from the OS. Furthermore, if you use the keepAlive header, and set long timeouts, then you don’t even have to pay the connection penalty. So essentially you’ve shifted thread management to HAProxy by virtue of its parallel connections which keeps the webserver code pretty simple. And in a C++ program simplicity is key to correctness
If that was true, I'd be convinced by it. But is it true? HTTP 1.1 is a pretty big and complicated spec.
What makes it simpler? I thought it was the other way around.
Even though HTTP/2 is usable, adoption is still low (last I checked it was around 25%), and any server that supports 2 needs to support 1 for backwards compatability. It's also more complicated to implement, so I can see why you'd want to start with HTTP/1.
As for client libraries for APIs, it's a non-issue. There's plenty of flexibility on backends.
I'm not saying you'd skip "HTTP/1" but I certainly wouldn't put a lot of effort into it.
Revproxies are essentially awful, ugly lynchpins in your distributed architecture. You want to be as low as you can afford to be on utilization for them, because if they have a bad day you have no product.
https://github.com/TechEmpower/FrameworkBenchmarks/tree/mast...
Absolutely not true for C++. The language was invented to guarantee memory safety, like Rust was. (The fact that people ignore the safety features when coding is irrelevant, people liberally throw 'unsafes' around in Rust and Haskell too.)
The fact that people can ignore the safety features is the point. Unsafe is a contract, and it only opens a small number of extra "features". It forms the axioms of a proof the your code correctly uses memory. C++ is essentially just patched with safer abstractions, some of which are major improvements, but there is no proof, no rigorous check for safety until runtime from asan or a fuzzer, or other tools that aren't a part of core C++.
The biggest issue with the safety of C++, however, is the size of the language. It has become so big and so complicated, and the rules that govern things we take for granted like function name lookups are horrendously unintuitive and lead to unintended consequences.
Plenty of interviews where he states this, including some of his books.
int foo(int x) {
return x+1;
}
leads to undefined behavior (aka the standard says the program can delete your hard drive) if x is too big, that's not a language that guarantees memory safety.The risk of security issues of such framework, since it uses C++, might be quite high. I'm not into security a lot, so don't trust my word, but I'd be very cautious.
Generally, I guess higher performance means lower security.
Both handle HTTP requests, but nginx mostly forwards requests to other stacks.
Using Nginx modules and LuaJIT, you kind of can. OpenResty is a web framework built using this principle.
app.get("/test", [](drogon::Request & req, drogon::Response & res) {
// Business Logic Goes Here?
});
I'm going to be honest, I'm turned off by the macros and general API style of endpoint definition. I know, I know...> Don't be scared by the code.
I can't help it!
drogon::app.registerHttpMethod("/test",
[=](const HttpRequestPtr& req,
const std::function<void (const HttpResponsePtr &)> & callback)
{
Json::Value json;
json["result"]="ok";
auto resp=HttpResponse::newHttpJsonResponse(json);
callback(resp);
},
{Get,"LoginFilter"});
The method in the readme file is for decoupling. Imagine a scene with dozens of path handlers. Isn't it better to disperse them in their respective classes?Of course, for very simple logic, the interface you are talking about is really more intuitive, I will consider adding such an interface. Thank you for your comment.
What is "NIO" here? I am familiar with NIO as New Input-Output from Java, which was the extension of the standard library to cover asynchronous I/O. Is the author using "NIO" to mean asynchronous IO? Their use of '"JSP-like" CSP file' elsewhere hints at a Java background.
However, the callback has an odd interface.
why not pass a universal ref T&& vs a const T&
most of your code is like this.
``` auto resp = HttpResponse::newHttpJsonResponse(json); callback(resp); ```
which means callback can reuse the buffer if it wanted to rather than making a copy because it's const ref.
PS: did you benchmark it against Folly/Proxygen (facebook) and Seastar
Also, this would be super cool if it were in Rust. As it stands writing web services in C++ is basically programming malpractice at this point. Would love to see the author contributing to tokio or hyper and helping us get rid of all this legacy inheritancey impl junk.
This is the kind of extremism that makes people hate Rust. Please don't make people hate Rust.
Literally anything would be better than C++ at this point though. I'd take D or Nim over C++ in a heartbeat, which is drowning in the weight of its own specification, coupled with a desire to keep programmers in the dark ages of memory safety by convention and the C preprocessor. It's also impossible to find a C++ code base that doesn't have some sort of safety issue even with smart pointers and RAII. Fuzzing, testing, and trying to patch things up simply isn't enough.
The software landscape has changed, there are now more reasons than every to chose a language based on safety and efficiency than can run everywhere than ever before.
(Rust is good idea, but about 10 years immature. Come back in 2029.)
Except for, you know, the part where Rust is actually memory-safe and C++ isn't.