Giter Club home page Giter Club logo

smol-kv's Introduction

Description

Minimal working setup of Actix-web with RocksDB being used as a simple JSON KV store or cache.

Quick Start

❯ docker run -p 5050:5050 -e DATABASE_PATH=/rocksdb \
  -v $(pwd)/rocksdb:/rocksdb \
  mpwsh/smol-kv:latest

Build from source

clang is required to build. Install with pacman or apt. Check the Dockerfile for guidance.

❯ cargo build --release

Configuration

Set the following env vars to configure the server (optional)

PORT=5050
WORKERS=4
LOG_LEVEL=info
DATABASE_PATH=./rocksdb
ADMIN_TOKEN=yourtoken

At this point you can run the binary and the server should start.

Usage

Get value

❯ curl -i -X GET -H "Content-Type: application/json" http://localhost:5050/api/yourkey
# Returns error 404 if key was not found.

Create new key with value

Value needs to be in valid UTF-8 and in JSON format, parsing will fail otherwise.

❯ curl -X POST -H "Content-Type: application/json" -d '{"name":"test"}' http://localhost:5050/api/yourkey
# output
{"name":"test"}

Hitting http://localhost:5050/api/yourkey with a GET request should output the value now instead of responding with 404.

❯ curl http://localhost:5050/api/yourkey
{"name":"test"}

Trying invalid json

❯ curl -X POST -H "Content-Type: application/json" -d 'invalid' http://localhost:5050/api/wontwork
# output
{"msg":"Parsing failed. value is not in JSON Format","status":400}
# No data was saved

Delete a key

❯ curl -i -X DELETE -H "Content-Type: application/json" http://localhost:5050/api/yourkey
# No output
# 200 OK means operation succeeded
# Responds with error 500 if something went wrong.

Benchmark

A Drill plan is available in the benchmark folder. To run install drill using cargo and execute:

drill --benchmark benchmark/plan.yaml  --stats

Plan

iterations: 2000
concurrency: 4
rampup: 4

System details: AMD Ryzen 7 3700X, 32 GB Ram, Samsung SSD 970 EVO Plus

Results

'Failed requests' are 404 assertions, so those are actually successful.

Time taken for tests      3.6 seconds
Total requests            8000
Successful requests       6000
Failed requests           2000
Requests per second       2239.79 [#/sec]
Median time per request   0ms
Average time per request  2ms
Sample standard deviation 3ms
99.0'th percentile        11ms
99.5'th percentile        11ms
99.9'th percentile        11ms

Or using apache-bench

apt update && apt install -y apache-bench
ab -n 20000 -c 8 -H 'Authorization: supersecret' -p ./benchmark/data.json -T 'application/json' -rk http://127.0.0.1:5050/benchmark

Results

Requests per second:    41251.57 [#/sec] (mean)
Time per request:       0.194 [ms] (mean)
Time per request:       0.024 [ms] (mean, across all concurrent requests)
Transfer rate:          11843.71 [Kbytes/sec] received
                        12488.27 kb/s sent
                        24331.98 kb/s total

smol-kv's People

Contributors

mpwsh avatar ukchukx avatar

Forkers

shabbirhasan1

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.