COSCUP
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 網站效能表現問題分析的五個方法 - 吳政斌 {%hackmd tGp8pt49Q2aT5cD5TFyaIA %} ## 講師介紹 吳政斌 Chris ## 現象 等待時間久 * 502 bad gateway * 504 timeout * 老闆覺得慢 ## 原因 ### 連線問題 too many connection 太多連線 ISP stability 海底電纜斷了(主機放國外) ### 資源問題 too many webpage assets 載入太多不必要的東西 frontend performance 前端效能 (或是 前端動畫看起來反應太慢 (ex 1秒的動畫和0.3秒的動畫) ### 程式問題 Too many inbound / outbound request 有時候要跟金流網站交換資料,可能是這邊很慢 server resource 主機資源不足的時候可能也會慢 ### 資料庫為主 drupal 使用標裝安裝的話,資料庫已經有70個表左右,如果自訂framework的話,一開始不會規劃這麼多的表 其實 views 建立欄位時,一個欄位就是一個表 選views在使用時,從哪一個entity開始,例如有時候從user開始效能會有影響 ## 案例 大概有5個 ### DCard App DDoS 發現網站被DCard 的 App (不是網站) 被DDoS,某篇文章被大量存取 猜測可能是被轉到某個平台上,但發現GA流量上沒有,但從Weblog一直看到紀錄 原來在女孩版上講到月亮杯,是熱門第一篇,所以負載很重,原來是在右手邊有一個連結 在網站上沒事,但在App上會有爬文章,爬OG:摘要的功能 ### 怎麼發現的? 用web access log分析 - 網站熱門文章 - 定義 七天內最多人次存取的文章 - 熱門文章造成首頁TTFB過久 - 解決辦法 - 修改查詢策略 如果花時間去改程式碼,可能會花更多時間 例如發現首頁讀了25秒 > 一個月後產生效能瓶頸 > 使用者拿到timestamp,30天內都query出來,存取的資料是 每個網頁的開啟紀錄 1個月後發現有300萬筆資料 ### 熱門標籤計數排序Tag Count tag ↓ 爆笑(1694) 喜劇(1126) 搞笑(1093) 生活(1085) ↑ count 計算tag在全部文章使用的使用次數,依照使用次數的前幾筆資料顯示 文章數量大概3~4千篇,每個tag都超過1k以上的文章量,每篇文章又都使用複數的標籤,查詢出來花的秒數大概是10萬毫秒 因為有太多太多的join table,而且還有join 子查詢table的情況 ### 熱門標籤計數排序 修改後10萬毫秒變成354毫秒,利用left join修改查詢語法 ### oEmbed Cache 如果我們要去找每篇文章嵌入代碼,每篇都不一樣,這個模組就是在幫我們做這個是事 網頁打進去,透過oEmbed API得到 Request 新開發oEmbed功能後一段時間,文章列表頁load速度逐漸增加 如何從php code中找到問題 (實際上是 因為快取出問題,沒有真的快取,所以每次都送新的request) ## 分析方法 如果找不出問題,主機上持續發生這個問題,老闆只會問你搞定沒 ### Website Assets Analysis Chrome Developer Tools有這個功能 在 Network的 Visibility和Assets info 新版chrome的chrome developer tools會提供預覽圖以供參考。 ### WebPageTest https://www.webpagetest.org/ 最近一次發現可以從台灣GCE發測試,如果想要查台灣出去的效能,還蠻適合的 可以自動化多回合測試,例如連續測3~5次,提供平均值做參考 ### 讓數據說話 * 較適合用來分析前端效能 * 找出真正感受慢的原因 (感覺慢 不一定是效能差) * 找出影響效能的來源或發生位置,進一步往後端分析 * API / Scripts / Assets ## Web profiling * Drupal 7 - Devel * Drupal 8 - WebProfiler 8的話可以看到 PHP 的記憶體 狀態 執行時間等等 頁面用了幾個Views, 區塊, Form ...等等 DataBase有時候他會用 where sid= :sid 來顯示, 在PHP可以顯示timeline,顯示用到黑色區塊Service 程式,或是黃色的template, * 適合分析特定路徑的效能問題 * 可分析 PHP 以及記憶體使用量 * 可分析 DB Query 的表現 ## 回到DCard問題 利用Web Access log找到問題 因為user agent有奇怪的字 DCard,讓我們能比較明確的找到問題所在,裝個DCard App看看是不是真的有這個文章 使用 goaccess 來看log https://goaccess.io/ ## oEmbed Cache問題 利用PHP Slow log 他可以在一個執行裡 超過一定時間 會給予 PHP 執行stack 發現有一個關鍵字很慢 預設沒開,但開了也要知道怎麼找問題 ``` showlog = /var/log/php5/slow.log request_slowlog_timeout = 10s ``` ### Query performance mysql裡面也有slow log * Enable mysql slowlog * percona toolkit ``` pt-query-digest [OPTIONS] [FILES] [DSN] ``` https://www.percona.com/doc/percona-toolkit/LATEST/pt-query-digest.html 如果是自己寫的模組,當然自己會寫 但如果是Views會很難找 可能會用filter的名稱,例如這個filter在哪個views被使用 但建議大家用另一個方法 在Views裡面有一個進階的叫Query Options 有一個Query Comment,這個就是幫你產生Query的時候幫你(在開頭)產生註解,就把Views ID或是可以辨識的資料寫到Comment去,當哪天要找紀錄的時候可以很快的定位出來 ## key takeaway * Websites assets analysis(前端) * Web Profiler(前端) * Access log(伺服器) * PHP Slow log(後端) * MySQL Slow log(後端) ## 總結 了解可能造成問題的原因 使用客觀數據 具體描述 慢 感覺慢不一定是效能差 找出影響效能的來源或發生位置,進一步往後端分析 ###### tags: `COSCUP2018` `drupal`

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully