ecshop数据库读写分离并发测试

linux

17-1-23 16:20:56

虚拟机linux服务器5台

mysql 数据库三台(一主二从,配置1核1G)

web 服务器一台  (4核 4G)

atlas 服务器一台(1核1G)


web服务器调用atlas,后面mysql主从复制


程序安装是的 ecshop2.7.4 

在程序里index.php  增加  更新goods表和插入goods 表的sql


$sql = "update  ecs_goods set  click_count= click_count+1 where goods_id=1 ";
$db->query($sql);
$sql = "insert into ecs_goods (goods_name) values ('123三三四') ";
$res = $db->query($sql);


因为ecshop 自身有缓存功能 先取消模板缓存 正常读取数据

首页会调用的sql如下


SELECT userid, adminid, user_name, user_rank, discount, email, data, expiry FROM `ec`.`ecs_sessions` WHERE sesskey = '22182017f976f7e49957af2b6bc38e65'
SELECT * FROM `ec`.`ecs_nav` WHERE ifshow = '1' ORDER BY type, vieworder
SELECT count(*) FROM `ec`.`ecs_category` WHERE parent_id = '0' AND is_show = 1 
SELECT cat_id,cat_name ,parent_id,is_show FROM `ec`.`ecs_category`WHERE parent_id = '0' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC
SELECT count(*) FROM `ec`.`ecs_category` WHERE parent_id = '1' AND is_show = 1 
SELECT cat_id, cat_name, parent_id, is_show FROM `ec`.`ecs_category`WHERE parent_id = '1' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC
SELECT count(*) FROM `ec`.`ecs_category` WHERE parent_id = '2' AND is_show = 1 
SELECT count(*) FROM `ec`.`ecs_category` WHERE parent_id = '3' AND is_show = 1 
SELECT count(*) FROM `ec`.`ecs_category` WHERE parent_id = '4' AND is_show = 1 
SELECT count(*) FROM `ec`.`ecs_category` WHERE parent_id = '5' AND is_show = 1 
SELECT count(*) FROM `ec`.`ecs_category` WHERE parent_id = '6' AND is_show = 1 
SELECT cat_id, cat_name, parent_id, is_show FROM `ec`.`ecs_category`WHERE parent_id = '6' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC
SELECT count(*) FROM `ec`.`ecs_category` WHERE parent_id = '7' AND is_show = 1 
SELECT count(*) FROM `ec`.`ecs_category` WHERE parent_id = '8' AND is_show = 1 
SELECT count(*) FROM `ec`.`ecs_category` WHERE parent_id = '9' AND is_show = 1 
SELECT count(*) FROM `ec`.`ecs_category` WHERE parent_id = '11' AND is_show = 1 
SELECT count(*) FROM `ec`.`ecs_category` WHERE parent_id = '12' AND is_show = 1 
SELECT cat_id, cat_name, parent_id, is_show FROM `ec`.`ecs_category`WHERE parent_id = '12' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC
SELECT count(*) FROM `ec`.`ecs_category` WHERE parent_id = '13' AND is_show = 1 
SELECT count(*) FROM `ec`.`ecs_category` WHERE parent_id = '14' AND is_show = 1 
SELECT count(*) FROM `ec`.`ecs_category` WHERE parent_id = '15' AND is_show = 1 
SELECT c.cat_id, c.cat_name, c.sort_order, a.article_id, a.title, a.file_url, a.open_type FROM `ec`.`ecs_article` AS a LEFT JOIN `ec`.`ecs_article_cat` AS c ON a.cat_id = c.cat_id WHERE c.cat_type = 5 AND a.is_open = 1 ORDER BY c.sort_order ASC, a.article_id
SELECT goods_id FROM `ec`.`ecs_goods_cat` AS g WHERE g.cat_id IN ('1','4','5','2','3','12','14','15','13','6','11','7','8','9') 
SELECT g.goods_id, g.goods_name, g.shop_price, g.goods_thumb, SUM(og.goods_number) as goods_number FROM `ec`.`ecs_goods` AS g, `ec`.`ecs_order_info` AS o, `ec`.`ecs_order_goods` AS og WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND (g.cat_id IN ('1','4','5','2','3','12','14','15','13','6','11','7','8','9') OR g.goods_id IN ('8','16') ) AND g.goods_number > 0 AND og.order_id = o.order_id AND og.goods_id = g.goods_id AND (o.order_status = '1' OR o.order_status = '5') AND (o.pay_status = '2' OR o.pay_status = '1') AND (o.shipping_status = '1' OR o.shipping_status = '2') GROUP BY g.goods_id ORDER BY goods_number DESC, g.goods_id DESC LIMIT 10
SELECT library, number FROM `ec`.`ecs_template` WHERE theme = 'default' AND filename = 'index' AND remarks='' 
SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, IFNULL(mp.user_price, g.shop_price * '1') AS shop_price, promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, g.goods_img, RAND() AS rnd FROM `ec`.`ecs_goods` AS g LEFT JOIN `ec`.`ecs_member_price` AS mp ON mp.goods_id = g.goods_id AND mp.user_rank = '0' WHERE g.goods_id IN ('9','1','8','19','20','22','23','24','32','12','17','27','13','14') ORDER BY g.sort_order, g.last_update DESC
SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, IFNULL(mp.user_price, g.shop_price * '1') AS shop_price, promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, b.brand_name, g.is_best, g.is_new, g.is_hot, g.is_promote, RAND() AS rnd FROM `ec`.`ecs_goods` AS g LEFT JOIN `ec`.`ecs_brand` AS b ON b.brand_id = g.brand_id LEFT JOIN `ec`.`ecs_member_price` AS mp ON mp.goods_id = g.goods_id AND mp.user_rank = '0' WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND g.is_promote = 1 AND promote_start_date <= '1485102098' AND promote_end_date >= '1485102098' ORDER BY g.sort_order, g.last_update DESC LIMIT 4 
SELECT b.brand_id, b.brand_name, b.brand_logo, b.brand_desc, COUNT(*) AS goods_num, IF(b.brand_logo > '', '1', '0') AS tag FROM `ec`.`ecs_brand`AS b, `ec`.`ecs_goods` AS g WHERE g.brand_id = b.brand_id AND is_show = 1 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 GROUP BY b.brand_id HAVING goods_num > 0 ORDER BY tag DESC, b.sort_order ASC LIMIT 11 
SELECT act_id, act_name, act_type, start_time, end_time FROM `ec`.`ecs_goods_activity` WHERE is_finished=0 AND start_time <= '1485102098' AND end_time >= '1485102098'
SELECT act_id, act_range, act_range_ext, act_name, start_time, end_time FROM `ec`.`ecs_favourable_activity` WHERE start_time <= '1485102098' AND end_time >= '1485102098'
SELECT o.order_sn, o.invoice_no, s.shipping_code FROM `ec`.`ecs_order_info` AS o LEFT JOIN `ec`.`ecs_shipping` AS s ON s.shipping_id = o.shipping_id WHERE invoice_no > '' AND shipping_status = 1 ORDER BY shipping_time DESC LIMIT 10
SELECT a.article_id, a.title, ac.cat_name, a.add_time, a.file_url, a.open_type, ac.cat_id, ac.cat_name FROM `ec`.`ecs_article` AS a, `ec`.`ecs_article_cat` AS ac WHERE a.is_open = 1 AND a.cat_id = ac.cat_id AND ac.cat_type = 1 ORDER BY a.article_type DESC, a.add_time DESC LIMIT 8
SELECT gb.act_id AS group_buy_id, gb.goods_id, gb.ext_info, gb.goods_name, g.goods_thumb, g.goods_img FROM `ec`.`ecs_goods_activity` AS gb, `ec`.`ecs_goods` AS g WHERE gb.act_type = '1' AND g.goods_id = gb.goods_id AND gb.start_time <= '1485102098' AND gb.end_time >= '1485102098' AND g.is_delete = 0 ORDER BY gb.act_id DESC LIMIT 3
SELECT a.act_id, a.goods_id, a.goods_name, a.ext_info, g.goods_thumb FROM `ec`.`ecs_goods_activity` AS a,`ec`.`ecs_goods` AS g WHERE a.goods_id = g.goods_id AND a.act_type = '2' AND a.is_finished = 0 AND a.start_time <= '1485102098' AND a.end_time >= '1485102098' AND g.is_delete = 0 ORDER BY a.start_time DESC LIMIT 3
SELECT link_logo, link_name, link_url FROM `ec`.`ecs_friend_link` ORDER BY show_order
SELECT c.cat_id, c.cat_name, cr.recommend_type FROM `ec`.`ecs_cat_recommend` AS cr INNER JOIN `ec`.`ecs_category` AS c ON cr.cat_id=c.cat_id
SELECT id, number, type FROM `ec`.`ecs_template` WHERE filename = 'index' AND type > 0 AND remarks ='' AND theme='default'
update ecs_goods set click_count= click_count+1 where goods_id=1 
insert into ecs_goods (goods_name) values ('123三三四') 
SELECT SUM(goods_number) AS number, SUM(goods_price * goods_number) AS amount FROM `ec`.`ecs_cart` WHERE session_id = '22182017f976f7e49957af2b6bc38e65' AND rec_type = '0'
SELECT vote_id, vote_name, can_multi, vote_count, RAND() AS rnd FROM `ec`.`ecs_vote` WHERE start_time <= '1485102098' AND end_time >= '1485102098' ORDER BY rnd LIMIT 1
SELECT COUNT(*) FROM `ec`.`ecs_sessions`

UPDATE `ec`.`ecs_sessions` SET expiry = '1485130994', ip = '192.168.10.166', userid = '0', adminid = '0', user_name='0', user_rank='0', discount='1', email='0', data = 'a:1:{s:10:\"login_fail\";i:0;}' WHERE sesskey = '22182017f976f7e49957af2b6bc38e65' LIMIT 1
DELETE FROM `ec`.`ecs_sessions_data` WHERE expiry < 1485129194
DELETE FROM `ec`.`ecs_sessions` WHERE expiry < 1485129194



ab -c 100 -n 1000 http://192.168.10.165/index.php

This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.10.165 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        Apache/2.2.15
Server Hostname:        192.168.10.165
Server Port:            80

Document Path:          /index.php
Document Length:        485 bytes

Concurrency Level:      100
Time taken for tests:   5.262 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      678000 bytes
HTML transferred:       485000 bytes
Requests per second:    190.04 [#/sec] (mean)
Time per request:       526.217 [ms] (mean)
Time per request:       5.262 [ms] (mean, across all concurrent requests)
Transfer rate:          125.82 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   2.8      2      35
Processing:    98  505 102.1    515     836
Waiting:       98  500 102.1    511     836
Total:         98  507 102.4    519     838

Percentage of the requests served within a certain time (ms)
  50%    519
  66%    551
  75%    572
  80%    584
  90%    618
  95%    652
  98%    682
  99%    711
 100%    838 (longest request)


ab -c 150 -n 1000 http://192.168.10.165/index.php
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.10.165 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        Apache/2.2.15
Server Hostname:        192.168.10.165
Server Port:            80

Document Path:          /index.php
Document Length:        485 bytes

Concurrency Level:      150
Time taken for tests:   8.400 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      678000 bytes
HTML transferred:       485000 bytes
Requests per second:    119.05 [#/sec] (mean)
Time per request:       1259.935 [ms] (mean)
Time per request:       8.400 [ms] (mean, across all concurrent requests)
Transfer rate:          78.83 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    6  95.0      2    3004
Processing:   155 1229 951.0    852    3765
Waiting:      151 1172 931.3    835    3761
Total:        155 1235 953.7    855    3767

Percentage of the requests served within a certain time (ms)
  50%    855
  66%    972
  75%   1173
  80%   1623
  90%   3309
  95%   3454
  98%   3539
  99%   3630
 100%   3767 (longest request)



ab -c 200 -n 1000 http://192.168.10.165/index.php
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.10.165 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        Apache/2.2.15
Server Hostname:        192.168.10.165
Server Port:            80

Document Path:          /index.php
Document Length:        485 bytes

Concurrency Level:      200
Time taken for tests:   10.321 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      678000 bytes
HTML transferred:       485000 bytes
Requests per second:    96.89 [#/sec] (mean)
Time per request:       2064.162 [ms] (mean)
Time per request:       10.321 [ms] (mean, across all concurrent requests)
Transfer rate:          64.15 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    8 134.2      1    3004
Processing:    56 1949 1509.1   1278    6314
Waiting:       56 1888 1493.7   1269    6312
Total:         60 1957 1515.0   1288    6315

Percentage of the requests served within a certain time (ms)
  50%   1288
  66%   3248
  75%   3288
  80%   3292
  90%   3313
  95%   6265
  98%   6305
  99%   6310
 100%   6315 (longest request)


然后开启模板缓存

仅会执行如下sql

SELECT userid, adminid, user_name, user_rank, discount, email, data, expiry FROM `ec`.`ecs_sessions` WHERE sesskey = '22182017f976f7e49957af2b6bc38e65'
update ecs_goods set click_count= click_count+1 where goods_id=1 
insert into ecs_goods (goods_name) values ('123三三四') 
SELECT SUM(goods_number) AS number, SUM(goods_price * goods_number) AS amount FROM `ec`.`ecs_cart` WHERE session_id = '22182017f976f7e49957af2b6bc38e65' AND rec_type = '0'
SELECT vote_id, vote_name, can_multi, vote_count, RAND() AS rnd FROM `ec`.`ecs_vote` WHERE start_time <= '1485102321' AND end_time >= '1485102321' ORDER BY rnd LIMIT 1
SELECT COUNT(*) FROM `ec`.`ecs_sessions`

UPDATE `ec`.`ecs_sessions` SET expiry = '1485131121', ip = '192.168.10.166', userid = '0', adminid = '0', user_name='0', user_rank='0', discount='1', email='0', data = 'a:1:{s:10:\"login_fail\";i:0;}' WHERE sesskey = '22182017f976f7e49957af2b6bc38e65' LIMIT 1



ab -c 100 -n 1000 http://192.168.10.165/index.php
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.10.165 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        Apache/2.2.15
Server Hostname:        192.168.10.165
Server Port:            80

Document Path:          /index.php
Document Length:        485 bytes

Concurrency Level:      100
Time taken for tests:   5.690 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      678000 bytes
HTML transferred:       485000 bytes
Requests per second:    175.74 [#/sec] (mean)
Time per request:       569.022 [ms] (mean)
Time per request:       5.690 [ms] (mean, across all concurrent requests)
Transfer rate:          116.36 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    3   4.1      2      41
Processing:    66  542 350.3    442    1575
Waiting:       63  505 352.3    406    1468
Total:         67  544 350.1    446    1575

Percentage of the requests served within a certain time (ms)
  50%    446
  66%    518
  75%    626
  80%    696
  90%   1199
  95%   1321
  98%   1515
  99%   1530
 100%   1575 (longest request)

ab -c 150 -n 1000 http://192.168.10.165/index.php
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.10.165 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        Apache/2.2.15
Server Hostname:        192.168.10.165
Server Port:            80

Document Path:          /index.php
Document Length:        485 bytes

Concurrency Level:      150
Time taken for tests:   5.804 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      678000 bytes
HTML transferred:       485000 bytes
Requests per second:    172.29 [#/sec] (mean)
Time per request:       870.636 [ms] (mean)
Time per request:       5.804 [ms] (mean, across all concurrent requests)
Transfer rate:          114.07 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    3   5.4      2      71
Processing:    65  743 322.2    697    3792
Waiting:       65  704 328.7    647    3782
Total:         71  746 322.1    699    3793

Percentage of the requests served within a certain time (ms)
  50%    699
  66%    777
  75%    831
  80%    876
  90%   1165
  95%   1381
  98%   1652
  99%   1804
 100%   3793 (longest request)



ab -c 200 -n 1000 http://192.168.10.165/index.php
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.10.165 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        Apache/2.2.15
Server Hostname:        192.168.10.165
Server Port:            80

Document Path:          /index.php
Document Length:        485 bytes

Concurrency Level:      200
Time taken for tests:   5.080 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      678000 bytes
HTML transferred:       485000 bytes
Requests per second:    196.86 [#/sec] (mean)
Time per request:       1015.929 [ms] (mean)
Time per request:       5.080 [ms] (mean, across all concurrent requests)
Transfer rate:          130.35 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   3.2      2      37
Processing:   202  971 503.8    755    2563
Waiting:      196  958 507.6    745    2562
Total:        202  973 503.7    760    2564

Percentage of the requests served within a certain time (ms)
  50%    760
  66%    908
  75%   1075
  80%   1638
  90%   1839
  95%   1977
  98%   2189
  99%   2257
 100%   2564 (longest request)


未开缓存

从数据库20%-50%cpu消耗

主数据库20%cpu消耗

web服务器50%-80%cpu消耗

atlas服务器20%cpu消耗


可见开启缓存的重要性 150并发级别的数据库配置

如果配合xcache memcached lvs  性能会大大提层

服务器硬件性能 直接影响效率 1核1G 的web 和4核4G的 根本无法比。。