Hacker News new | past | comments | ask | show | jobs | submit login

It works with nginx threads using aio. It's in one of the issues there if you look deep enough.

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.




what is the src of the C function?


Check this file out, it's in the example that's provided: https://github.com/Taymindis/sample-ngx-cfunc-project/blob/m... I've stripped out everything of 'getRoute' and only provide a response of a global variable 'thing' that never changes.

  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()
    );
  }




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: