All Projects → Taymindis → fcgi-function

Taymindis / fcgi-function

Licence: MIT license
A cross-platform module to writing C/C++ service for nginx.

Programming Languages

c
50402 projects - #5 most used programming language
CMake
9771 projects
C++
36643 projects - #6 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to fcgi-function

Fos
FastCgi Server designed to run Owin applications side by side with a FastCgi enabled web server.
Stars: ✭ 65 (+96.97%)
Mutual labels:  webserver, fastcgi
Gofast
gofast is a FastCGI "client" library written purely in go
Stars: ✭ 140 (+324.24%)
Mutual labels:  webserver, fastcgi
Criollo
A powerful Cocoa web framework and HTTP server for macOS, iOS and tvOS.
Stars: ✭ 229 (+593.94%)
Mutual labels:  webserver, fastcgi
concurrent-ll
concurrent linked list implementation
Stars: ✭ 66 (+100%)
Mutual labels:  lock-free
wine
A lightweight and flexible framework to help build elegant web API
Stars: ✭ 39 (+18.18%)
Mutual labels:  webserver
async
async is a tiny C++ header-only high-performance library for async calls handled by a thread-pool, which is built on top of an unbounded MPMC lock-free queue.
Stars: ✭ 25 (-24.24%)
Mutual labels:  lock-free
quranize
transform transliteration to Quran text
Stars: ✭ 13 (-60.61%)
Mutual labels:  indexing
DSMRloggerWS
New firmware for the DSMRlogger heavily using WebSockets and Javascript
Stars: ✭ 29 (-12.12%)
Mutual labels:  webserver
mongoose
Embedded Web Server
Stars: ✭ 8,968 (+27075.76%)
Mutual labels:  webserver
http-server-pwa
👾 http-server alike but for serving and rendering PWA: pwa-server
Stars: ✭ 14 (-57.58%)
Mutual labels:  indexing
secondary
Redis Secondary Indexing Module, been suspended see: https://github.com/RediSearch/RediSearch/
Stars: ✭ 33 (+0%)
Mutual labels:  indexing
SimpleWebServer
TinyWebServer的cpp11实现,代码精简,注释详尽,比原版更容易阅读上手!新增文件上传与下载功能!
Stars: ✭ 67 (+103.03%)
Mutual labels:  webserver
btree
A persistent B+Tree (clustered index) implementation in Rust.
Stars: ✭ 167 (+406.06%)
Mutual labels:  indexing
DevCeption
Inception Style (Docker inside Vagrant inside Host) Development Environment
Stars: ✭ 13 (-60.61%)
Mutual labels:  webserver
zedis
A tiny embedded, lock free, redis-like, pub+sub, brokerless, key value datastore. ømq+sled
Stars: ✭ 33 (+0%)
Mutual labels:  lock-free
hasses
Hyper's Asynchronous Server Sent event (SSE) notification Server
Stars: ✭ 18 (-45.45%)
Mutual labels:  webserver
learn undertow
learn undertow
Stars: ✭ 27 (-18.18%)
Mutual labels:  webserver
lockfree
⚡️ lock-free utilities in Go
Stars: ✭ 109 (+230.3%)
Mutual labels:  lock-free
Jarvis
APL-based web service framework supporting JSON or REST
Stars: ✭ 17 (-48.48%)
Mutual labels:  webserver
gdrive-index
An index server for Google Drive
Stars: ✭ 107 (+224.24%)
Mutual labels:  indexing

fcgi-function

fcgi Function is a C/CPP language based interface, which build on top of FastCGI with built in functional handler support, it also provided useful collection tools to enhance the facilities. It can be integrated with Nginx Fastcgi module

How it works

Image of architecture

Prerequisition Installed

Nginx -- https://www.nginx.com/

fcgi library -- https://github.com/FastCGI-Archives/FastCGI.com

cmake and make

Supported OS: LINUX, MAC OSX, and Windows

Clone the Repository Recursively

git clone --recursive https://github.com/Taymindis/fcgi-function.git

How to Build

Just Include ffunc.h and ffunc.c in your project, simplest way ( applicable to Linux, Darwin and Windows platforms )

Build sample

gcc profile_service.c ffunc.c ffunc.h -lfcgi -pthread -ldl -rdynamic

g++ profile_service.cpp ffunc.c ffunc.h -lfcgi -pthread -ldl -rdynamic

g++ -std=c++11 -I/home/xxx/cpplib/spdlog-0.17.0/include -DSPDLOG_FMT_PRINTF service_with_spdlog.cpp ffunc.c ffunc.h -lfcgi -pthread -ldl -rdynamic

when you type

./simple_service

it will result:-

Service starting
sock_port=2005, backlog=16
total function = 3
64 threads in process
Socket on hook 2005

Running on background by setting ffunc_conf->daemon = 1 , see example for mode details

int ffunc_main(int argc, char *argv[], ffunc_config_t *ffunc_conf) {
  ffunc_conf->sock_port = 2005;
  ffunc_conf->backlog = 160;
  ffunc_conf->max_thread = 64;
  ffunc_conf->daemon = 1; // run as daemon
  ffunc_parse_function(ffunc_conf, "getProfile", "postError", "postProfile");
  return 0;
}

Running on valgrind (performance will impact)

valgrind --leak-check=full --show-leak-kinds=all --trace-children=yes ./simple_service

Edit the nginx.conf in your nginx config folder by append in your server block:-

location /getProfile {
  add_header Allow "GET, POST, HEAD" always;
  if ( $request_method !~ ^(GET|HEAD)$ ) {
    return 405;
  }
  include /etc/nginx/fastcgi_params;
  fastcgi_param FN_HANDLER getProfile;
  fastcgi_pass 127.0.0.1:2005;
}

location /postProfile {
  add_header Allow "GET, POST, HEAD" always;
  if ( $request_method !~ ^(POST)$ ) {
    return 405;
  }
   include /etc/nginx/fastcgi_params;
  fastcgi_param FN_HANDLER postProfile;
  fastcgi_pass 127.0.0.1:2005;
}

Edit the httpd.conf in your httpd config folder by append in your block

<Location "/getProfile">
    # Timeout values are in seconds
    ProxyPass "fcgi://127.0.0.1:2005" connectiontimeout=300 timeout=300
    ProxyPassReverse "fcgi://127.0.0.1:2005"
    SetEnv  FN_HANDLER "getProfile"
</Location>

You will see the FN_HANDLER is function name mapping with the function inside simple_service code, the fastcgi port 2005 is the service you start with(please look at step 10 for more details.

start the nginx/httpd server

Using apache benchmark for get request load test

ab -c 100 -n 10000 http://127.0.0.1:80/getProfile

For post request load test

ab -p "payload.txt" -T application/json -c 100 -n 10000 http://127.0.0.1:80/postProfile

the payload.txt is inside the root directory

shutdown the background instance

kill the process by using kill -2 <pid>, please do not use -9 as it will direct kill the process, unless -2 is not working

for valgrind log, you will get the summary report after kill -2 <pid>

Example of how to build a docker image

cd DockerExample
docker build -t nginx_ffunc -f Dockerfile_ngx_ffunc .
docker run -d -v ~/fcgi-function/DockerExample:/tmp -p 80:80 --name testffunc nginx_ffunc
curl "http://127.0.0.1/getProfile"

Logging Recommendation

Due to built in logging mechanism will slow down the process speed, suggested to use third party logging mechanism for your application layer such as:-

C++ spdlog

C++ g3log

C mini-async-log

Please contact [email protected] for More End to End tier project examples.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].