Swapi is a CRSD Create Read Search Delete show case for the following features:
- Async/Sync actors.
- Actor communication in a local/thread context.
- Uses Futures for asynchronous message handling.
- HTTP1/HTTP2 support (actix-web)
- Typed messages (No
Any
type). - Patched Mentat Datomic's embedded database
- Multi-producer multi-consumer channels
- Json speculative parsing with Pikkr which is based on Y. Li, N. R. Katsipoulakis, B. Chandramouli, J. Goldstein, and D. Kossmann. Mison: a fast JSON parser for data analytics. In VLDB, 2017. Benchmark Result:
- REST interface
- CORS enabled
- Http client requests with actors based Scatter-Gather Pattern
- Client requests with Least Recent Used frontal cache LRU Time Cache
- Json result paging
- Authentication
- database replication
- Json error handling
To compile and install you need to first install Rust compiler
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly-2018-05-10
Compile for release
cargo build --release
Should compile and work on all rust compiler supported plataforms but only tested for 64bit linux
There is a docker image on docker hub
docker pull mmacedoeu/swapi
docker run -p 8080:8080 mmacedoeu/swapi
Look for Snap install instructions for your OS and install swapi with:
sudo snap install swapi --channel=edge --devmode
Support for heroku based Cloud services with provided Procfile, should work on any cloud provider based on Heroku Procfile and with minor manifest files on any Cloud provider
Display help:
./target/release/swapi --help
Star Wars Api
USAGE:
swapi [OPTIONS]
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
-d <db> Specify the base database storage path.
-e <expire> Time in seconds for cache expiration. default 7 days. [default: 604800]
-i <IP> Specify the hostname portion of the REST API server, IP should be an interface's IP address,
or all (all interfaces) or local. [default: local]
-l <LOG_PATTERN> Sets a custom logging
-p <PORT> Api tcp listener port, default to environment variable PORT or 8080
Run with full trace:
./target/release/swapi -l trace
Run with no logging:
./target/release/swapi -l warn,actix_web::middleware::logger=warn
Manual Testing is done with your preferred http client cli like curl, Httpie, http-prompt, or any http test tool like postman
http :8080/sw
http :8080/sw/?search=Tato
http :8080/sw/<uuid>
like http :8080/sw/0c298919-76f0-42d7-868b-0a0d70d14903
http DELETE :8080/sw/<uuid>
like http DELETE :8080/sw/0c298919-76f0-42d7-868b-0a0d70d14903
http POST :8080/sw name=Hoth climate=frozen terrain='tundra, ice caves, mountain ranges'
Using Vegeta with 8 cores during 10 seconds and 5000 requests per second
echo "GET http://localhost:8080/sw" | vegeta attack -duration=10s -rate=5000 | tee results.bin | vegeta report -reporter=plot > plot.html
echo "GET http://localhost:8080/sw" | vegeta attack -duration=10s -rate=5000 | tee results.bin | vegeta report
Requests [total, rate] 50000, 5000.10
Duration [total, attack, wait] 10.000322134s, 9.999799929s, 522.205µs
Latencies [mean, 50, 95, 99, max] 583.374µs, 457.817µs, 1.038971ms, 3.024058ms, 15.524554ms
Bytes In [total, mean] 19950000, 399.00
Bytes Out [total, mean] 0, 0.00
Success [ratio] 100.00%
Status Codes [code:count] 200:50000
Error Set:
echo "GET http://localhost:8080/sw/de09bbe9-a993-4ede-89aa-6713e8fc2976" | vegeta attack -duration=10s -rate=5000 | tee results.bin | vegeta report
Requests [total, rate] 50000, 5000.10
Duration [total, attack, wait] 10.00022721s, 9.999799894s, 427.316µs
Latencies [mean, 50, 95, 99, max] 477.733µs, 396.327µs, 785.652µs, 2.179568ms, 11.341423ms
Bytes In [total, mean] 6850000, 137.00
Bytes Out [total, mean] 0, 0.00
Success [ratio] 100.00%
Status Codes [code:count] 200:50000
Error Set:
echo "GET http://127.0.0.1:8080/sw/?search=Tato" | vegeta attack -duration=10s -rate=5000 | tee results.bin | vegeta report
Requests [total, rate] 50000, 5000.10
Duration [total, attack, wait] 10.000370959s, 9.999799882s, 571.077µs
Latencies [mean, 50, 95, 99, max] 727.904µs, 482.15µs, 1.551523ms, 4.861028ms, 22.019851ms
Bytes In [total, mean] 5650000, 113.00
Bytes Out [total, mean] 0, 0.00
Success [ratio] 100.00%
Status Codes [code:count] 200:50000
Error Set:
With histogram:
echo "GET http://127.0.0.1:8080/sw/?search=Tato" | vegeta attack -duration=10s -rate=5000 | tee results.bin | vegeta report -reporter='hist[0,1ms,2ms,3ms,4ms]'
Bucket # % Histogram
[0s, 1ms] 46790 93.58% ######################################################################
[1ms, 2ms] 1773 3.55% ##
[2ms, 3ms] 624 1.25%
[3ms, 4ms] 297 0.59%
[4ms, +Inf] 516 1.03%