diff --git a/README.md b/README.md index 6118418..b94a122 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ [![Docker Stars](https://img.shields.io/docker/stars/sjdonado/bit.svg)](https://hub.docker.com/r/sjdonado/bit) [![Docker Image Size](https://img.shields.io/docker/image-size/sjdonado/bit/latest)](https://hub.docker.com/r/sjdonado/bit) -Lightweight URL shortener service with minimal resource requirements. Average memory consumption is under **20MiB RAM** and single CPU core consumption under 30%. +Lightweight URL shortener service with minimal resource requirements. Average memory consumption is under **20MiB** and single CPU core consumption under 30%. -bit is highly performant, achieving maximum **15.3K RPS** with a minimum latency of 48.89ms with 100K requests using 100 connections. For detailed benchmark results, see [benchmark](docs/SETUP.md#benchmark). +bit is highly performant, achieving maximum **15.3K RPS** with a minimum latency of 48.89ms for 100K requests using 100 connections. For detailed benchmark results, see [benchmark](docs/SETUP.md#benchmark). Images available on [Docker Hub](https://hub.docker.com/r/sjdonado/bit/tags). diff --git a/app/lib/database.cr b/app/lib/database.cr index 7bcfbf0..282b3c9 100644 --- a/app/lib/database.cr +++ b/app/lib/database.cr @@ -1,6 +1,6 @@ require "sqlite3" require "crecto" -require"micrate" +require "micrate" module App::Lib class Database @@ -9,7 +9,17 @@ module App::Lib Query = Crecto::Repo::Query config do |conf| - conf.uri = ENV["DATABASE_URL"] + base_url = ENV["DATABASE_URL"] + separator = base_url.includes?("?") ? "&" : "?" + + db_url = base_url + separator + + "pool_size=20" + + "&max_idle_pool_size=10" + # Keep connections ready + "&journal_mode=WAL" + # Write-Ahead Logging for concurrent reads + "&synchronous=NORMAL" + # Better performance with reasonable safety + "&foreign_keys=true" + + conf.uri = db_url end if ENV["ENV"] == "development" diff --git a/docs/SETUP.md b/docs/SETUP.md index cb51030..ed72a3e 100644 --- a/docs/SETUP.md +++ b/docs/SETUP.md @@ -27,7 +27,7 @@ docker run \ --name bit \ -p 4000:4000 \ -e ENV="production" \ - -e DATABASE_URL="sqlite3://./sqlite/data.db?journal_mode=wal&synchronous=normal&foreign_keys=true" \ + -e DATABASE_URL="sqlite3://./sqlite/data.db" \ -e APP_URL="http://localhost:4000" \ -e ADMIN_NAME="Admin" \ -e ADMIN_API_KEY=$(openssl rand -base64 32) \ @@ -52,7 +52,7 @@ dokku letsencrypt:enable bit dokku storage:ensure-directory bit-sqlite dokku storage:mount bit /var/lib/dokku/data/storage/bit-sqlite:/usr/src/app/sqlite/ -dokku config:set bit DATABASE_URL="sqlite3://./sqlite/data.db?journal_mode=wal&synchronous=normal&foreign_keys=true" APP_URL=https://bit.donado.co ADMIN_NAME=Admin ADMIN_API_KEY=$(openssl rand -base64 32) +dokku config:set bit DATABASE_URL="sqlite3://./sqlite/data.db" APP_URL=https://bit.donado.co ADMIN_NAME=Admin ADMIN_API_KEY=$(openssl rand -base64 32) dokku ports:add bit http:80:4000 dokku ports:add bit https:443:4000