apache2-utils: ab 2.3
sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
apt-get update
apt-get -y install postgresql-15 apache2-utils build-essential
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
git clone https://github.com/liuquanhao/axum-todo.git
cd axum-todo
cargo build --release
su - postgres
psql
postgres=# CREATE USER todouser WITH ENCRYPTED PASSWORD 'todopassword';
postgres=# CREATE DATABASE todos;
postgres=# GRANT ALL PRIVILEGES ON DATABASE todos to todouser;
postgres=# \c todos;
postgres=# CREATE TABLE todos (id UUID PRIMARY KEY NOT NULL, text VARCHAR(255) NOT NULL DEFAULT '', completed BOOLEAN NOT NULL DEFAULT false);
postgres=# GRANT ALL ON todos TO todouser;
ulimit -n
102400
cat /etc/sysctl.conf
net.ipv4.ip_local_port_range=1024 65535
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_timestamps = 1
cat /etc/postgresql/15/main/postgresql.conf
# 修改关键配置
shared_buffers = 256MB
max_connections = 2000
ssl = false
# 具体看sql,简单sql 4MB也够用
work_mem = 64MB
maintenance_work_mem = 256MB
wal_level = minimal
synchronous_commit = off
max_wal_senders = 0
# ssd用2.0或1.0
random_page_cost = 2.0
# 服务器可用内存
effective_cache_size = 1GB
POSTGRESQL_URL="postgres://todouser:[email protected]:5432/todos" ./target/release/axum-todo
cat create_todo.json
{"text":"todo1"}
ab -n10000 -c1000 "http://127.0.0.1:3000/helloworld/"
ab -n10000 -c1000 -p ./create_todo.json -T "application/json" "http://127.0.0.1:3000/todos/"
ab -n10000 -c1000 "http://127.0.0.1:3000/todos/"
ab -n10000 -c1000 "http://127.0.0.1:3000/todos/?page=1&per_page=10"
ab -n10000 -c1000 "http://127.0.0.1:3000/todos/{某个todo id}"
cat create_todo.json
{"text":"todo1"}
curl -d "@./create_todo.json" -H "Content-Type:application/json" "http://127.0.0.1:3000/todos.json"
curl "http://127.0.0.1:3000/todos/"
curl "http://127.0.0.1:3000/todos/?page=1&per_page=10"
curl "http://127.0.0.1:3000/todos/{某个todo id}"
GET: /todos/
GET: /todos/:id
POST: /todos/
header: content-type:application/json
body: {"text": "todo test"}
PUT: /todos/:id
header: content-type:application/json
body: {"text": "todo test2"}
DELETE: /todos/:id