vps内存是多少?
一加ace2Pro(灰|24+1024)
@老虎会游泳,我写了一些脚本,利用去年隔壁 v2 论坛千万帖子数据,在机械硬盘上,测试了 SQLite
并发能力:
(读写请求,用两个 wrk
同时进行。末尾附上运行过程)
700 写请求/秒:新增用户信息/帖子数据/回帖数据 + 全文索引 (新增帖子/回帖时。效果) + 计算该帖总回复数(新增帖子/回帖时)。
4000 读请求/秒:读取某个帖子及其所有回帖的所有数据,以 json 形式响应。
断电可能丢失少量数据
操作系统崩溃/断电时,可能会损失少量数据。但可以维持原子性、一致性。
落盘几千个事务时,会卡 0.5 秒
几千个事务后,会在一个事务强制将预写日志,刷新回数据库。(否则日志无限增长,读取速度下降)
但该事务需要等待:
因此:
改进方向:
写事务串行,需最快速度完成
本质上,SQLite 的并行写事务数仍是 1,因此每个写请求都需要尽可能快处理,否则后续写请求都会被拖慢,降低 RPS。
改进方向:
FastAPI 服务端,需要读写请求分离
一个 worker 专心处理写请求,其他 workers 处理读请求。
原因:
写请求
$ wrk -s test.lua --latency -t1 -d30 -c100 http://127.0.0.1:8081 -- write
[22:24:42] INFO 启动写入脚本
Running 30s test @ http://127.0.0.1:8081
1 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 221.29ms 237.46ms 1.98s 79.97%
Req/Sec 1.25k 684.68 2.37k 51.41%
Latency Distribution
50% 66.50ms
75% 382.95ms
90% 622.55ms
99% 806.51ms
20453 requests in 30.06s, 4.90MB read
Socket errors: connect 0, read 0, write 0, timeout 5
Requests/sec: 680.47
Transfer/sec: 167.06KB
读请求
$ wrk -s test.lua --latency -t1 -d30 -c100 http://127.0.0.1:8080
[22:24:43] INFO 启动读取脚本
Running 30s test @ http://127.0.0.1:8080
1 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 22.74ms 12.94ms 369.21ms 98.69%
Req/Sec 4.24k 429.51 4.64k 90.88%
Latency Distribution
50% 21.47ms
75% 22.67ms
90% 24.43ms
99% 70.82ms
126055 requests in 30.03s, 193.80MB read
Requests/sec: 4197.77
Transfer/sec: 6.45MB
@老虎会游泳,我又用 CM311-1A 电视盒子,测试了千万数据论坛在 SQLite
上的并发能力:
(用两个 wrk
,同时进行读写请求。即,➀➁ 或 ➀➂)
CPU:晶晨 S905L3A
内存:2 GB
功耗:2 ~ 3 W
系统:Armbian 24.8.0 noble 6.1.100
服务端:Python 3.12,FastAPI,四进程(4 workers),压测时 200 MB 内存
测试时服务端数据库
存储
获取整帖请求
$ wrk -s test.lua --latency -t1 -d30 -c100 http://192.168.1.8:8080
[00:03:43] INFO 启动读取整帖脚本
Running 30s test @ http://192.168.1.8:8080
1 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 85.74ms 32.75ms 874.56ms 98.14%
Req/Sec 1.13k 141.22 1.52k 77.66%
Latency Distribution
50% 82.90ms
75% 92.17ms
90% 97.29ms
99% 116.91ms
33742 requests in 30.01s, 81.59MB read
Requests/sec: 1124.43
Transfer/sec: 2.72MB
注册用户请求
$ wrk -s test.lua --latency -t1 -d30 -c100 http://192.168.1.8:8081 -- user
[00:03:42] INFO 启动注册用户脚本
Running 30s test @ http://192.168.1.8:8081
1 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 309.43ms 124.90ms 1.94s 84.28%
Req/Sec 309.40 100.59 524.00 71.36%
Latency Distribution
50% 311.17ms
75% 330.83ms
90% 354.10ms
99% 839.12ms
8531 requests in 30.04s, 1.61MB read
Socket errors: connect 0, read 0, write 0, timeout 50
Requests/sec: 284.03
Transfer/sec: 55.00KB
发帖回帖请求
$ wrk -s test.lua --latency -t1 -d30 -c100 http://192.168.1.8:8081 -- post
[00:22:44] INFO 启动发帖回帖脚本
Running 30s test @ http://192.168.1.8:8081
1 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 411.50ms 194.28ms 1.94s 81.43%
Req/Sec 228.08 73.82 490.00 77.99%
Latency Distribution
50% 400.31ms
75% 433.54ms
90% 540.13ms
99% 1.03s
6127 requests in 30.01s, 1.47MB read
Socket errors: connect 0, read 0, write 0, timeout 60
Requests/sec: 204.16
Transfer/sec: 50.15KB
沙发