山崎雅師
    • Create new note
    • Create a note from template
      • 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
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me 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
    • Save as template
    • 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 Create Help
Create Create new note Create a note from template
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
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me 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
    # ISUCON チートシート ## TODOリスト - [ ] スクリプトを書く - [ ] alp,pt-query-digestのインストールコマンド - [x] alpを実行したときにタイムスタンプでログを保存してくれるやつ - [x] alp -f /var/log/nginx/access.log >> alp{#Time.now}.txt みたいなやつ - [ ] pt-query-digestも同上 - [ ] ベンチ回した時(ビルドした時?)にnginxのaccess.logをaccess-2020-06-07.logみたいに前のを変更してくれるやつ - [ ] deployのスクリプト - [ ] 役割を決める(インフラ系、アプリ系とか?全員が全部やるでも可) - [ ] 過去問を一緒に解く(isucon8) got # 当日作業流れ ## 初期行動 - [ ] ベンチ回す - [ ] 公開鍵認証でログインできるようにする - [ ] git管理できるようにする(どこでgit initするか要相談) - [ ] サーバーのスペック確認(cpuコア数・メモリ・ディスク容量など) - [ ] [MySQLデータ確認](#MySQLのデータ確認) - [ ] [MySQLのタレを入れる](#MySQLのタレ) - [ ] [Nginxのタレを入れる](#Nginxのタレ) - [ ] alp,pt-query-digestを入れる - [ ] [pt-query-digestを見てindexを貼る](#pt-query-digest) - [ ] ベンチを回す - [ ] アプリケーションの一通りの動作・コードを確認する(1時間くらいはかけていい) - [ ] ボトルネックになっているものを解決していく ## 困った時に見るリスト - [ ] N+1問題(クエリ改善だけじゃなくてクエリなくすのもあり) - [ ] DBじゃなくてインメモリにできるか - [ ] キャッシュをつける - [ ] [http2にする sslの設定が要ります(ベンチで落ちる可能性もあるが効果はでかいはず)](https://qiita.com/takahia/items/756be5b47134f9e51a11) - [ ] [ロードバランシング](#ロードバランシング)する(どのサーバーをどれに割り当てるかは要検討) - [ ] 並列処理にする(コア数確認する) - [ ] 処理速度が上がってまだデータがないのにリクエストが来てfailの可能性がある ## # 便利コマンド ### alp インストール ``` wget https://github.com/tkuchiki/alp/releases/download/v0.4.0/alp_linux_amd64.zip unzip alp_linux_amd64.zip sudo install ./alp /usr/local/bin alp --version ``` 実行コマンド(AVGあたりを意識して見る、これもスクリプトあれば嬉しい) ``` alp -f /var/log/nginx/access.log ``` ### pt-query-digest インストール(ubuntu) ``` apt-get install percona-toolkit ``` 使う(スクリプト用意したい) ``` pt-query-digest /var/log/mysql/slow-queries.log >> slow.txt ``` ### MySQLのデータ確認 ``` SELECT table_name, engine, table_rows, avg_row_length, floor((data_length+index_length)/1024/1024) as allMB, floor((data_length)/1024/1024) as dMB, floor((index_length)/1024/1024) as iMB FROM information_schema.tables WHERE table_schema=database() ORDER BY (data_length+index_length) DESC; ``` ## MySQLのタレ コメントアウトしてるのは入ってると動かない可能性がある(環境によるっぽい) ``` [mysqld] # スロークエリの出力設定(最後切る) slow_query_log=ON # スロークエリと判定する秒数(全て表示) long_query_time=0 # スロークエリログの場所 slow_query_log_file = /var/log/mysql/mysql-slow.log # スレッドキャッシュ保持最大数 thread_cache_size=100 # クエリキャッシュ最大サイズ query_cache_limit=16M # クエリキャッシュで使用するメモリサイズ query_cache_size=512M # クエリキャッシュのタイプ(0:off, 1:ON SELECT SQL_NO_CACHE以外, 2:DEMAND SELECT SQL_CACHEのみ) query_cache_type=1 # テーブルを作り直さないと効果が薄い innodb_file_per_table=ON # InnoDBのデータとインデックスをキャッシュするバッファのサイズ(推奨は物理メモリの8割) innodb_buffer_pool_size=6G # InnoDBの更新ログを記録するディスク上のファイルサイズ(innodb_buffer_pool_sizeの4分の1程度) innodb_log_file_size=1G ################# # innodb # ################# # InnoDBのデータ・ディクショナリーや内部データ構造情報を持つバッファのサイズ(deprecated) #innodb_additional_mem_pool_size=20M # コミットされていないトランザクションのためのバッファのサイズ innodb_log_buffer_size=64M # データやインデックスを共有ではなくテーブル個別に保存する innodb_file_per_table=1 # ################# # etc # ################# # インデックス未使用でのJOIN時に使用するバッファ join_buffer_size=256K # クライアントからサーバーに送信できるパケットの最大長 max_allowed_packet=8M # フルスキャンのレコードバッファ read_buffer_size=1M # キーを使用したソートで読み込まれた行がキャッシュされるバッファ read_rnd_buffer_size=2M # ソート時に使用されるバッファ sort_buffer_size=4M # MEMORYテーブルの最大サイズ。このサイズを超えたMEMORYテーブルはディスク上に作成 max_heap_table_size=16M # スレッド毎に作成される一時的なテーブルの最大サイズ。スレッドバッファ tmp_table_size=16M # コネクションタイムアウト時間 wait_timeout=30 # 実行されたSQLをログに残すか general_log=OFF ``` ## Nginxのタレ ### Nginx.conf ``` worker_processes auto; worker_rlimit_nofile 100000; events { worker_connections 2048; multi_accept on; use epoll; } http{ #alp用のlog設定 log_format ltsv "time:$time_local" "\thost:$remote_addr" "\tforwardedfor:$http_x_forwarded_for" "\treq:$request" "\tstatus:$status" "\tmethod:$request_method" "\turi:$request_uri" "\tsize:$body_bytes_sent" "\treferer:$http_referer" "\tua:$http_user_agent" "\treqtime:$request_time" "\tcache:$upstream_http_x_cache" "\truntime:$upstream_http_x_runtime" "\tapptime:$upstream_response_time" "\tvhost:$host"; access_log /var/log/nginx/access.log ltsv; sendfile on; tcp_nopush on; tcp_nodelay on; server_tokens off; gzip on; gzip_http_version 1.0; gzip_disable "msie6"; gzip_proxied any; #小さすぎるのはむしろ効率悪いので最小値を決める gzip_min_length 1024; gzip_comp_level 6; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript ; open_file_cache max=100000 inactive=20s; open_file_cache_valid 30s; open_file_cache_min_uses 2; open_file_cache_errors on; } ``` ### isucon.conf ``` proxy_cache_path /tmp/nginx_cache levels=1:2 keys_zone=objects:20m max_size=3g inactive=4d; proxy_temp_path /tmp/nginx_tmp; proxy_cache_lock on; proxy_cache_lock_timeout 2m; servers{ location /icons/ { add_header X-Cached $upstream_cache_status; #どこからか持ってきたんだけど調べても意味がわかりませんでした・・ proxy_cache objects; proxy_cache_valid 200 302 12h; # proxy_cache_valid 404 403 1m; # public=みんなでキャッシュを共有 immutable=サーバーに問い合わせない add_header Cache-Control "public, max-age=31536000, immutable"; proxy_set_header Host $http_host; #当日サーバーIPによって変える proxy_pass http://app:5000; } } ``` ### ロードバランシング ``` upstream backend { server 192.168.101.1:80; server 192.168.101.2:80; keepalive 64; } server{ location / { proxy_set_header Host $http_host; proxy_pass http://backend; proxy_http_version 1.1; proxy_set_header Connection ""; } } ``` ### 参考になりそう - https://gist.github.com/south37/d4a5a8158f49e067237c17d13ecab12a#file-04_nginx-md # 超絶参考になりそうリンク 厳選してこれは役立ちそう!ってやつだけ - [GoでISUCONを戦う話](https://gist.github.com/catatsuy/e627aaf118fbe001f2e7c665fda48146)

    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