Successfully reported this slideshow.
Your SlideShare is downloading. ×

Azure Websites で作るスケーラブルな PHP アプリケーション

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Loading in …3
×

Check these out next

1 of 63 Ad

More Related Content

Slideshows for you (20)

Similar to Azure Websites で作るスケーラブルな PHP アプリケーション (20)

Advertisement

More from Masashi Shinbara (17)

Recently uploaded (20)

Advertisement

Azure Websites で作るスケーラブルな PHP アプリケーション

  1. 1. 2015/01/16 shin1x1 GoAzure 2015 Azure Websites で作る スケーラブルな
 PHPアプリケーション
  2. 2. 2015/01/16 shin1x1 GoAzure 2015 LAMP(LAPP)ユーザが使う Azure Websites
  3. 3. Agenda (c) 2015 Masashi Shinbara @shin1x1 • Azure Websites とは • Azure Websites の PHP環境 • スケーラブルな PHP アプリケーション • まとめ
  4. 4. (c) 2015 Masashi Shinbara @shin1x1 Azure Websites
  5. 5. Azure Websites (c) 2015 Masashi Shinbara @shin1x1 • Azure の PaaS
 (Platform as a Service) • デプロイするだけで、すぐに公開できる • 柔軟なスケール / オートスケール • .NET、Java、PHP、Node.js、Python
  6. 6. 詳しくは (c) 2015 Masashi Shinbara @shin1x1 http://azure.microsoft.com/ja-jp/services/websites/
  7. 7. おさえておく特徴 (c) 2015 Masashi Shinbara @shin1x1 • 東日本 / 西日本リージョン • 多様なデプロイ方法( Git あり) • コマンドラインツール( azure コマンド) • Windows Server + IIS • DB や KVS 等は、別サービスと連携
  8. 8. Webインスタンスを作って、デプロイする $ git init $ echo “<?php phpinfo();” > index.php $ git add . $ git commit -m ‘init’ $ azure $ azure site create shin1x1-goazure --location "Japan East" $ git push azure master $ open http://shin1x1-goazure.azurewebsites.net
  9. 9. PHPバージョン変更 $ azure site set --php-version 5.5
  10. 10. $ azure portal 管理サイト(ポータル)を開く
  11. 11. Monaco でシェル操作
  12. 12. 操作ツール (c) 2015 Masashi Shinbara @shin1x1 • 現ポータルサイト • 新ポータルサイト • コマンドラインツール • Visual Studio Online Monaco • Kudu
  13. 13. (c) 2015 Masashi Shinbara @shin1x1 PHP環境
  14. 14. PHP (c) 2015 Masashi Shinbara @shin1x1 • Windows 版 PHP • 32bit / 64bit • 5.3 / 5.4 / 5.5 / 5.6 • ランタイムを追加することも可能
  15. 15. PHPランタイムの追加 (c) 2015 Masashi Shinbara @shin1x1 http://azure.microsoft.com/ja-jp/documentation/articles/ web-sites-php-configure/#UseCustomPHP
  16. 16. PHP拡張 (c) 2015 Masashi Shinbara @shin1x1 • 主要なものは有効
 (mbstring / pdo / opcache 等) • DLL を追加して、利用可能
  17. 17. PHP拡張の追加 (c) 2015 Masashi Shinbara @shin1x1 http://azure.microsoft.com/ja-jp/documentation/articles/ web-sites-php-configure/#EnableExtDefaultPHP
  18. 18. Composer (c) 2015 Masashi Shinbara @shin1x1 • デフォルトでは、未対応 • Websites 上で直接実行する
 (Monaco / Kudo) • デプロイスクリプトを利用すれば、
 デプロイ時に composer install
  19. 19. デプロイスクリプトのひな形を生成 $ azure site deploymentscript --php -t bash # .deployment deploy.sh が生成される
  20. 20. deploy.sh を編集 $ vim deploy.sh # 下記を DEPLOYMENT セクション上に追加 curl -sS https://getcomposer.org/installer | php php composer.phar install --prefer-dist --no-dev
  21. 21. デプロイ時に composer install 実行 $ git push azure master (snip) remote: Loading composer repositories with package information remote: Installing dependencies from lock file remote: - Installing shin1x1/sample (dev-master 565c62e) remote: Downloading: connection... Downloading: 100% remote: Extracting archive remote: (snip)
  22. 22. .htaccess (c) 2015 Masashi Shinbara @shin1x1 • IIS なので、.htaccess は対応しない • 設定を Web.Config に記述 • .htaccess -> Web.Config 変換サイト http://cbsa.com.br/tools/online-convert-htaccess-to-web-config.aspx
  23. 23. Azure SDK for PHP (c) 2015 Masashi Shinbara @shin1x1 • Azure サービスを PHP から操作 • Composer / PEAR でインストール • 開発が、ややのんびり?
  24. 24. (c) 2015 Masashi Shinbara @shin1x1 スケーラブルな
 PHPアプリケーション
  25. 25. The Twelve-Factor App (c) 2015 Masashi Shinbara @shin1x1 • アプリケーションは、プロセスとして実行 • プロセスは、ステートレスで、共有しない • データは、バックエンドサービスに保存すべき • Sticky session には依存しない http://12factor.net/processes
  26. 26. サンプルアプリケーション (c) 2015 Masashi Shinbara @shin1x1 • 会員制画像投稿サイト • Laravel 4.2 • ログイン / 画像登録 / 画像閲覧 会員制画像投稿サイト Laravel 4.2 ログイン 画像登録 / 画像閲覧
  27. 27. アプリケーションデータ (c) 2015 Masashi Shinbara @shin1x1 • ユーザデータ = ClearDB(MySQL)Free • セッション = Webインスタンス(ファイル) • 画像 = Webインスタンス(ファイル)
  28. 28. 構成 (c) 2015 Masashi Shinbara @shin1x1 セッション ClearDB 写真 ユーザデータ
  29. 29. インスタンス2台構成 (c) 2015 Masashi Shinbara @shin1x1 セッション ClearDB 写真 セッション 写真 ユーザデータ
  30. 30. インスタンス2台構成 (c) 2015 Masashi Shinbara @shin1x1 ClearDB ログイン
  31. 31. インスタンス2台構成 (c) 2015 Masashi Shinbara @shin1x1 ClearDB セッション
  32. 32. インスタンス2台構成 (c) 2015 Masashi Shinbara @shin1x1 ClearDB セッション 会員ページ
  33. 33. インスタンス2台構成 (c) 2015 Masashi Shinbara @shin1x1 ClearDB セッション セッションが無い!
  34. 34. インスタンス2台構成 (c) 2015 Masashi Shinbara @shin1x1 ClearDB セッション ログアウト
  35. 35. 検証 (c) 2015 Masashi Shinbara @shin1x1 • 2インスタンス構成 • ログインして、会員ページを何度もリロード • ログアウトするはず
  36. 36. ログアウトしない!
  37. 37. Sticky Session (c) 2015 Masashi Shinbara @shin1x1 • デフォルトで、LB の Sticky Sessionが有効 • リロードだと、常に同じインスタンスへアクセス • Arr-Disable-Session-Affinity ヘッダで
 無効にできる http://blogs.msdn.com/b/windowsazurej/archive/2013/11/25/blog- disabling-arrs-instance-affinity-in-windows-azure-web-sites.aspx
  38. 38. 検証2 (c) 2015 Masashi Shinbara @shin1x1 • WebサイトにインスタンスIDを表示 • Sticky Session はオフに • インスタンスID が変化することは確認済
  39. 39. ログアウトしない!!
  40. 40. なぜか???
  41. 41. インスタンス2台構成 (c) 2015 Masashi Shinbara @shin1x1 セッション 写真 セッション 写真
  42. 42. おそらく… (c) 2015 Masashi Shinbara @shin1x1 セッション 写真
  43. 43. (c) 2015 Masashi Shinbara @shin1x1 セッション 写真 Azure Storage ?? おそらく…
  44. 44. インスタンスのストレージ? (c) 2015 Masashi Shinbara @shin1x1 C: 共有されていない D: 共有されている?
  45. 45. (c) 2015 Masashi Shinbara @shin1x1 C: D: デプロイしたアプリケーション
 D:homesitewwwroot インスタンスのストレージ?
  46. 46. (c) 2015 Masashi Shinbara @shin1x1 C: D: Laravel でのセッション D:homesitewwwroot appstoragesessions インスタンスのストレージ?
  47. 47. (c) 2015 Masashi Shinbara @shin1x1 C: D: PHPデフォルトのセッション C:DWASFilesSitesxxxxTemp インスタンスのストレージ?
  48. 48. DEMO2
  49. 49. スケーラブルにするには (c) 2015 Masashi Shinbara @shin1x1 データが D: にあれば 何もしなくて良い
  50. 50. スケーラブルにするには (c) 2015 Masashi Shinbara @shin1x1 データが C: にあれば 別サービスに逃す (セッションなら sticky session でも可)
  51. 51. デフォルト構成のまま で良いか?
  52. 52. 負荷を計測 (c) 2015 Masashi Shinbara @shin1x1 • jmeter で計測(大阪) • 画像表示ページ
 (DB = Read / セッション = Read / Write) • 1インスタンス(Basic / S / Japan East)
  53. 53. ケース1 (c) 2015 Masashi Shinbara @shin1x1 ClearDB • データベース = ClearDB (Free) • Thread = 10 / Rumpup = 60 / Loop = 10 • Response time = 1,217ms
  54. 54. ケース2 (c) 2015 Masashi Shinbara @shin1x1 CentOS
 MySQL • データベース = Azure VM (Basic_A0) • Thread = 10 / Rumpup = 60 / Loop = 10 • Response time = 188ms
  55. 55. 1クエリの速度 (c) 2015 Masashi Shinbara @shin1x1 Azure VM(MySQL) = 2ms ∼ 20ms ClearDB(Free)= 3ms ∼ 200ms
  56. 56. ケース3 (c) 2015 Masashi Shinbara @shin1x1 CentOS
 MySQL • セッション = ファイル(共有ディスク?) • Thread = 60 / Rumpup = 60 / Loop = 10 • Response time = 3,892ms
  57. 57. ケース4 (c) 2015 Masashi Shinbara @shin1x1 CentOS
 MySQL • セッション = Azure Redis Cache • Thread = 60 / Rumpup = 60 / Loop = 10 • Response time = 223ms
  58. 58. (c) 2015 Masashi Shinbara @shin1x1 スループット req/sec 0 10 20 30 40 ケース1 ケース2 ケース3 ケース4
  59. 59. (c) 2015 Masashi Shinbara @shin1x1 • とりあえずは、そのままで良い
 (Sticky session / 共有ディスク) • 負荷に応じて、アプリケーションデータを
 別サービスに逃がしていく • Azure サービスなら、利用しやすい スケーラブルにするには
  60. 60. (c) 2015 Masashi Shinbara @shin1x1 CDNによるコンテンツ配信 • Azure CDN • Azure Websites をオリジンサーバに • エッジロケーションから高速配信
  61. 61. (c) 2015 Masashi Shinbara @shin1x1 まとめ
  62. 62. (c) 2015 Masashi Shinbara @shin1x1 • 日本国内にある PHP の PaaS • 無料枠で、簡単に試せる • 元からスケーラブルな構成 • Azure サービスとの親和性が高い • Windows ユーザだけに使わせるのは勿体無い まとめ
  63. 63. @shin1x1 (c) 2015 Masashi Shinbara @shin1x1

×