国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

PHP Opcode緩存加速組件:APC詳解介紹

2024-05-04 21:50:16
字體:
來源:轉載
供稿:網友

PHP在性能上相對于其他編譯型語言來說算不上突出,但是使用了Opcode緩存后性能提升還是很明顯的。常見的緩存加速組件主要有 eAccelerator,XCache,APC本文主要介紹APC的安裝使用。

APC,全稱是Alternative PHP Cache,官方翻譯叫"可選PHP緩存"。它為我們提供了緩存和優化PHP的中間代碼的框架。 APC的緩存分兩部分:系統緩存和用戶數據緩存。

系統緩存

它是指APC把PHP文件源碼的編譯結果緩存起來,然后在每次調用時先對比時間標記。如果未過期,則使用緩存的中間代碼運行。默認緩存3600s(一小時)。但是這樣仍會浪費大量CPU時間。因此可以在php.ini中設置system緩存為永不過期(apc.ttl=0)。不過如果這樣設置,改運php代碼后需要重啟WEB服務器。目前使用較多的是指此類緩存。

用戶數據緩存

緩存由用戶在編寫PHP代碼時用apc_store和apc_fetch函數操作讀取、寫入的。如果數據量不大的話,可以一試。如果數據量大,使用類似memcache此類的更加專著的內存緩存方案會更好。

APC模塊的安裝

最簡單的方法是直接使用pecl,在命令行下輸入:/usr/local/php/bin/pecl install apc

然后按照提示一步步完成即可,示例如下:

  1. [root@iZ23bm1tc0pZ ~]# /usr/local/php/bin/pecl install apc 
  2. downloading APC-3.1.13.tgz ... 
  3. Starting to download APC-3.1.13.tgz (171,591 bytes) 
  4. .....................................done: 171,591 bytes 
  5. 55 source files, building 
  6. running: phpize 
  7. Configuring for
  8. PHP Api Version:         20100412 
  9. Zend Module Api No:      20100525 
  10. Zend Extension Api No:   220100525 
  11. Enable internal debugging in APC [no] : no 
  12. Enable per request file info about files used from the APC cache [no] : no 
  13. Enable spin locks (EXPERIMENTAL) [no] : no 
  14. Enable memory protection (EXPERIMENTAL) [no] : no 
  15. Enable pthread mutexes (default) [no] : no 
  16. Enable pthread read/write locks (EXPERIMENTAL) [yes] : yes 

然后重啟服務器即可:

lnmp nginx restart

先看一下沒有使用apc情況下的壓測結果:

  1. [root@iZ23bm1tc0pZ ~]# ab -n1000 -c100 http://zfsphp.cn/index.php 
  2. This is ApacheBench, Version 2.3 <$Revision: 1706008 $> 
  3. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ 
  4. Licensed to The Apache Software Foundation, http://www.apache.org/ 
  5. Benchmarking zfsphp.cn (be patient) 
  6. Completed 100 requests 
  7. Completed 200 requests 
  8. Completed 300 requests 
  9. Completed 400 requests 
  10. Completed 500 requests 
  11. Completed 600 requests 
  12. Completed 700 requests 
  13. Completed 800 requests 
  14. Completed 900 requests 
  15. Completed 1000 requests 
  16. Finished 1000 requests 
  17. Server Software:        nginx 
  18. Server Hostname:        zfsphp.cn 
  19. Server Port:            80 
  20. Document Path:          /index.php 
  21. Document Length:        14341 bytes 
  22. Concurrency Level:      100 
  23. Time taken for tests:   15.517 seconds 
  24. Complete requests:      1000 
  25. Failed requests:        0 
  26. Total transferred:      14544000 bytes 
  27. HTML transferred:       14341000 bytes 
  28. Requests per second:    64.45 [#/sec] (mean) 
  29. Time per request:       1551.671 [ms] (mean) 
  30. Time per request:       15.517 [ms] (mean, across all concurrent requests) 
  31. Transfer rate:          915.34 [Kbytes/sec] received 
  32. Connection Times (ms) 
  33.               min  mean[+/-sd] median   max 
  34. Connect:        0    2   4.8      0      17 
  35. Processing:    46 1481 277.0   1560    1638 
  36. Waiting:       42 1481 277.1   1560    1638 
  37. Total:         58 1482 272.8   1560    1638 
  38. Percentage of the requests served within a certain time (ms) 
  39.   50%   1560 
  40.   66%   1576 
  41.   75%   1582 
  42.   80%   1587 
  43.   90%   1602 
  44.   95%   1612 
  45.   98%   1622 
  46.   99%   1629 
  47.  100%   1638 (longest request) 

可見最大吞吐率只有64.45reqs/s

然后我們開啟apc,測試結果如下:

  1. [root@iZ23bm1tc0pZ ~]# ab -n1000 -c100 http://Vevb.com/index.php 
  2. This is ApacheBench, Version 2.3 <$Revision: 1706008 $> 
  3. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://m.survivalescaperooms.com/ 
  4. Licensed to The Apache Software Foundation, http://www.apache.org/ 
  5. Benchmarking Vevb.com (be patient) 
  6. Completed 100 requests 
  7. Completed 200 requests 
  8. Completed 300 requests 
  9. Completed 400 requests 
  10. Completed 500 requests 
  11. Completed 600 requests 
  12. Completed 700 requests 
  13. Completed 800 requests 
  14. Completed 900 requests 
  15. Completed 1000 requests 
  16. Finished 1000 requests 
  17. Server Software:        nginx 
  18. Server Hostname:        zfsphp.cn 
  19. Server Port:            80 
  20. Document Path:          /index.php 
  21. Document Length:        14341 bytes 
  22. Concurrency Level:      100 
  23. Time taken for tests:   7.122 seconds 
  24. Complete requests:      1000 
  25. Failed requests:        0 
  26. Total transferred:      14544000 bytes 
  27. HTML transferred:       14341000 bytes 
  28. Requests per second:    140.41 [#/sec] (mean) 
  29. Time per request:       712.189 [ms] (mean) 
  30. Time per request:       7.122 [ms] (mean, across all concurrent requests) 
  31. Transfer rate:          1994.29 [Kbytes/sec] received 
  32. Connection Times (ms) 
  33.               min  mean[+/-sd] median   max 
  34. Connect:        0    1   2.4      0      10 
  35. Processing:    23  677 125.3    705     775 
  36. Waiting:       22  677 125.4    705     775 
  37. Total:         30  678 123.1    705     775 
  38. Percentage of the requests served within a certain time (ms) 
  39.   50%    705 
  40.   66%    719 
  41.   75%    726 
  42.   80%    730 
  43.   90%    742 
  44.   95%    750 
  45.   98%    760 
  46.   99%    765 
  47.  100%    775 (longest request) 

可見吞吐率提高了一倍多,達到140.41reqs/s,然后,我們在開啟動態內容緩存(樓主的博客用的是Smarty緩存),測試結果如下:

  1.  [root@iZ23bm1tc0pZ ~]# ab -n1000 -c100 http://Vevb.com/index.php 
  2. This is ApacheBench, Version 2.3 <$Revision: 1706008 $> 
  3. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://m.survivalescaperooms.com/ 
  4. Licensed to The Apache Software Foundation, http://www.apache.org/ 
  5. Benchmarking zfsphp.cn (be patient) 
  6. Completed 100 requests 
  7. Completed 200 requests 
  8. Completed 300 requests 
  9. Completed 400 requests 
  10. Completed 500 requests 
  11. Completed 600 requests 
  12. Completed 700 requests 
  13. Completed 800 requests 
  14. Completed 900 requests 
  15. Completed 1000 requests 
  16. Finished 1000 requests 
  17. Server Software:        nginx 
  18. Server Hostname:        zfsphp.cn 
  19. Server Port:            80 
  20. Document Path:          /index.php 
  21. Document Length:        14341 bytes 
  22. Concurrency Level:      100 
  23. Time taken for tests:   2.263 seconds 
  24. Complete requests:      1000 
  25. Failed requests:        0 
  26. Total transferred:      14544000 bytes 
  27. HTML transferred:       14341000 bytes 
  28. Requests per second:    441.98 [#/sec] (mean) 
  29. Time per request:       226.255 [ms] (mean) 
  30. Time per request:       2.263 [ms] (mean, across all concurrent requests) 
  31. Transfer rate:          6277.49 [Kbytes/sec] received 
  32. Connection Times (ms) 
  33.               min  mean[+/-sd] median   max 
  34. Connect:        0    1   3.1      0      12 
  35. Processing:    18  215  38.1    222     255 
  36. Waiting:       18  215  38.3    222     255 
  37. Total:         26  216  35.6    223     255 
  38. Percentage of the requests served within a certain time (ms) 
  39.   50%    223 
  40.   66%    230 
  41.   75%    232 
  42.   80%    234 
  43.   90%    237 
  44.   95%    239 
  45.   98%    240 
  46.   99%    243 
  47.  100%    255 (longest request) 

這一次吞吐率居然達到441.98reqs/s,提高了三倍多,相比最初的64.45reqs/s提高了近7倍,可見使用apc的opcode緩存配合Smarty緩存,對網站性能的優化效果還是相當明顯的。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 北辰区| 金阳县| 宿州市| 朝阳市| 宁津县| 常德市| 百色市| 黔西县| 东莞市| 正蓝旗| 白城市| 大连市| 乌审旗| 宾川县| 洪雅县| 龙南县| 奈曼旗| 绥阳县| 河东区| 甘南县| 梁河县| 车致| 锡林浩特市| 卢氏县| 个旧市| 织金县| 罗江县| 永年县| 北宁市| 赞皇县| 阿克苏市| 万年县| 凤阳县| 班戈县| 蚌埠市| 图木舒克市| 福贡县| 南溪县| 尉氏县| 田东县| 宁波市|