{"id":37312324,"url":"https://github.com/bowber/axum-db-benchmark","last_synced_at":"2026-01-16T03:02:05.938Z","repository":{"id":308166937,"uuid":"1000059693","full_name":"bowber/axum-db-benchmark","owner":"bowber","description":"A benchmark of some db using rust + axum + wrk. Each db benchmark code and result locate in its own branch.","archived":false,"fork":false,"pushed_at":"2025-08-04T13:54:56.000Z","size":43347,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-08-04T17:05:51.560Z","etag":null,"topics":["benchmarking","rocksdb","rust","sqlite"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bowber.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-11T07:52:20.000Z","updated_at":"2025-08-04T13:55:00.000Z","dependencies_parsed_at":"2025-08-04T17:21:08.341Z","dependency_job_id":null,"html_url":"https://github.com/bowber/axum-db-benchmark","commit_stats":null,"previous_names":["bowber/axum-db-benchmark"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/bowber/axum-db-benchmark","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bowber%2Faxum-db-benchmark","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bowber%2Faxum-db-benchmark/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bowber%2Faxum-db-benchmark/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bowber%2Faxum-db-benchmark/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bowber","download_url":"https://codeload.github.com/bowber/axum-db-benchmark/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bowber%2Faxum-db-benchmark/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28476682,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T00:15:39.755Z","status":"online","status_checked_at":"2026-01-16T02:00:07.781Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["benchmarking","rocksdb","rust","sqlite"],"created_at":"2026-01-16T03:02:05.869Z","updated_at":"2026-01-16T03:02:05.929Z","avatar_url":"https://github.com/bowber.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Axum Database Benchmark\n\nA comprehensive database performance benchmark using Axum web framework with support for multiple database backends.\n\n## Supported Databases\n\nThis benchmark now supports **5 popular databases**:\n\n1. **SQLite** (default) - File-based SQL database with WAL mode\n2. **PostgreSQL** - Popular relational database\n3. **MySQL** - Popular relational database  \n4. **Redis** - In-memory key-value store\n5. **MongoDB** - Document database\n\n## Quick Start\n\n### Default SQLite Setup\n```bash\n# Uses SQLite by default (no setup required)\ncargo run\n```\n\n### Using Different Databases\n\nSet the `DATABASE_TYPE` environment variable to use different databases:\n\n```bash\n# PostgreSQL\nexport DATABASE_TYPE=postgres\nexport POSTGRES_URL=\"postgresql://postgres:password@localhost:5432/benchmark\"\ncargo run\n\n# MySQL\nexport DATABASE_TYPE=mysql\nexport MYSQL_URL=\"mysql://root:password@localhost:3306/benchmark\"\ncargo run\n\n# Redis\nexport DATABASE_TYPE=redis\nexport REDIS_URL=\"redis://localhost:6379\"\ncargo run\n\n# MongoDB\nexport DATABASE_TYPE=mongodb\nexport MONGO_URL=\"mongodb://localhost:27017\"\ncargo run\n```\n\n## Database Setup\n\n### SQLite (Default)\nNo setup required. Creates `my_database.db` file automatically.\n\n### PostgreSQL\n```bash\n# Using Docker\ndocker run --name postgres-bench -e POSTGRES_PASSWORD=password -e POSTGRES_DB=benchmark -p 5432:5432 -d postgres:13\n\n# Or using local PostgreSQL\ncreatedb benchmark\n```\n\n### MySQL\n```bash\n# Using Docker\ndocker run --name mysql-bench -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=benchmark -p 3306:3306 -d mysql:8\n\n# Or using local MySQL\nmysql -u root -p -e \"CREATE DATABASE benchmark;\"\n```\n\n### Redis\n```bash\n# Using Docker\ndocker run --name redis-bench -p 6379:6379 -d redis:7\n\n# Or using local Redis\nredis-server\n```\n\n### MongoDB\n```bash\n# Using Docker\ndocker run --name mongo-bench -p 27017:27017 -d mongo:6\n\n# Or using local MongoDB\nmongod\n```\n\n## API Endpoints\n\nAll databases expose the same REST API:\n\n- `GET /` - Health check\n- `POST /users` - Create user: `{\"username\": \"john\"}`\n- `GET /users/{username}` - Get user by username\n- `PATCH /users/{username}` - Update user: `{\"age\": 25}`\n- `DELETE /users/{username}` - Delete user by username\n\n## Benchmarking\n\nUse the included wrk scripts for benchmarking:\n\n```bash\n# Start the server\ncargo run\n\n# In another terminal, run benchmarks:\n\n# GET requests\nwrk -t4 -c100 -d10s http://localhost:3000/users/testuser\n\n# POST requests  \nwrk -t4 -c100 -d10s -s post.lua http://localhost:3000\n\n# PATCH requests\nwrk -t4 -c100 -d10s -s update.lua http://localhost:3000  \n\n# DELETE requests\nwrk -t4 -c100 -d10s -s delete.lua http://localhost:3000\n```\n\n## Performance Notes\n\n### SQLite Configuration\n- **Journal Mode**: WAL2 for better concurrent performance\n- **Synchronous**: NORMAL for balanced safety/performance\n- **Foreign Keys**: Enabled\n- **Connection Pool**: r2d2 with configurable pool size\n\n### Database-Specific Optimizations\n- **PostgreSQL/MySQL**: Uses connection pooling with r2d2\n- **Redis**: JSON serialization for complex data structures  \n- **MongoDB**: Indexes on username field for fast lookups\n- **All**: Async operations for non-blocking I/O\n\n## Previous Benchmark Results (SQLite)\n\n### Max Throughput (Single vs Multi-connection):\n\n**Single-connection (r2d2_sqlite with 1 connection):**\n- SELECT: 120,943 rows/sec\n- INSERT: 22,379 rows/sec  \n- UPDATE: 41,299 rows/sec (97,882 without value changes)\n- DELETE: 51k to 137k rows/sec\n\n**Multi-connection (r2d2_sqlite with pool):**\n- SELECT: 502,142 rows/sec\n- Similar INSERT/UPDATE/DELETE performance after configuration fixes\n\n## Testing\n\n```bash\n# Run unit tests (uses in-memory SQLite)\ncargo test\n\n# Run with specific database for integration testing\nDATABASE_TYPE=postgres cargo test\n```\n\n## Architecture\n\nThe application uses a trait-based database abstraction:\n\n```rust\n#[async_trait]\npub trait Database: Send + Sync + Clone {\n    type Error: std::error::Error + Send + Sync + 'static;\n    \n    async fn init() -\u003e Result\u003cSelf, Self::Error\u003e;\n    async fn create_user(\u0026self, user: CreateUser) -\u003e Result\u003cString, Self::Error\u003e;\n    async fn get_user(\u0026self, username: String) -\u003e Result\u003cUser, Self::Error\u003e;\n    async fn update_user(\u0026self, username: String, update: UpdateUser) -\u003e Result\u003c(), Self::Error\u003e;\n    async fn delete_user(\u0026self, username: String) -\u003e Result\u003c(), Self::Error\u003e;\n}\n```\n\nThis allows switching between databases at runtime while maintaining the same API and benchmark scripts.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbowber%2Faxum-db-benchmark","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbowber%2Faxum-db-benchmark","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbowber%2Faxum-db-benchmark/lists"}