13 ms·
Balde: a microframework to develop web applications in C
- catmanjan 10y agoLooks neat, although I think I'd find myself mistyping "blade" a lot.
- _RPM 10y agoSo this has an embedded HTTP server then? Looks cool.
- kbaker 10y agoNo, I don't think so, it says it requires an SCGI interface to the web server. Apparently SCGI is like an upgraded CGI.
- aninteger 10y agoLooking through the source (app.c) it can do SCGI, CGI, and also has its own httpd server.
- rafaelmartins 10y agoYou are supposed to use SCGI in production. The embedded HTTPD is provided to help during development, so you don't need to setup SCGI in your local machine. I never did any serious testing on the HTTPD, but it was not developed with security and performance in mind.
- isuckatcoding 10y agoThis looks very interesting. This being C, I assume the performance is really good (although yes I know it's not always the case). However, C is one of those "double-edged sword" kinds of languages. What kind of trade offs between performance and "safety" would one be making here? Are they worth it?
- ktRolster 10y agoThis being C, I assume the performance is really good FWIW, everyone I know who moved web-serving things to C did so primarily because of latency, and then secondarily to avoid GC time delays. Higher transactions per server was a bonus, but no one did it for that. Also, if you have to hit a database, then any efficiency you get from switching to C will probably be swallowed up by that.
- woodman 10y ago> Also, if you have to hit a database... I can only think of one case where that is pretty much always true - CRUD with a network connected db backend, several cases where it is debatable, and a bunch of cases where that is wrong. See sqlite3, situations where you can use unix sockets, dynamically loaded modules, etc. I'm finishing up a project that basically builds state models from log events, automatically, and robustly enough that hopefully the end users wouldn't notice if I were run down by a bus. With the massive amount of data and high dimensionality of the problem, I have a hard time seeing how to pull it off but with C and statically compiled sqlite... or a big bag of money to throw at IBM.
- ktRolster 10y agobuilds state models from log events, automatically That sounds really cool, but I'm not quite sure what it means.
- woodman 10y agoTake business process modeling [0], and add a dash of directed acyclic graph [1]. You need both fast access to a massive amount of historical data, and the ability to finely control what gets stored where in memory - so not something you can really do in an SQL transaction. [0] https://en.wikipedia.org/wiki/Business_process_modeling https://en.wikipedia.org/wiki/Business_process_modeling [1] https://en.wikipedia.org/wiki/Directed_acyclic_graph https://en.wikipedia.org/wiki/Directed_acyclic_graph
- deleted 10y ago
- qaq 10y ago"With balde you can serve hundreds of requests per second" is it supposed to be "hundreds of thousands"?
- EpicEng 10y agoThey're just playing the expectations game.
- kabdib 10y agoUnlike, say, Oracle :-)
- est 10y agoIt's based on SCGI, which is kinda slow these days.
- m_mueller 10y agoSo why bother with a low level language like C? With just plain CPython, Flask and a file based approach (including polling the modified dates and thus get live reload) I can get up to ~2500 req/s on localhost with a good CPU, i.e. network is going to be the bottleneck until a fairly high level of performance (at which it becomes a no brainer to scale out). https://github.com/muellermichel/guetzli https://github.com/muellermichel/guetzli
- rafaelmartins 10y agoI'm just avoiding claims without evidence... unlike the guy who says that SCGI is slow ;)
- m_mueller 10y agoIt would still be interesting to know what you think you can achieve with this approach, i.e. in a direct comparison with Flask (because as you wrote it's quite similar in the featureset) what do you think is the advantage of your approach? Performance is the only justification you give on the page, so I'd be curious about this. Other than that I guess it's useful if you want to display data from a C / C++ program without going through any bindings. When it comes to that, maybe it would be great to get some automatic HTML display helpers for data structures common in C, like Arrays of numerical values or pointers to sequences of structs. For example in Python it's really fun to just use something like [1] together with Flask and get interfaces to your data without doing any template programming. [1] https://github.com/softvar/json2html https://github.com/softvar/json2html
- ktRolster 10y agoIt has potential, but the documentation is full of TODO, so it's hard to say much about it. For example, I was trying to figure out how it handles unicode, and also how it handles memory management. For comparison, ribs2 ( https://github.com/Adaptv/ribs2 https://github.com/Adaptv/ribs2 ) is a framework in C that handles garbage collection for you. But it's not really a comparison because Balde doesn't have the documentation, unfortunately.
- rafaelmartins 10y agoyes, it lacks documentation, I started this blog post series to try to address this: https://rgm.io/post/balde-internals-part1-foundations/ https://rgm.io/post/balde-internals-part1-foundations/ if you have some specific question, feel free to ask
- ktRolster 10y agoSo, how does it handle memory allocation? Are there memory pools?
- rafaelmartins 10y agoas it is a microframework, it does not cares about such details, you can handle memory allocation by hand, or use memory pools provided by glib, create gobjects and use refcount, etc. It is up to you :) Internally used memory should be free'd manually with the balde_app_free function. it encapsulates most of it for you.
- ktRolster 10y agoThat actually helps me have a better understanding of how the framework is structured, thanks.
- rafaelmartins 10y agoHi guys, I'm the author of this framework, and it seems that someone shared it here because I started this blog post series this weekend: https://rgm.io/post/balde-internals-part1-foundations/ https://rgm.io/post/balde-internals-part1-foundations/ This is why most of the documentation is marked as TODO, but the API docs are reasonably up-to-date. If someone has interest on it or is willing to help, please let me know :) EDIT: simple url shortener example, using redis: https://gist.github.com/rafaelmartins/9f8392a8909e62820ae0 https://gist.github.com/rafaelmartins/9f8392a8909e62820ae0 "complete" app, with templates and stuff: https://github.com/rafaelmartins/bluster https://github.com/rafaelmartins/bluster
- 35bge57dtjku 10y agoIs it supposed to do more than hundreds of requests per second??
- rafaelmartins 10y agoof course. I'll just get some benchmark results published before doing such claim on the website. :)
- chmike 10y agoCould you please compare it with kore [https://github.com/jorisvink/kore https://github.com/jorisvink/kore] which is another C web server that seam quite efficient when tested with the benchmarking tool wrk [https://github.com/wg/wrk https://github.com/wg/wrk]. Result are bad with the benchmark tool Siege for kore because of its particular request pattern. You might find this set of benchmarks inspirational [https://github.com/nanoant/WebFrameworkBenchmark https://github.com/nanoant/WebFrameworkBenchmark]. The Java web server seam faster because it returns less data. kore is faster in fact. Note: vibe.d has improved its performance with more recent versions. The author of the benchmarks ignore requests to update the benchmarks.
- bencollier49 10y agoIs this meant to be pronounced "baldy"? Are you bald? Excellent name, especially if one or more of the above questions are true!
- eatonphil 10y agoI've been looking into web frameworks in C recently. The offerings aren't awesome. It's hard to find a good BSD-like-licensed library. Frontrunners included Kore and Crow (another microframework). I went with Kore for a while but it has a pretty terrible API for actually writing web applications. I couldn't take Crow seriously. I ended up going with fastcgi because it was the simplest to wrap using the Scheme FFI. Others included Lwan (gpl) and Mongoose (gpl).
- aninteger 10y agoWell there is civetweb (BSD) which was forked from an earlier BSD release of mongoose but has now diverged a little on its own.
- rafaelmartins 10y agoI'd love to make balde BSD-licensed ( see https://github.com/balde/balde/wiki/Converting-from-LGPL-to-BSD https://github.com/balde/balde/wiki/Converting-from-LGPL-to-... ) but unfortunately I have to deal with GLib for now... :/
- woodman 10y agohttps://libwebsockets.org https://libwebsockets.org - LGPL though. There would be a bunch of dead code if you had no intention of using WS, but the commitment to being valgrind-clean is pretty nice, multiple event library options, multiple ssl backend options... lots of flexibility with what I find to be a sane api. Oh and this might matter to some more than others, but the developer is very active - I've had pull requests accepted within minutes for the obviously correct patches.
- hellofunk 10y agobuilding libwebsockets on iOS can be quite a chore for many, however, and the authors of the library are not shy to express their distaste for Apple products, which I find inappropriate.
- 10y ago
- lossolo 10y agoBecause we all do web applications in C.
- deleted 10y ago[deleted]
- lillesvin 10y agoWhy not? If we only developed for what we already do, then we'd still be doing the same stuff we did years ago. Besides, web apps in C aren't completely unheard of.
- ninguem2 10y agoBalde means bucket in Portuguese. I thought that was an accident, but looking at the logo on the website I guess it's intentional.
- kev009 10y agoI really wouldn't want to expose GLib to this level but to each their own. kcgi is an interesting C API with security taken seriously: http://kristaps.bsd.lv/kcgi/ http://kristaps.bsd.lv/kcgi/
- rafaelmartins 10y agoI love kcgi, but we have different focus. I may use it as FCGI layer for balde, though :)
- est 10y agoLooks like it's using NULL-terminated strings. Is the framework secure? Is it compatible with (all kinds of) Unicode and data with NULL in it?
- rspeer 10y agoWhy would you need to be compatible with "all kinds of Unicode", by which I assume you mean different encodings? You just need to be fully compatible with one kind of Unicode (UTF-8) and use it consistently. And null-terminated UTF-8 is no more or less safe than null-terminated ASCII, because the only UTF-8 codepoint that uses 0x00 is the same one as in ASCII.
- fauigerzigerk 10y agoThat's true provided you validate all UTF-8 input. As you probably know, UTF-8 has a lead byte that indicates how many of the following bytes are part of the same code point. If your code blindly believes what that first byte claims, then you could easily get tricked into reading beyond '\0'.
- deleted 10y ago[deleted]
- rspeer 10y agoYes, you should validate the UTF-8 at some point before you actually manipulate the contents of the string. Before that, you can just treat it as a pile of bytes. You don't need to go down different paths of how you read those bytes based on the codepoint lengths until you're actually doing something with codepoints.
- gbog 10y agoI remember that one big lesson learned after heartbleed bug was that we should not develop in C anymore. To me, this has probably many exceptions, but still should be especially true for web dev.
- mrweasel 10y agoIf that was your takeaway from Heartbleed, then you wheren't paying attention.
- TickleSteve 10y agowhoosh!
- azov 10y agoI would guess most people use C web frameworks for embeddability, not performance. The use case is to add a web-based UI to some C/C++ application or device, think configuration UI of your router or something of this sort. My go to solution for this is libwebsockets. Balde seems to have some nice features, but SCGI + external webserver requirement makes it difficult to embed. I'd also question whether GLib is a reasonable dependency for HTTP microframework.
- a2800276 10y agoMy thoughts exactly! Apart from embedded systems (or using it as embedded in an application, e.g. to provide an application's help system via an internal web browser) I'd find it weird to build websites in C. I'm looking for something along these lines for embedded systems, but GLib & external webserver disqualify balde. Still looks like a nice, clean project, though I was disappointed to find out I can't try it out :)
- tosseraccount 10y agoC may have some shortcomings, particulary policing memory vioations, but can be very lightweight and very fast. Remember, Linux and Apache/NGINX are in C . Implementing the site specifics in C isn't that much of a stretch. The extra speed could even make your site that much more useable. The canonical genome browser is written in C: http://genome.ucsc.edu/cgi-bin/hgTracks?db=hg19 http://genome.ucsc.edu/cgi-bin/hgTracks?db=hg19 ... for pure speed.
- deleted 10y ago[deleted]
- Eun 10y agoA comparison in terms of speed between blade and cppcms would be nice.
- jaromilrojo 10y agoI used my own C code generator for CGIs for years, along mongoose for other tasks. Nowadays I'm using https://kore.io https://kore.io and I'm VERY happy with it, great developer experience, well written and understandable code, minimal in dependencies and no bugs so far. I'm using it quite heavily in a project, it was easy to add templating and other amenities to it. Highly recommended.
- cordite 10y agoSeems more promising than g-wan
- sdsk8 10y agoRafael, congratulations on this project, i love seeing Brazilian projects here.
- moron4hire 10y ago"Why would anyone want this?" -- There are people who know C--and it's associate library ecosystem--really well and are very comfortable with it. They may have projects where it would not be a productive use of their time to have to learn a new language and a new set of libraries just to get a little code online. I know, shock and horror, wailing, gnashing of teeth. /s Is it just me, or has HN gotten really bitchy towards people's projects lately (and by "lately", I mean "the last year")? There are real people behind these projects. They did a thing and it might not be your cup of tea or anything in your experience bubble, but that doesn't make it stupid or misguided.
- icebraining 10y agoIt's not a new phenomena, Show HN has had such questions for years: https://news.ycombinator.com/item?id=5873619 https://news.ycombinator.com/item?id=5873619 :)
- deleted 10y ago[deleted]
- deleted 10y ago[deleted]
- mirekrusin 10y agoWhy not vala (or genie)?
- deleted 10y ago[deleted]
- bmedwar 10y agoanyone know a good micro web framework written in LLVM IR?
- deleted 10y ago[deleted]