capacherestcgi-bin

C program that acts as APIs


Sorry for my lack of knowledge related to this question but: if I want to create a C application that exposes a REST API layer using Apache as web server there are 2 options (at least these 2 I have found googling)

  • using CGI .

  • implement an Apache extension i.e hello_world.so and then load in the Apache configuration

What is the main difference between them in terms of process created, overhead, lag etc?

Thanks.


Solution

  • Using CGI, one runs the application in a separate process.

    Using Apache extensions, the application is a loaded module of Apache, and can run in the same process as Apache.

    For performance, you likely want it in the same process; however, if you have a coding error it will bring Apache down.

    For stability, you likely want it in a different process; however, the costs associated with starting and stopping the processes will be permanent overhead in your request processing, and that will limit the number of connections you can maintain and service.

    There is a compromise, but it shouldn't be seen as the best of both worlds. FastCGI works by reusing the CGI process that Apache uses. However, it is still slower than an Apache module, and incurs more overhead, but that overhead is generally less than traditional CGI.