Skip to content
/ CCache Public

C HTTP throughput cache using Tarantool and PostgreSQL

Notifications You must be signed in to change notification settings

chmzy/CCache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTTP throughput cache

written in C, with PostgreSQL and Tarantool

Features

  • HTTP API, can be used via Postman or Thunder Client;
  • Uses in-memory cache to improve throughput;
  • PostgreSQL - the best database management system;
  • ANSI C;
  • Cmake config to build project by yourself;

HTTP data schema

Request HTTP Method Request body Asnwer
/data PUT {data: string "any string data"} id: string uuid
/data?id=my_id GET {id: string my_id, data: string my_data}

Launch guide

Pre-requisites

Before we proceed:

  1. Install the PostreSQL (author uses Ubuntu)
    sudo apt install postgresql postgresql-contrib
  2. Install PostgreSQL library
    sudo apt-get install libpq-dev
  3. Install Tarantool
  4. Download and install C client library and msgpuck library

Initialize PostgreSQL

  1. If you cant login into Posgress, then follow this guide
  2. Start PostreSQL service
    sudo sudo service postgresql start
  3. Login into psql
    sudo -u postgres psql
  4. Create new user
    CREATE USER pico WITH PASSWORD 'pico';
  5. Create a new database:
    CREATE DATABASE picodb;
  6. Grant the user permission to access the database:
    GRANT ALL PRIVILEGES ON DATABASE picodb TO pico;
    ALTER USER pico CREATEDB;
    GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO pico;
  7. Exit from PostgreSQL
    \q
  8. Login into PostgreSQL as user and enter password:
    psql -U pico -d picodb
  9. Add extension for generating UUIDs
    CREATE EXTENSION "uuid-ossp";

NOTE:
Default PostgreSQL port is 8080. It can be configured in pg_hba.conf file

Initialize Tarantool

  1. Run Tarantool:
    tarantool
  2. Set listening port:
    box.cfg{ listen = '8081' } 

NOTE:
Remember this port. It will be used to communicate with Tarantool. Can be confugured in config.txt (located in project folder)

  1. Change password for admin:
    box.schema.user.passwd('pass')
  2. Create space - Tarantool table:
    s = box.schema.space.create('pico_tarantool')
    s:format({{name = 'id', type = 'string'},{name = 'data', type = 'string'}})---
    s:create_index('primary',{type = 'hash', parts = {'id'}})
  3. Get space id
    box.space.pico_tarantool.id

NOTE:
Remember this id. It will be used to store data in it. Can be confugured in config.txt (located in project folder)

(C)Make source files

  1. Project main folder
    -src
  • main.c
  • ...
    CMakeLists.txt
    config.txt
    Readme.md
  1. Create build folder
    mkdir build
  2. Configure cmake
    cmake -B ./build -S .

NOTE:
Execute this command in folder, where CMakeLists.txt is located

  1. Change dir to build
    cd ./build
  2. Run cmake
    cmake ../CMakeLists.txt
  3. Run make
    make
  4. Run compiled file pico with flag -f /path/to/config.txt
    ./pico -f ../config.txt

Sending requests

  1. Just use Postaman or Thunder Client. Create and send requests, guiding by HTTP data shema provided before.
  2. Enjoy :)

Known issues

  1. PUT request: JSON with spaces and will not work for Tarantool, while in PSQL stores correctly. Fixed
  2. If Tarantool goes offline while server is on - unexpected behavior. Fixed.
  3. If PostgreSQL goes offline while server is on - unexpected behavior. Note: Server responses with PSQL error.
  4. If you face any bugs and glitches - be welcome to make Pull Request!

TO DO

  • Proof of concept
  • MVP
  • Add HTTP validation
  • Cover MVP with test
  • Make better query parameters handler
  • Write func, that creates space in Tarantool, if space intially doesn't exist
  • Add pthread support
  • Check connection to PostgreSQL and Tarantool in separate threads
  • Make cache asynchronous
  • Cover code with test
  • More stuff to do

About

C HTTP throughput cache using Tarantool and PostgreSQL

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published