View
5.491
Download
9
Category
Preview:
Citation preview
Agenda
(c) 2015 Masashi Shinbara @shin1x1
• Azure Websites とは • Azure Websites の PHP環境 • スケーラブルな PHP アプリケーション • まとめ
Azure Websites
(c) 2015 Masashi Shinbara @shin1x1
• Azure の PaaS (Platform as a Service)
• デプロイするだけで、すぐに公開できる • 柔軟なスケール / オートスケール • .NET、Java、PHP、Node.js、Python
おさえておく特徴
(c) 2015 Masashi Shinbara @shin1x1
• 東日本 / 西日本リージョン • 多様なデプロイ方法( Git あり) • コマンドラインツール( azure コマンド) • Windows Server + IIS • DB や KVS 等は、別サービスと連携
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
操作ツール
(c) 2015 Masashi Shinbara @shin1x1
• 現ポータルサイト • 新ポータルサイト • コマンドラインツール • Visual Studio Online Monaco • Kudu
PHP
(c) 2015 Masashi Shinbara @shin1x1
• Windows 版 PHP • 32bit / 64bit • 5.3 / 5.4 / 5.5 / 5.6 • ランタイムを追加することも可能
PHPランタイムの追加
(c) 2015 Masashi Shinbara @shin1x1
http://azure.microsoft.com/ja-jp/documentation/articles/web-sites-php-configure/#UseCustomPHP
PHP拡張の追加
(c) 2015 Masashi Shinbara @shin1x1
http://azure.microsoft.com/ja-jp/documentation/articles/web-sites-php-configure/#EnableExtDefaultPHP
Composer
(c) 2015 Masashi Shinbara @shin1x1
• デフォルトでは、未対応 • Websites 上で直接実行する (Monaco / Kudo)
• デプロイスクリプトを利用すれば、 デプロイ時に composer install
deploy.sh を編集
$ vim deploy.sh
# 下記を DEPLOYMENT セクション上に追加
curl -sS https://getcomposer.org/installer | phpphp composer.phar install --prefer-dist --no-dev
デプロイ時に composer install 実行
$ git push azure master
(snip)remote: Loading composer repositories with package informationremote: Installing dependencies from lock fileremote: - Installing shin1x1/sample (dev-master 565c62e)remote: Downloading: connection... Downloading: 100%remote: Extracting archiveremote:(snip)
.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
Azure SDK for PHP
(c) 2015 Masashi Shinbara @shin1x1
• Azure サービスを PHP から操作 • Composer / PEAR でインストール • 開発が、ややのんびり?
The Twelve-Factor App
(c) 2015 Masashi Shinbara @shin1x1
• アプリケーションは、プロセスとして実行 • プロセスは、ステートレスで、共有しない • データは、バックエンドサービスに保存すべき • Sticky session には依存しない
http://12factor.net/processes
サンプルアプリケーション
(c) 2015 Masashi Shinbara @shin1x1
• 会員制画像投稿サイト • Laravel 4.2 • ログイン / 画像登録 / 画像閲覧
会員制画像投稿サイト
Laravel 4.2
ログイン
画像登録 / 画像閲覧
アプリケーションデータ
(c) 2015 Masashi Shinbara @shin1x1
• ユーザデータ = ClearDB(MySQL)Free • セッション = Webインスタンス(ファイル) • 画像 = Webインスタンス(ファイル)
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
検証2
(c) 2015 Masashi Shinbara @shin1x1
• WebサイトにインスタンスIDを表示 • Sticky Session はオフに • インスタンスID が変化することは確認済
(c) 2015 Masashi Shinbara @shin1x1
C:
D:Laravel でのセッション
D:\home\site\wwwroot\ app\storage\sessions
インスタンスのストレージ?
負荷を計測
(c) 2015 Masashi Shinbara @shin1x1
• jmeter で計測(大阪) • 画像表示ページ (DB = Read / セッション = Read / Write)
• 1インスタンス(Basic / S / Japan East)
ケース1
(c) 2015 Masashi Shinbara @shin1x1
ClearDB
• データベース = ClearDB (Free) • Thread = 10 / Rumpup = 60 / Loop = 10 • Response time = 1,217ms
ケース2
(c) 2015 Masashi Shinbara @shin1x1
CentOS MySQL
• データベース = Azure VM (Basic_A0) • Thread = 10 / Rumpup = 60 / Loop = 10 • Response time = 188ms
ケース3
(c) 2015 Masashi Shinbara @shin1x1
CentOS MySQL
• セッション = ファイル(共有ディスク?) • Thread = 60 / Rumpup = 60 / Loop = 10 • Response time = 3,892ms
ケース4
(c) 2015 Masashi Shinbara @shin1x1
CentOS MySQL
• セッション = Azure Redis Cache • Thread = 60 / Rumpup = 60 / Loop = 10 • Response time = 223ms
(c) 2015 Masashi Shinbara @shin1x1
• とりあえずは、そのままで良い (Sticky session / 共有ディスク)
• 負荷に応じて、アプリケーションデータを 別サービスに逃がしていく
• Azure サービスなら、利用しやすい
スケーラブルにするには
(c) 2015 Masashi Shinbara @shin1x1
CDNによるコンテンツ配信
• Azure CDN • Azure Websites をオリジンサーバに • エッジロケーションから高速配信
(c) 2015 Masashi Shinbara @shin1x1
• 日本国内にある PHP の PaaS • 無料枠で、簡単に試せる • 元からスケーラブルな構成 • Azure サービスとの親和性が高い • Windows ユーザだけに使わせるのは勿体無い
まとめ
Recommended