More Related Content Similar to flyingV Laravel & AWS 經驗分享 (20) flyingV Laravel & AWS 經驗分享5. flyingV 重點營運數據
¡ 重點案件
¡ 超電能飛行錶 354 萬
¡ 太白粉路跑 635萬
¡ 殭屍路跑 796萬
¡ 看見台灣首映會 248萬
¡ 紐時集資廣告 - 台灣,這次妳一定要撐下去 693萬
¡ 割闌尾 – 1198萬
7. flyingV開發工具
¡ 全站使用AWS solution
¡ EC2 + RDS + CloudFront + S3 + SES + SQS
¡ 網站架構
¡ 後端框架
¡ Play framework (java, scala) → Laravel 4 (php)
¡ 前端框架
¡ jQuery → Backbone.js → jQuery + handlebars.js
¡ 其他工具
¡ Github
¡ Slack
¡ Asana
¡ Rollbar
10. Laravel 建立了優良的PHP 社群
¡ 傳統PHP社群難以建
¡ Composer
¡ PHP artisan
¡ 產生Model、Controller、
Migration
¡ Localhost web server
¡ Eloquent ORM
11. Composer.json flyingV
¡ laravel/framework: 4.1
¡ cartalyst/sentry
¡ cartalyst/sentry-social
¡ j20/php-uuid
¡ intervention/image
¡ aws/aws-sdk-php-laravel
¡ vinelab/http
¡ codesleeve/asset-pipeline
¡ rollbar/rollbar
¡ thujohn/rss
¡ anahkiasen/former
¡ intouch/laravel-newrelic
¡ Dev
¡ barryvdh/laravel-debugbar
¡ barryvdh/laravel-migration-
generator
15. 超大型案件 - 匍匐前進
¡ 2013年 全台灣最大路跑平台…
¡ 太白粉路跑
¡ 殭屍路跑
¡ 2014年 全台灣最大學運平台…
¡ 紐約時報廣告
¡ 割闌尾
16. 太白粉路跑
¡ 起因:color run 路跑報名系統掛站,促成第一場由素
人舉辦的路跑活動
¡ 規模:限時不限量,四天募資653萬、6700人報名
¡ 花錢加開機器 (java scala)
¡ 7台4x large FE
¡ 8x large RDS
¡ 結果
¡ safe
¡ 同時線上人數1600人
17. 殭屍路跑
¡ 起因:flyingV 引領 台灣素人舉辦特色路跑風氣
¡ 規模:限量一個下午
¡ PHP Laravel 第一次上陣
¡ 7台 4xlarge FE + RDS 8xlarge
¡ 結果:
¡ 2200同時在線
¡ RDS cpu100% 掛站 四十分鐘
¡ 一天之內造成 800封客服信
¡ 檢討:居然忘了在table 裡的 foreign key 加index
18. 紐約時報廣告
¡ 起因:ptt 鄉民發起募資廣告挺學運
¡ 規模:三個小時
¡ 四台 4xlarge FE + RDS 8X large
¡ 結果:
¡ 幾乎掛站,速度非常慢
¡ RDS 100%
¡ 6700人同時在線
¡ 檢討:cache 做的不夠
¡ 改進加上view cache、query cache、找出mysql slow log
24. Outline
¡ 伺服器效能調教一路上踩過的雷
¡ New Server Architecture
¡ Problem & Solution how to solve
¡ Ssl termination
¡ Elb auto scaling
¡ The future of flyingv
¡ https 轉的問題
¡ 過去 nfs 問題(I/O lock problem)
¡ Nginx php5-fpm 效能調教(different instance type)、htop (php 執
行速度、RDS)
25. Due to…
¡ 網站同時在線數暴增
¡ 網友分享、名人、粉絲團發文(ex:馬來膜)
¡ 募資案件相關:預熱開始上線、上架開賣、快要結案時
¡ https
¡ OpenSSL 大大小小的問題 (ex:
Heartbleed)
100
500
1000
2000
0
1000
2000
3000
1 5 10 30
同
時
在
線
人
數
分鐘數
流量示意圖
27. NFS I/O-Lock
¡ 什麼都想 cache,結果什麼都被 lock !!!
¡ View cache, db query cache, session, …
View Cache
DB Query Cache
Session
28. PHP5-FPM & Nginx
Configuration
¡ EC2 Instance Type: c3.large, c3.xlarge, c3.2xlarge,
c3.4xlarge, c3.8xlarge
¡ # of CPU Core: 2~32
¡ RAM: 3.75~60 GiB
¡ Configuration
¡ Nginx: worker_processes 4;
¡ PHP5-FPM: pm.max_children = 32;
¡ Static, dynamic, on demand
¡ Process children 數量取決於 RAM 的大小,能同時處理越多
php scripts
¡ 根據 CPU 的核心數,給予 Nginx worker_process 不同的設定值
32. SSL Termination
¡ 把 SSL 加解密傳輸的部份都交由 AWS 處理
¡ 雷之 HTTPS forward to HTTP(對於 Web Server 而言拿到的是 HTTP)
¡ URL Rewrites: 3xx Redirects 對於 POST 支援度不完整
¡ Website Development Framework 的 URL Helper 多轉成絕對位址(例如:
laravel 之 form::open, request::root(), …)
¡ PHP 可用 $_SERVER[‘HTTP_X_FORWARDED_PROTO’]
¡ 善用相對位址 (ex: js/jquery.latest.min.js)
34. PHP Script Including Laravel
require '../vendor/autoload.php';
require '../bootstrap/start.php';
use IlluminateDatabaseCapsuleManager as
Capsule;
$capsule = new Capsule;
$capsule-
>addConnection(Config::get('database.connections.
mysql'));
$capsule->bootEloquent();
37. 之後的 FlyingV
¡ 週末
¡ 不要再接到 PM 跟老闆的電話
¡ 不要打開電腦
¡ 拒絕遠端連線回伺服器
¡ 周間上班日
¡ 可以安心的吃午餐
¡ 可以安心的睡午覺
¡ 可以安心的下班
¡ 以上所述之前提為程式面沒有 Bug 下…