Drupal performance (in DrupalCamp Taipei)

31
Drupal 超超超超 How to Speed Up Drupal Jimmy Huang 2011 Drupalcamp Taipei email: Jimmy at netivism.com.t blog: jimmyhub.net

Transcript of Drupal performance (in DrupalCamp Taipei)

Page 1: Drupal performance (in DrupalCamp Taipei)

Drupal 超速指引How to Speed Up Drupal

Jimmy Huang2011 Drupalcamp Taipeiemail: Jimmy at netivism.com.twblog: jimmyhub.net

Page 2: Drupal performance (in DrupalCamp Taipei)

高效能 Drupal 策略• 小比大好,少比多好,瘦比胖好• 不該出現的不要出現• 不需裝的不要裝• 不需即時運算的就快取• 記憶體比資料庫好• 資料庫比檔案好

Page 3: Drupal performance (in DrupalCamp Taipei)

如何擬定效能改善方針• 瓶頸在哪裡?

– 慢再哪裡? CPU / 記憶體 / 流量?– 哪個頁面發生這個問題?– 慢再何時?

• 檢測瓶頸– CPU : 確認是 Apache 還是 MySQL– 記憶體 : 確認沒有用到 Swap 磁區– 流量 : 確認連線場所網路順暢– 頁面 : 確認某些頁面特別久

Page 4: Drupal performance (in DrupalCamp Taipei)

如何擬定效能改善方針 ( 續 )

• 哪個網頁特別龜?• 登入時瀏覽和登出時瀏覽的差異?• 租用哪家 Server ?有權限做 Server 調整?• 每日造訪頁數( awstats / google analytics ) ?

• 很多人看?還是很多爬蟲?

Page 5: Drupal performance (in DrupalCamp Taipei)

如何擬定效能改善方針 ( 續 )

• 安裝模組ex. memcache, boost, csstidy …

• 調整 Serverex. Apache MaxClients 數值ex. Mod Deflate

• 調整 Drupal 設定– 根據檢測出來的頁面,調整對應設定

• 調整程式碼– 非不得已,自行開發模組,再調整程式碼

Page 6: Drupal performance (in DrupalCamp Taipei)

在 Drupal 如何檢測效能• Devel 觀察記憶體 / 頁面產生速度• Devel 蒐集 Database 使用的狀況

• 分析 Query 問題、來源• 調整出問題之 Views / Panels / 程式碼

Page 7: Drupal performance (in DrupalCamp Taipei)

在 Drupal 如何檢測效能 ( 續 )

garland, system, block, dblog, filter, menu, node, taxonomy, user, content, date, date_api, date_repeat, date_timezone, number, optionwidgets, text, feeds, feeds_ui, feeds_xpathparser, ctools, job_scheduler, devel, views, views_ui

Page 8: Drupal performance (in DrupalCamp Taipei)

在 Drupal 如何檢測效能 ( 續 )

Page 9: Drupal performance (in DrupalCamp Taipei)
Page 10: Drupal performance (in DrupalCamp Taipei)

檢測效能 – Apache / MySQL

Page 11: Drupal performance (in DrupalCamp Taipei)

檢測效能 – 流量問題

Page 12: Drupal performance (in DrupalCamp Taipei)

檢測效能 – 流量問題

Page 13: Drupal performance (in DrupalCamp Taipei)

實戰 - css / javascript aggregration

Before…

Page 14: Drupal performance (in DrupalCamp Taipei)

實戰 - css / javascript aggregration

After…

Page 15: Drupal performance (in DrupalCamp Taipei)

實戰 - html / css / javascript 壓縮

Before…

Page 16: Drupal performance (in DrupalCamp Taipei)

實戰 - html / css / javascript 壓縮( 續 )

After…

Page 17: Drupal performance (in DrupalCamp Taipei)

實戰 - html / css / javascript 壓縮( 續 )

use: http://www.seoconsultants.com/tools/compression

Page 18: Drupal performance (in DrupalCamp Taipei)

實戰 - html / css / javascript 壓縮( 續 )

• Apache mod_deflate 開啟• Page Compression 開啟• 第三方模組

– Advanced CSS/JS Aggregation– CSS Gzip– CSSTidy

Page 19: Drupal performance (in DrupalCamp Taipei)

實戰 – 快取技術• Drupal 快取方式

– Menu , Form, Page, Variables, Content, Language …

• 快取技術– Drupal 內建整頁 HTML 快取– Views / Panels 模組快取– Boost 模組

Page 20: Drupal performance (in DrupalCamp Taipei)

Drupal頁面快取

Page 21: Drupal performance (in DrupalCamp Taipei)

Views快取

Page 22: Drupal performance (in DrupalCamp Taipei)

Panel快取

Page 23: Drupal performance (in DrupalCamp Taipei)

Boost快取

Page 24: Drupal performance (in DrupalCamp Taipei)

實戰 – 記憶體快取• 為何把快取放進記憶體?

– 建立 Database 連線緩慢– MySQL 的效能不足– Database 新增、刪除的動作比記憶體慢

• 如何做?– 安裝 memcached– 安裝 php-memcache– 安裝 drupal memcache

Page 25: Drupal performance (in DrupalCamp Taipei)

實戰 – 記憶體快取

Page 26: Drupal performance (in DrupalCamp Taipei)

Before…

# ab -c 100 -t 30 http://netivism.com.tw/Document Path: /Document Length: 33246 bytes

Concurrency Level: 100Time taken for tests: 30.085 secondsComplete requests: 130Failed requests: 0Write errors: 0Total transferred: 4992040 bytesHTML transferred: 4920408 bytesRequests per second: 4.32 [#/sec] (mean)Time per request: 23142.220 [ms] (mean)Time per request: 231.422 [ms] (mean, across all concurrent requests)Transfer rate: 162.04 [Kbytes/sec] received

Page 27: Drupal performance (in DrupalCamp Taipei)

AfterMemcache:

# ab -c 100 -t 30 http://netivism.com.tw/Document Path: /Document Length: 33246 bytes

Concurrency Level: 100Time taken for tests: 30.021 secondsComplete requests: 432Failed requests: 0Write errors: 0Total transferred: 14976120 bytesHTML transferred: 14761224 bytesRequests per second: 14.39 [#/sec] (mean)Time per request: 6949.333 [ms] (mean)Time per request: 69.493 [ms] (mean, across all concurrent requests)Transfer rate: 487.16 [Kbytes/sec] received

Page 28: Drupal performance (in DrupalCamp Taipei)

# ab -c 100 -t 30 http://netivism.com.tw/Document Path: /Document Length: 33329 bytes

Concurrency Level: 100Time taken for tests: 30.009 secondsComplete requests: 5113Failed requests: 0Write errors: 0Total transferred: 172425088 bytesHTML transferred: 170310941 bytesRequests per second: 170.38 [#/sec] (mean)Time per request: 586.922 [ms] (mean)Time per request: 5.869 [ms] (mean, across all concurrent requests)Transfer rate: 5611.05 [Kbytes/sec] received

AfterBoost:

Page 29: Drupal performance (in DrupalCamp Taipei)

Before After

Page 30: Drupal performance (in DrupalCamp Taipei)

參考資源• Web resource

– Drupal效能相關模組 (drupal.org)– Drupal效能群組 (group.drupal.org)– Drupal Performance Handbook (drupal.org)– Drupal Performance Tuning (2bits)

• Book– Drupal 6 Performance Tips (PACKT)– Drupal Performance and Scalability (Lullabot)

Page 31: Drupal performance (in DrupalCamp Taipei)

photo list

http://www.flickr.com/photos/17612257@N00/4639794109/http://gala4th.blogspot.com/2009_09_01_archive.html http://www.flickr.com/photos/runforcover/3791930953/ http://www.flickr.com/photos/cyberslayer/5874026128/ http://www.flickr.com/photos/marcovdz/4520986339/ http://www.flickr.com/photos/bwjones/4227870410/ http://www.flickr.com/photos/adcuz/3104028585/ http://www.flickr.com/photos/antphotos/3469245178/ http://www.flickr.com/photos/kino/487539637/in/photostream/ http://www.flickr.com/photos/nathey4/5713434731/http://bumpshack.com/2010/08/06/sara-rue-incredible-weight-loss-

before-after-photos/