13 ms·
Show HN: Drogon – A C++14/17 based high performance HTTP application framework
- umvi 8y agoI like it, but the API for defining HTTP endpoints seems messy compared to, say, Flask or ExpressJS. Is there any particular reason it is done this way vs something syntactically cleaner, like: 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!
- an-tao 8y agoYou can register handler like this in Drogon: 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.
- shakna 8y ago2 small things. 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. [0] https://github.com/an-tao/drogon/wiki/quick-start https://github.com/an-tao/drogon/wiki/quick-start
- an-tao 8y agoYour suggestion is very good, I have made some modifications.
- ilovecaching 8y agoWhy not just wrap libevent or some other battle tested network poller? 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.
- svnpenn 8y agoI agree. However your wording just makes you seem like a rust fanboy. Other decent new languages exist such as Nim and Zig.
- ilovecaching 8y agoNim is playing much of the same tune of D, which ultimately failed to gain the needed traction to be a real competitor. It's already ruined by inheritance and the desire to please everyone with the multi-paradigm, take it or leave it GC, compile to everything approach. 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.
- oconnor663 8y ago> As it stands writing web services in C++ is basically programming malpractice at this point. This is the kind of extremism that makes people hate Rust. Please don't make people hate Rust.
- ilovecaching 8y agoI am unapologetic about the truth. The calculus engineers employee that leads them to defer the safety of user facing software for the familiarity of C++ has to stop.
- KirinDave 8y agoThis is cool, and I like it. Very Haskell like, which is a compliment in my book. 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.
- ilovecaching 8y agoBy that argument, they should get cracking on HTTP/3 already. :) 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.
- stock_toaster 8y agoMaybe they can just skip 2 and go straight to 3! :P
- deleted 8y ago[deleted]
- KirinDave 8y agoHTTP/2 has support on over 90% on caniuse, which is a decent approximation of what most folks selling products here will see. The browsers that don't support it aren't the sort we really care that much about anyways unless we're building a bank or something, in which case suffering is your mandate anyways. 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.
- stock_toaster 8y ago
- keyle 8y agoI wish it told me why it's better than nginx/others rather than why the author picked that name.
- securityfreak 8y agoDrogon is an application framework. Nginx is a web server. You can’t write a custom application in nginx. You can write almost anything in Drogon. Both handle HTTP requests, but nginx mostly forwards requests to other stacks.
- dagw 8y agoYou can’t write a custom application in nginx. Using Nginx modules and LuaJIT, you kind of can. OpenResty is a web framework built using this principle.
- WalterGR 8y agoWhat’s the security story with this framework?
- ilovecaching 8y agoIf you really want a security story, you shouldn't be looking into a C++ server. That's a very false sense of security, there is no way to guarantee memory safety.
- otabdeveloper2 8y ago> there is no way to guarantee memory safety. 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.)
- ilovecaching 8y agoC++ wasn't invented to be safe in the same way as Rust or Ada, whose author's saw state of the art safety as a critical tenant of the language. Stroupsoup was, I believe, mostly interested in making C more suitable for large software engineering projects and was more interested in better abstractions, which could lead to better safety. 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.
- Thorrez 8y agoWhen a simple 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.
- deleted 8y ago[deleted]
- utopcell 8y agoI've used Crow [1], a C++ web micro framework, in the past and it was delightful. Glad to see more competition in this space. [1] https://github.com/ipkn/crow https://github.com/ipkn/crow
- vivekbernard1 8y agoNot that it's super important, but it'll be interesting to see this in the next techempower benchmark round.
- rienbdj 8y agoShame this is not built on libuv or even boost.
- mellery451 8y ago..yes - in particular, boost::asio which will provide a sensible transition to std::net (networking TS) when it's available.
- eao197 8y agoThere is a lightweight alternative that is built on top of standalone Asio (but Boost.Asio can also be used): https://github.com/Stiffstream/restinio https://github.com/Stiffstream/restinio
- StreamBright 8y agoIt should be submitted to Techempower benchmarks. https://www.techempower.com/benchmarks/ https://www.techempower.com/benchmarks/
- an-tao 8y agoIt has recently been submitted to TFB. https://github.com/TechEmpower/FrameworkBenchmarks/tree/master/frameworks/C%2B%2B/drogon https://github.com/TechEmpower/FrameworkBenchmarks/tree/mast...
- StreamBright 8y agoGood to know thanks!
- twic 8y ago> Use a NIO network lib based on epoll (kqueue under MacOS/FreeBSD) to provide high-concurrency, high-performance network IO 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.
- hawkingrip 8y agoIt's really awesome
- agallego 8y agocool project. 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
- an-tao 8y agoGood question! If the type of the parameter of callback is an r-reference, users must move resp into the callback. Note that the resp is a shared_ptr, which means callback can reuse the buffer or do anything to the resp object and copying smart pointers does not require too much cost.
- an-tao 8y agoFor benchmarking I have submitted it to the famous TFB and I am waiting for the result of testing round 18. https://github.com/TechEmpower/FrameworkBenchmarks/tree/master/frameworks/C%2B%2B/drogon https://github.com/TechEmpower/FrameworkBenchmarks/tree/mast...
- rlopezcc 8y agoJust wanted you to know "Drogon" means "Stoner" in spanish.
- an-tao 8y agoIt's an embarrassing mistake, thank you for your reminder, but it seems that it's too late to change the name.
- gitgud 8y agoHow big does this hello-world server binary compile down to?
- an-tao 8y agoAbout 5M bytes in size, considering that the drogon application is statically linked, I am afraid it has no advantage in binary size.