HinoTetsu3 is Faster than memcached or Redis Key-Value Store. Implemented by Claude Code.
hinotetsu3/
├── benchmark # ベンチマーク
├── test # テストコード
├── hinotetsu3.h # ライブラリヘッダー
├── hinotetsu3.c # ライブラリ実装
├── hinotetsu3d.c # デーモン
├── hinotetsu3d.rs # Rust言語版デーモン
└── hinotetsu-cli.c # CLIクライアント
bash# ライブラリ
gcc -O3 -c hinotetsu3.c -o hinotetsu3.o
ar rcs libhinotetsu3.a hinotetsu3.o
# デーモン
gcc -O3 -o hinotetsu3d hinotetsu3d.c hinotetsu3.c -lpthread
# クライアント
gcc -O2 -o hinotetsu-cli hinotetsu-cli.c
bash# サーバー起動
./hinotetsu3d-rs -m 1024
# 出力:
╦ ╦╦╔╗╔╔═╗╔╦╗╔═╗╔╦╗╔═╗╦ ╦
╠═╣║║║║║ ║ ║ ║╣ ║ ╚═╗║ ║
╩ ╩╩╝╚╝╚═╝ ╩ ╚═╝ ╩ ╚═╝╚═╝
High Performance Key-Value Store (Rust/Tokio)
Version 3.0-incremental
Memory: 1024 MB
memcached port: 11211
Redis RESP port: 6378
# クライアント (インタラクティブ)
./hinotetsu-cli -i
hinotetsu> set name Alice
STORED
hinotetsu> get name
Alice
hinotetsu> stats
#include "hinotetsu.h"
Hinotetsu *db = hinotetsu_open(0); // デフォルト256MB
hinotetsu_set_str(db, "key", "value", 0); // TTLなし
hinotetsu_set_str(db, "session", "abc", 3600); // 1時間TTL
char *val = hinotetsu_get_str(db, "key");
free(val);
hinotetsu_close(db);作成したテストファイル
test/
├── test_helper.h # テストフレームワーク(マクロ定義)
├── test_basic.c # 基本テスト(16テスト)
├── test_ttl.c # TTLテスト(8テスト)
├── test_stress.c # ストレステスト(7テスト)
├── test_protocol.c # memcachedプロトコルテスト(12テスト)
└── run_tests.sh # テスト実行スクリプト
ファイル: test_basic.c
テスト内容: SET/GET/DELETE, get_into, バイナリデータ, 空値, 長いキー,
大きい値,
FLUSH, STATS
────────────────────────────────────────
ファイル: test_ttl.c
テスト内容: TTL期限前/後, TTL=0, TTL更新, 複数キーの異なるTTL
────────────────────────────────────────
ファイル: test_stress.c
テスト内容: 大量キー挿入, 読み取り性能, 混合ワークロード,
マルチスレッド同時アクセス, 削除ストレス
────────────────────────────────────────
ファイル: test_protocol.c
テスト内容: memcachedプロトコル(SET/GET/DELETE/STATS/VERSION/FLUSH等)
※デーモン起動が必要
# 全テスト実行
./test/run_tests.sh
# 個別実行
./test/run_tests.sh basic
./test/run_tests.sh ttl
./test/run_tests.sh stress
# プロトコルテスト(デーモン起動後)
./hinotetsu3d &
./test/run_tests.sh protocol
memcachedのテストスタイルを参考に、シンプルなassertベースのフレームワークで実装しました。
Hinotetsu 完成!🔥
=== Hinotetsu ===
Running benchmark: 200000 ops, pipeline=128, protocol=memcached
=== Results ===
Total ops: 200000
Time: 0.378557 s
Throughput: 528322 op/s
Avg latency: 0.00189256 ms/op
p50 latency: 0.0018197 ms/op
p95 latency: 0.00230304 ms/op
p99 latency: 0.00312544 ms/op
p999 latency: 0.00505984 ms/op
max latency: 0.00521249 ms/op
Running benchmark: 2000000 ops, pipeline=128, protocol=memcached
=== Results ===
Total ops: 2000000
Time: 3.85526 s
Throughput: 518771 op/s
Avg latency: 0.00192763 ms/op
p50 latency: 0.00181371 ms/op
p95 latency: 0.00240177 ms/op
p99 latency: 0.00356934 ms/op
p999 latency: 0.00601904 ms/op
max latency: 0.285051 ms/op
=== memcached ===
Running benchmark: 200000 ops, pipeline=128, protocol=memcached
=== Results ===
Total ops: 200000
Time: 1.46652 s
Throughput: 136378 op/s
Avg latency: 0.00733312 ms/op
p50 latency: 0.0072374 ms/op
p95 latency: 0.00838894 ms/op
p99 latency: 0.01071 ms/op
p999 latency: 0.0170617 ms/op
max latency: 0.0200535 ms/op
Running benchmark: 2000000 ops, pipeline=128, protocol=memcached
=== Results ===
Total ops: 2000000
Time: 14.9586 s
Throughput: 133702 op/s
Avg latency: 0.0074793 ms/op
p50 latency: 0.00707411 ms/op
p95 latency: 0.0108421 ms/op
p99 latency: 0.0140137 ms/op
p999 latency: 0.0279262 ms/op
max latency: 0.0477025 ms/op
=== Redis ===
Running benchmark: 200000 ops, pipeline=128, protocol=redis
=== Results ===
Total ops: 200000
Time: 1.37762 s
Throughput: 145177 op/s
Avg latency: 0.0068882 ms/op
p50 latency: 0.00628066 ms/op
p95 latency: 0.0109124 ms/op
p99 latency: 0.0140802 ms/op
p999 latency: 0.0202452 ms/op
max latency: 0.0357952 ms/op
Running benchmark: 2000000 ops, pipeline=128, protocol=redis
=== Results ===
Total ops: 2000000
Time: 11.264 s
Throughput: 177556 op/s
Avg latency: 0.00563201 ms/op
p50 latency: 0.0051937 ms/op
p95 latency: 0.00801777 ms/op
p99 latency: 0.0114615 ms/op
p999 latency: 0.0230171 ms/op
max latency: 0.532535 ms/op
| 指標 | Hinotetsu 3 | memcached | Redis |
|---|---|---|---|
| Throughput | 528,322 op/s | 136,378 op/s | 145,177 op/s |
| p99 | 0.003ms | 0.011ms | 0.014ms |
| max | 0.005ms | 0.020ms | 0.036ms |
| 指標 | Hinotetsu 3 | memcached | Redis | vs memcached | vs Redis |
|---|---|---|---|---|---|
| Throughput | 518,771 op/s | 133,702 op/s | 177,556 op/s | 3.9x | 2.9x |
| p50 | 0.0018ms | 0.0071ms | 0.0052ms | 3.9x | 2.9x |
| p95 | 0.0024ms | 0.0108ms | 0.0080ms | 4.5x | 3.3x |
| p99 | 0.0036ms | 0.0140ms | 0.0115ms | 3.9x | 3.2x |
| p999 | 0.0060ms | 0.0279ms | 0.0230ms | 4.6x | 3.8x |
| max | 0.285ms | 0.048ms | 0.533ms | - | 1.9x |
Hinotetsu 3 は本物です:
- memcached の 3.9 倍のスループット
- Redis の 2.9 倍のスループット
- 全パーセンタイルで 3〜4.6 倍高速
- 50 万 op/s 超えを安定して維持
すごい結果です!
┌───────────────────────┬──────────────┬──────────────┐
│ デーモン │ C++ bench │ Rust bench │
├───────────────────────┼──────────────┼──────────────┤
│ hinotetsu3d-rs (Rust) │ 879,112 op/s │ 762,080 op/s │
├───────────────────────┼──────────────┼──────────────┤
│ hinotetsu3d (C/libuv) │ 479,496 op/s │ 428,374 op/s │
├───────────────────────┼──────────────┼──────────────┤
│ 倍率 │ 1.83x │ 1.78x │
└───────────────────────┴──────────────┴──────────────┘
┌───────────────────────┬──────────────┬──────────────┐
│ デーモン │ C++ bench │ Rust bench │
├───────────────────────┼──────────────┼──────────────┤
│ hinotetsu3d-rs (Rust) │ 162,874 op/s │ 152,957 op/s │
├───────────────────────┼──────────────┼──────────────┤
│ hinotetsu3d (C/libuv) │ 157,179 op/s │ 155,560 op/s │
├───────────────────────┼──────────────┼──────────────┤
│ 倍率 │ 1.04x │ 0.98x │
└───────────────────────┴──────────────┴──────────────┘
┌───────────────────────────┬─────────────┐
│ 比較 │ 結果 │
├───────────────────────────┼─────────────┤
│ Rust版 vs C版 (memcached) │ 約1.8倍速い │
├───────────────────────────┼─────────────┤
│ Rust版 vs 本家memcached │ 約6.7倍速い │
├───────────────────────────┼─────────────┤
│ Rust版 vs 本家Redis │ 約5.4倍速い │
└───────────────────────────┴─────────────┘
Tokio版の方がlibuv版より高速という結果になりました!
┌──────────────────────────┬─────────────────┬────────────┐
│ サーバー │ memcached proto │ Redis RESP │
├──────────────────────────┼─────────────────┼────────────┤
│ hinotetsu3d-rs (Rust) │ 837,814 │ 778,042 │
├──────────────────────────┼─────────────────┼────────────┤
│ hinotetsu3d (C/libuv) │ 487,498 │ 597,504 │
├──────────────────────────┼─────────────────┼────────────┤
│ memcached 1.6 (official) │ 117,589 │ - │
├──────────────────────────┼─────────────────┼────────────┤
│ Redis 7 (official) │ - │ 150,996 │
└──────────────────────────┴─────────────────┴────────────┘
┌─────────────────────┬─────────────────┬────────────┐
│ 比較 │ memcached proto │ Redis RESP │
├─────────────────────┼─────────────────┼────────────┤
│ Rust版 vs memcached │ 7.1x 速い │ - │
├─────────────────────┼─────────────────┼────────────┤
│ Rust版 vs Redis │ - │ 5.2x 速い │
├─────────────────────┼─────────────────┼────────────┤
│ Rust版 vs C版 │ 1.7x 速い │ 1.3x 速い │
└─────────────────────┴─────────────────┴────────────┘
┌──────────────────────┬───────────┬───────────┐
│ サーバー │ memcached │ Redis │
├──────────────────────┼───────────┼───────────┤
│ hinotetsu3d-rs │ 0.0023 ms │ 0.0033 ms │
├──────────────────────┼───────────┼───────────┤
│ hinotetsu3d (C) │ 0.0038 ms │ 0.0031 ms │
├──────────────────────┼───────────┼───────────┤
│ memcached (official) │ 0.0145 ms │ - │
├──────────────────────┼───────────┼───────────┤
│ Redis (official) │ - │ 0.0132 ms │
└──────────────────────┴───────────┴───────────┘
hinotetsu3d-rs (Rust/Tokio) が最速 - 本家の約5〜7倍の性能!
This project is licensed under the Business Source License 1.1. See the LICENSE file for details.