所有数据和结论,仅仅是基于个人的知识能力范围内产生的..,仅代表个人观点 如果错误.. 喷我就对了
测试并得出结论 mysql 数据是否能解决高并发问题?
ab -c 100 -n 1000 http://127.0.0.1:8001/
id | key | count |
---|---|---|
1 | key | 10 |
设置count=10个 并发 100 请求1000 每次只要count有值就 -1 直到0
select * from `test` where `id` = 1 limit 1
update `test` set `count` = `count` - 1 where `id` = 1
count值 | Time per request | Requests per second |
---|---|---|
-7 | 379.150 | 263.75 |
结论: 失败 出现了超减
begin;
select * from `test` where `id` = 1 limit 1
update `test` set `count` = `count` - 1 where `id` = 1
commit;
count值 | Time per request | Requests per second |
---|---|---|
-5 | 389.550 | 256.71 |
结论: 失败 出现了超减
select * from `test` where `id` = 1 limit 1 for update
update `test` set `count` = `count` - 1 where `id` = 1
count值 | Time per request | Requests per second |
---|---|---|
-3 | 372.377 | 268.55 |
结论: 失败 出现了超减
begin;
select * from `test` where `id` = 1 limit 1 for update
update `test` set `count` = `count` - 1 where `id` = 1
commit;
count值 | Time per request | Requests per second |
---|---|---|
0 | 391.694 | 255.30 |
结论: 成功
单纯靠事务,并不能在高并发场景下保证数据的正确性.. 从而也达不到事务的要求