Coder Social home page Coder Social logo

minikawoon / c-service-interface Goto Github PK

View Code? Open in Web Editor NEW

This project forked from taymindis/fcgi-function

1.0 0.0 0.0 44 KB

csif is a C-Service interface built by C-language based Service Interface which build on top of FastCGI and NGINX which provided function handler support, it also provided useful collection tools to enhance the facilities, It has built in CJSON third party library to handle JSON payload.

License: MIT License

CMake 10.30% C 81.55% C++ 8.14%

c-service-interface's Introduction

C-Service-Interface(CSIF)

C service interface is C Language based, It is a Service Interface build on top of FastCGI and Nginx which provided function handler support, it also provided useful collection tools to enhance the facilities.

Prerequisition Installed

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

cJSON libraries -- https://github.com/DaveGamble/cJSON

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

cmake and make

Supported OS: LINUX, MAC OSX

Step of installation

1. Go to root directory

2. type

mkdir build (if not existed)

cd build

cmake ..

make

sudo make install

3. the result will be

Install the project...

-- Install configuration: ""

-- Installing: /usr/local/lib/libcsif.dylib

-- Installing: /usr/local/lib/libcsif.a

-- Installing: /usr/local/include/csif/csif.h

-- Installing: /usr/local/include/csif/csif_json.h

-- Installing: /usr/local/include/csif/csif_hash.h

-- Installing: /usr/local/include/csif/csif_LFHashTable.h

-- Installing: /usr/local/include/csif/csif_map.h

-- Installing: /usr/local/include/csif/csif_buf.h

-- Installing: /usr/local/include/csif/csif_pool.h

4. build a simple program by execute

gcc ../services_sample/profile_service.c -lcsif -lcjson -lfcgi -rdynamic -o simple_service

if C++ please use c++03

g++ -std=c++03 ../services_sample/cpp_profile_service.cpp -lcsif -lcjson -lfcgi -rdynamic -o simple_service

5. when you type

./simple_service

it will result:- Available options:

-a	the ip address which binding to

-p	port number to specified, not for -s

-s	unix domain socket path to generate, not for -p

-q	number of socket backlog

-w	number of worker process

-l	log file path

-e	signal handling

-f	Fork Daemon process

-d	Run on debug Mode

-o	Dynamic Link shared object file

-h	display usage

-v	display version

6. simple start a service by execute

./simple_service -p2005 -q200 -w200 -d

7. 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;
}

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.

8. start the nginx server

9. 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

To uninstall.

1. Go to root_directory/build folder -- make sure build content is still existed.

2. type "sudo make uninstall"

Then result

-- Uninstalling /usr/local/lib/libcsif.dylib

-- Uninstalling /usr/local/lib/libcsif.a

-- Uninstalling /usr/local/include/csif/csif.h

-- Uninstalling /usr/local/include/csif/csif_json.h

-- Uninstalling /usr/local/include/csif/csif_hash.h

-- Uninstalling /usr/local/include/csif/csif_LFHashTable.h

-- Uninstalling /usr/local/include/csif/csif_map.h

-- Uninstalling /usr/local/include/csif/csif_buf.h

-- Uninstalling /usr/local/include/csif/csif_pool.h

c-service-interface's People

Contributors

taymindis avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.