Nginx C function
nginx-c-function.github.io
nginx-c-function.github.io
https://www.nginx.com/resources/wiki/modules/
It's great because you don't even need a web framework, really. If you're comfortable and confident in nginx you can get quite a bit of performance out of the server while adding your application logic to it. I'm not sure why more people don't and just use it as a reverse proxy.
imho its keyword engineering, but you can see given the history why nginx adopters aren't thinking that way.
It has a sane architecture, and is fully privilege separated by default, with private keys isolated in a separate process. I've been using it lately to write REST APIs in C, and the experience has been awesome, it has great APIs to parse requests and easily construct responses.
I’ve been writing C for 25 years and I wouldn’t trust myself not to do something stupid.
C isn't hard to maintain -- it's not some mystical language..
Tools should be ergonomic, they should reduce the need for diligence, care, discipline, and intelligence.
I'm not saying that the above aren't all important to programming, or that we should abandon anything that's not easy, but we're humans and make human mistakes and tools that are unforgiving when we do are ripe to be replaced by those that nudge us back on track.
I completely agree with you on all points. Languages exist to make our lives easier.
When developers demand that compilers compete with each other on fractions of a percent of runtime performance, we set ourselves up for things like UB acting in unintuitive ways. When people give us the choice between safer but slower systems, and fast but unsafe ones, until recently people have overwhelmingly chosen fast and unsafe and pretended they're superhuman enough to not write bad code.
The language implementation is fast, and allows you to tap into any C-compatible library.
The question isn't why you would go through Lua, but why you would choose something with less support?
That's the role of the C API [0]. But usually you'd just be passing C up to Lua to bind it together.
For nginx-c-function, it's easy build and I can build this as dynamic module and use it with other servers which has same version of nginx.
It might be good to use lua if the person not good in c/c++.
It's primary interface is C. In our opinion, it's lighter weight, and simpler to integrate with your app.
https://github.com/Taymindis/nginx-c-function/issues/2
I haven't figured out how to get rid of the drop in performance though. Lets say you just return a 200 from the nginx location like so:
location /a {
return 200 "{\"result\": \"Hello World!\"}";
}
vs location / {
ngx_http_c_func_call 'getRoute';
}
The requests per second will drop by about 40% of what you'd otherwise get. This is with 4 workers, the worker_rlimit_nofile set to 262144 etc, etc.I'm not sure what I'm doing wrong. It is pretty nice given that you also get all of the other options like upstream handling and reverse proxying and pretty damned good speed. The flexibility this adds is beyond awesome. But if I only need max speed for an api that only talks to postgres, redis, and a few other things, I'd just use H2o.
std::string thing = "{\"result\": \"Hello World!\"}";
void getRoute(ngx_http_c_func_ctx_t* ctx) {
ngx_http_c_func_write_resp(
ctx,
200,
NULL,
ngx_http_c_func_content_type_json,
::thing.c_str(),
::thing.length()
);
}ngx_http_c_func_call "my_app_simple_get_greeting";
vs
ngx_http_c_func_call "my_app_simple_get_greeting" respTo=myResponseVariable;
I didn't see any different, just create a variable.