国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

代碼性能-php(二)

dance / 1755人閱讀

摘要:小草博客地址回家的路,。

  

小草博客地址: http://homeway.me/ =>回家的路

The artile is about php cache and mysql speed.

(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


  

all ready. fire!!

Ox03. TEST1 => insert、select、update x100 Loop x100 GET first test
  

ab -n 100 -c 10 http://127.0.0.1/phpcache/cache.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/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




second test(Without clean created file)
  

cache.php

result:
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   
  

mysql.php

result:
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




third test(Without clean created file)
  

cache.php

result:
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)
  

mysql.php

result:
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




Ox04. TEST2 => insert x100 Loop x200 GET
  

cache.php (ab -n 200 -c 10 http://127.0.0.1/phpcache/cache.php)

result:
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)
=> From the result, we can see that, insert data into msyql or writer into disk is quickly. And mysql is more quick than disk. Than we can find a way to save time, save cache in a file not create a file for each data.




Ox04. TEST3 => select x100 Loop x200 GET(select a does not existed data)
  

cache.php

result:
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!!
  

mysql.php

result:
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.




Ox05. TEST4 => update x100 Loop x200 GET
  

cache.php

result:
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)
  

mysql.php

result:
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.




Ox06.Find a solution

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

文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。

轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/20826.html

相關文章

  • PHP程序員學習路線

    摘要:第一階段基礎階段基礎程序員重點把搞熟練核心是安裝配置基本操作目標能夠完成基本的系統安裝,簡單配置維護能夠做基本的簡單系統的開發能夠在中型系統中支持某個功能模塊的開發。本項不做重點學習,除非對前端有興趣。 第一階段:基礎階段(基礎PHP程序員) 重點:把LNMP搞熟練(核心是安裝配置基本操作) 目標:能夠完成基本的LNMP系統安裝,簡單配置維護;能夠做基本的簡單系統的PHP開發;能夠在P...

    genedna 評論0 收藏0
  • PHP 開發中的外圍資源性能分析(

    摘要:本文作為針對外圍資源性的能分析,比較簡單地設計了一些實驗場景,看到了外部資源,包括中間件和數據庫資源給程序性能帶來的影響。有關影響程序性能的后端外圍資源就到這里,在下一篇中,我們將分析前端或者前后端結合給頁面延時帶來的影響。 暫且不討論「PHP 是不是最好的編程語言」,本文我們將分別分析一下在 PHP 程序的后端外圍資源和前端外圍資源,它們對整個 PHP Web 應用體驗的影響,這往往...

    cod7ce 評論0 收藏0
  • PHP 性能分析與實驗()——PHP 性能的微觀分析

    摘要:性能分析與實驗性能的宏觀分析在上一篇文章中,我們從是解釋性語言動態語言和底層實現等三個方面,探討了性能的問題。在開始分析之前,我們得掌握一些與性能分析相關的函數。二性能分析則下面我們根據小程序來驗證一些常見的性能差別。 【編者按】此前,閱讀過了很多關于 PHP 性能分析的文章,不過寫的都是一條一條的規則,而且,這些規則并沒有上下文,也沒有明確的實驗來體現出這些規則的優勢,同時討論的也側...

    Airy 評論0 收藏0
  • 使用XHProf分析PHP性能瓶頸()

    摘要:上一篇文章里,我們介紹了如何基于擴展來分析性能,并記錄到日志里,最后使用擴展自帶的在里展示出來。本次測試中,實際使用了擴展切換為擴展后里看不到數據,原因未知。雖然來自但已經很久不更新,官方源已經顯示此包已廢棄,不再維護。 上一篇文章里,我們介紹了如何基于xhprof擴展來分析PHP性能,并記錄到日志里,最后使用xhprof擴展自帶的UI在web里展示出來。本篇文章將講述2個知識點: ...

    Worktile 評論0 收藏0
  • PHP 性能分析與實驗——性能的宏觀分析

    摘要:本文就改變性能分析的角度,并通過實例來分析出的性能方面需要注意和改進的點。如下是作為解釋性語言的執行過程。這里分別啟用和做實驗。 編者按】此前,閱讀過了很多關于 PHP 性能分析的文章,不過寫的都是一條一條的規則,而且,這些規則并沒有上下文,也沒有明確的實驗來體現出這些規則的優勢,同時討論的也側重于一些語法要點。本文就改變 PHP 性能分析的角度,并通過實例來分析出 PHP 的性能方面...

    anquan 評論0 收藏0
  • PHP 性能分析與實驗——性能的宏觀分析

    摘要:本文就改變性能分析的角度,并通過實例來分析出的性能方面需要注意和改進的點。如下是作為解釋性語言的執行過程。這里分別啟用和做實驗。 【編者按】此前,閱讀過了很多關于 PHP 性能分析的文章,不過寫的都是一條一條的規則,而且,這些規則并沒有上下文,也沒有明確的實驗來體現出這些規則的優勢,同時討論的也側重于一些語法要點。本文就改變 PHP 性能分析的角度,并通過實例來分析出 PHP 的性能方...

    yy736044583 評論0 收藏0

發表評論

0條評論

最新活動
閱讀需要支付1元查看
<