摘要:小草博客地址回家的路,。
小草博客地址: http://homeway.me/ =>回家的路
(Today"s all code is here http://xiaocao.u.qiniudn.com/work%2F2014-09-06-mysql-vs-cache.zip)
Tool:
Apache Benchmark And Siege (about "ab" and "siege"
model:
insert、select、update x100loop x100get
insert x200loop x200get
select x200loop x200get
update x200loop x200get
Ox01.System Environment- system MAC os Software OS X 10.9.4 (13E28) Processor 2.4 GHz Intel Core i5 Memory 8 GB 1600 MHz DDR3 250GB SSD - environment xampp 1.8.3 Apache/2.4.9 PHP Version 5.5.11 mysqlnd 5.0.11-dev - 20120503 - (mysql is empty)Ox02.Code:
cache.php
cache_path = "cache/";
$cache->cache_time = 3600;
for ($i=1; $i < 100 ; $i++) { 
    $key = md5( uniqid().time() ) ;
    $date = time();
    //insert
    $save = $cache->set_cache( $key, $data);
    //get
    $get = $cache->get_cache( $key );
    //update
    $update = $cache->set_cache( $key, $data);
}
exit();
?>
cache.class.php is sample cache class, every key create a "key.data" file, nothing special。
mysql.php
Ox03. TEST1 => insert、select、update x100 Loop x100 GET first testall ready. fire!!
result:ab -n 100 -c 10 http://127.0.0.1/phpcache/cache.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 127.0.0.1 (be patient).....done
Server Software:        Apache/2.4.9
Server Hostname:        127.0.0.1
Server Port:            80
Document Path:          /phpcache/cache.php
Document Length:        27522 bytes
Concurrency Level:      10
Time taken for tests:   3.543 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Total transferred:      2773500 bytes
HTML transferred:       2752200 bytes
Requests per second:    28.22 [#/sec] (mean)
Time per request:       354.349 [ms] (mean)
Time per request:       35.435 [ms] (mean, across all concurrent requests)
Transfer rate:          764.36 [Kbytes/sec] received
Connection Times (ms)
          min  mean[+/-sd] median   max
Connect:        0    0   1.1      0      11
Processing:   135  347 138.3    339     730
Waiting:       36  101  44.8     80     204
Total:        136  347 138.5    339     730
Percentage of the requests served within a certain time (ms)
    50%    339
    66%    420
    75%    434
    80%    473
    90%    530
    95%    583
    98%    624
    99%    730
    100%    730 (longest request)
    all 10198 records
ab -n 100 -c 10 http://127.0.0.1/phpcache/mysql.php
####result:
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 127.0.0.1 (be patient).....done
Server Software:        Apache/2.4.9
Server Hostname:        127.0.0.1
Server Port:            80
Document Path:          /phpcache/mysql.php
Document Length:        0 bytes
Concurrency Level:      10
Time taken for tests:   37.934 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Total transferred:      23200 bytes
HTML transferred:       0 bytes
Requests per second:    2.64 [#/sec] (mean)
Time per request:       3793.356 [ms] (mean)
Time per request:       379.336 [ms] (mean, across all concurrent requests)
Transfer rate:          0.60 [Kbytes/sec] received
Connection Times (ms)
          min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       0
Processing:  1229 3790 1623.9   4030    6359
Waiting:     1229 3790 1623.9   4030    6359
Total:       1230 3790 1623.9   4030    6359
Percentage of the requests served within a certain time (ms)
    50%   4030
    66%   4650
    75%   5187
    80%   5793
    90%   6293
    95%   6348
    98%   6356
    99%   6359
    100%   6359 (longest request)
all 10198 records
result:cache.php
Concurrency Level:      10
Time taken for tests:   7.518 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Total transferred:      23200 bytes
HTML transferred:       0 bytes
Requests per second:    13.30 [#/sec] (mean)
Time per request:       751.756 [ms] (mean)
Time per request:       75.176 [ms] (mean, across all concurrent requests)
Transfer rate:          3.01 [Kbytes/sec] received
Percentage of the requests served within a certain time (ms)
    50%    591
    66%    636
    75%    682
    80%    695
    90%    752
    95%    795
    98%    859
    99%    882
    100%    882 (longest request)
all 19800 records   
result:mysql.php
Concurrency Level:      10
Time taken for tests:   89.448 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Total transferred:      23200 bytes
HTML transferred:       0 bytes
Requests per second:    1.12 [#/sec] (mean)
Time per request:       8944.776 [ms] (mean)
Time per request:       894.478 [ms] (mean, across all concurrent requests)
Transfer rate:          0.25 [Kbytes/sec] received
Connection Times (ms)
          min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       0
Processing:  6474 8939 1506.3   9314   11180
Waiting:     6474 8938 1506.3   9314   11179
Total:       6474 8939 1506.2   9314   11180
Percentage of the requests served within a certain time (ms)
    50%   9314
    66%   9722
    75%  10388
    80%  10701
    90%  11058
    95%  11148
    98%  11167
    99%  11180
    100%  11180 (longest request)
all 20010 records
result:cache.php
Concurrency Level:      10
Time taken for tests:   8.563 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Total transferred:      23200 bytes
HTML transferred:       0 bytes
Requests per second:    11.68 [#/sec] (mean)
Time per request:       856.292 [ms] (mean)
Time per request:       85.629 [ms] (mean, across all concurrent requests)
Transfer rate:          2.65 [Kbytes/sec] received
Percentage of the requests served within a certain time (ms)
    50%    838
    66%    875
    75%    899
    80%    907
    90%    968
    95%   1007
    98%   1034
    99%   1034
    100%   1034 (longest request)
all 29362 records(->_-> when I get folder info, it`s a litte slow)
result:mysql.php
Concurrency Level:      10
Time taken for tests:   146.047 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Total transferred:      23200 bytes
HTML transferred:       0 bytes
Requests per second:    0.68 [#/sec] (mean)
Time per request:       14604.688 [ms] (mean)
Time per request:       1460.469 [ms] (mean, across all concurrent requests)
Transfer rate:          0.16 [Kbytes/sec] received
Percentage of the requests served within a certain time (ms)
    50%  14514
    66%  14853
    75%  15347
    80%  16788
    90%  18805
    95%  18832
    98%  18841
    99%  18843
    100%  18843 (longest request)
 all 30141 records
result:cache.php (ab -n 200 -c 10 http://127.0.0.1/phpcache/cache.php)
Concurrency Level:      10
Time taken for tests:   6.775 seconds
Complete requests:      200
Failed requests:        0
Write errors:           0
Total transferred:      46400 bytes
HTML transferred:       0 bytes
Requests per second:    29.52 [#/sec] (mean)
Time per request:       338.728 [ms] (mean)
Time per request:       33.873 [ms] (mean, across all concurrent requests)
Transfer rate:          6.69 [Kbytes/sec] received
Connection Times (ms)
          min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:    87  335  96.7    357     530
Waiting:       87  335  96.4    355     530
Total:         87  335  96.7    357     531
Percentage of the requests served within a certain time (ms)
    50%    357
    66%    385
    75%    401
    80%    409
    90%    436
    95%    456
    98%    478
    99%    523
    100%    531 (longest request)
mysql.php (ab -n 200 -c 10 http://127.0.0.1/phpcache/mysql.php)
Concurrency Level:      10
Time taken for tests:   1.179 seconds
Complete requests:      200
Failed requests:        0
Write errors:           0
Total transferred:      46400 bytes
HTML transferred:       0 bytes 
Requests per second:    169.57 [#/sec] (mean)
Time per request:       58.972 [ms] (mean)
Time per request:       5.897 [ms] (mean, across all concurrent requests)
Transfer rate:          38.42 [Kbytes/sec] received
Connection Times (ms)
          min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:    27   58  36.7     42     226
Waiting:       27   58  36.7     42     226
Total:         28   58  36.7     42     226
Percentage of the requests served within a certain time (ms)
    50%     42
    66%     55
    75%     63
    80%     72
    90%    116
    95%    141
    98%    173
    99%    208
    100%    226 (longest request)
result:cache.php
Concurrency Level:      10
Time taken for tests:   0.201 seconds
Complete requests:      200
Failed requests:        0
Write errors:           0
Total transferred:      46400 bytes
HTML transferred:       0 bytes
Requests per second:    993.31 [#/sec] (mean)
Time per request:       10.067 [ms] (mean)
Time per request:       1.007 [ms] (mean, across all concurrent requests)
Transfer rate:          225.05 [Kbytes/sec] received
Connection Times (ms)
          min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:     4   10   1.8     10      14
Waiting:        4   10   1.8     10      14
Total:          4   10   1.8     10      14
Percentage of the requests served within a certain time (ms)
    50%     10
    66%     11
    75%     11
    80%     11
    90%     12
    95%     13
    98%     14
    99%     14
    100%     14 (longest request)
so quickly!!
result:mysql.php
Concurrency Level:      10
Time taken for tests:   70.006 seconds
Complete requests:      200
Failed requests:        0
Write errors:           0
Total transferred:      46400 bytes
HTML transferred:       0 bytes
Requests per second:    2.86 [#/sec] (mean)
Time per request:       3500.306 [ms] (mean)
Time per request:       350.031 [ms] (mean, across all concurrent requests)
Transfer rate:          0.65 [Kbytes/sec] received
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       0
Processing:  3000 3492 230.4   3438    4047
Waiting:     3000 3491 230.4   3438    4047
Total:       3000 3492 230.4   3438    4047
Percentage of the requests served within a certain time (ms)
    50%   3438
    66%   3628
    75%   3679
    80%   3701
    90%   3804
    95%   3898
    98%   4005
    99%   4033
    100%   4047 (longest request)
so slow!!
The results are very clear, using cache to search data is qulcikly than mysql select a lot. So use cache to save some data reselected many times will be more quickly so much.
result:cache.php
Concurrency Level:      10
Time taken for tests:   0.973 seconds
Complete requests:      200
Failed requests:        0
Write errors:           0
Total transferred:      46400 bytes
HTML transferred:       0 bytes
Requests per second:    205.51 [#/sec] (mean)
Time per request:       48.660 [ms] (mean)
Time per request:       4.866 [ms] (mean, across all concurrent requests)
Transfer rate:          46.56 [Kbytes/sec] received
Connection Times (ms)
          min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:     9   47  54.9     23     267
Waiting:        9   47  54.9     23     267
Total:          9   47  54.9     23     267
Percentage of the requests served within a certain time (ms)
    50%     23
    66%     42
    75%     53
    80%     59
    90%    142
    95%    175
    98%    255
    99%    265
    100%    267 (longest request)
result:mysql.php
Concurrency Level:      10
Time taken for tests:   1.411 seconds
Complete requests:      200
Failed requests:        0
Write errors:           0
Total transferred:      46400 bytes
HTML transferred:       0 bytes
Requests per second:    141.78 [#/sec] (mean)
Time per request:       70.532 [ms] (mean)
Time per request:       7.053 [ms] (mean, across all concurrent requests)
Transfer rate:          32.12 [Kbytes/sec] received
Connection Times (ms)
          min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       0
Processing:    39   70   7.9     68      97
Waiting:       39   70   7.9     68      97
Total:         39   70   8.0     68      97
Percentage of the requests served within a certain time (ms)
    50%     68
    66%     70
    75%     71
    80%     73
    90%     82
    95%     90
    98%     93
    99%     94
    100%     97 (longest request)
From it, so clear. Because when mysql update a data, it must seach id in all data, so it include select.
As we know, speed is always the most important element in developing a website especially for those high traffic database driven website. You can try to turn on query cache to speed up query.
To speed up query, enable the MySQL query cache, before that you need to set few variables in mysql configuration file (usually is my.cnf or my.ini)
first, set query_cache_type to 1. (There are 3 possible settings: 0 (disable / off), 1 (enable / on) and 2 (on demand).
query-cache-type = 1
second, set query_cache_size to your expected size. I’d prefer to set it at 20MB.
query-cache-size = 20M
So use cache in right time is a batter way to speed your website.
some useful link to make your mysql qulickly.
http://coolshell.cn/articles/1846.html
http://soft.chinabyte.com/database/55/12710055.shtml
http://planetcassandra.org/nosql-performance-benchmarks/
-By xiaocao
2014-09-05 03:41:13
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://m.hztianpu.com/yun/20826.html
摘要:第一階段基礎(chǔ)階段基礎(chǔ)程序員重點(diǎn)把搞熟練核心是安裝配置基本操作目標(biāo)能夠完成基本的系統(tǒng)安裝,簡(jiǎn)單配置維護(hù)能夠做基本的簡(jiǎn)單系統(tǒng)的開(kāi)發(fā)能夠在中型系統(tǒng)中支持某個(gè)功能模塊的開(kāi)發(fā)。本項(xiàng)不做重點(diǎn)學(xué)習(xí),除非對(duì)前端有興趣。 第一階段:基礎(chǔ)階段(基礎(chǔ)PHP程序員) 重點(diǎn):把LNMP搞熟練(核心是安裝配置基本操作) 目標(biāo):能夠完成基本的LNMP系統(tǒng)安裝,簡(jiǎn)單配置維護(hù);能夠做基本的簡(jiǎn)單系統(tǒng)的PHP開(kāi)發(fā);能夠在P...
摘要:本文作為針對(duì)外圍資源性的能分析,比較簡(jiǎn)單地設(shè)計(jì)了一些實(shí)驗(yàn)場(chǎng)景,看到了外部資源,包括中間件和數(shù)據(jù)庫(kù)資源給程序性能帶來(lái)的影響。有關(guān)影響程序性能的后端外圍資源就到這里,在下一篇中,我們將分析前端或者前后端結(jié)合給頁(yè)面延時(shí)帶來(lái)的影響。 暫且不討論「PHP 是不是最好的編程語(yǔ)言」,本文我們將分別分析一下在 PHP 程序的后端外圍資源和前端外圍資源,它們對(duì)整個(gè) PHP Web 應(yīng)用體驗(yàn)的影響,這往往...
摘要:性能分析與實(shí)驗(yàn)性能的宏觀分析在上一篇文章中,我們從是解釋性語(yǔ)言動(dòng)態(tài)語(yǔ)言和底層實(shí)現(xiàn)等三個(gè)方面,探討了性能的問(wèn)題。在開(kāi)始分析之前,我們得掌握一些與性能分析相關(guān)的函數(shù)。二性能分析則下面我們根據(jù)小程序來(lái)驗(yàn)證一些常見(jiàn)的性能差別。 【編者按】此前,閱讀過(guò)了很多關(guān)于 PHP 性能分析的文章,不過(guò)寫的都是一條一條的規(guī)則,而且,這些規(guī)則并沒(méi)有上下文,也沒(méi)有明確的實(shí)驗(yàn)來(lái)體現(xiàn)出這些規(guī)則的優(yōu)勢(shì),同時(shí)討論的也側(cè)...
摘要:上一篇文章里,我們介紹了如何基于擴(kuò)展來(lái)分析性能,并記錄到日志里,最后使用擴(kuò)展自帶的在里展示出來(lái)。本次測(cè)試中,實(shí)際使用了擴(kuò)展切換為擴(kuò)展后里看不到數(shù)據(jù),原因未知。雖然來(lái)自但已經(jīng)很久不更新,官方源已經(jīng)顯示此包已廢棄,不再維護(hù)。 上一篇文章里,我們介紹了如何基于xhprof擴(kuò)展來(lái)分析PHP性能,并記錄到日志里,最后使用xhprof擴(kuò)展自帶的UI在web里展示出來(lái)。本篇文章將講述2個(gè)知識(shí)點(diǎn): ...
摘要:本文就改變性能分析的角度,并通過(guò)實(shí)例來(lái)分析出的性能方面需要注意和改進(jìn)的點(diǎn)。如下是作為解釋性語(yǔ)言的執(zhí)行過(guò)程。這里分別啟用和做實(shí)驗(yàn)。 編者按】此前,閱讀過(guò)了很多關(guān)于 PHP 性能分析的文章,不過(guò)寫的都是一條一條的規(guī)則,而且,這些規(guī)則并沒(méi)有上下文,也沒(méi)有明確的實(shí)驗(yàn)來(lái)體現(xiàn)出這些規(guī)則的優(yōu)勢(shì),同時(shí)討論的也側(cè)重于一些語(yǔ)法要點(diǎn)。本文就改變 PHP 性能分析的角度,并通過(guò)實(shí)例來(lái)分析出 PHP 的性能方面...
摘要:本文就改變性能分析的角度,并通過(guò)實(shí)例來(lái)分析出的性能方面需要注意和改進(jìn)的點(diǎn)。如下是作為解釋性語(yǔ)言的執(zhí)行過(guò)程。這里分別啟用和做實(shí)驗(yàn)。 【編者按】此前,閱讀過(guò)了很多關(guān)于 PHP 性能分析的文章,不過(guò)寫的都是一條一條的規(guī)則,而且,這些規(guī)則并沒(méi)有上下文,也沒(méi)有明確的實(shí)驗(yàn)來(lái)體現(xiàn)出這些規(guī)則的優(yōu)勢(shì),同時(shí)討論的也側(cè)重于一些語(yǔ)法要點(diǎn)。本文就改變 PHP 性能分析的角度,并通過(guò)實(shí)例來(lái)分析出 PHP 的性能方...
 
                    閱讀 1532·2021-11-17 09:33
閱讀 3118·2021-10-13 09:39
閱讀 2791·2021-10-09 10:01
閱讀 2532·2021-09-29 09:35
閱讀 4050·2021-09-26 10:01
閱讀 3593·2019-08-26 18:37
閱讀 3243·2019-08-26 13:46
閱讀 1972·2019-08-26 13:39