Home
Slides
Blog
slide.seike460.com
Home
Slides
Blog
Home
Slides
PHP on AWS Lambda!
PHP on AWS Lambda!
PHP Conference 2019
2019年12月1日
PHP
PHP
AWS
Lambda
Serverless
Keyboard Shortcuts
←
→
Navigate slides
Space
Next slide
F
Fullscreen
ESC
Exit fullscreen
Home
First slide
End
Last slide
B
.
Pause
S
Speaker notes
?
Reveal.js help
Close
## PHP on AWS Lambda! PHP Conference 2019 株式会社Fusic  清家史郎(@seike460) 
# 自己紹介 出来たら最後にします
# 今回お話する内容 - AWS Lambda is 何? - PHP on AWS Lambda! - パフォーマンス、利便性 さっきTweetしたはずなので、補足URLがあります
## AWS Lambda is 何?
# AWS Lambda is 何? - AWS が提供する Function as a Service (FaaS) - 管理するものは関数のみ - Serverless といえば AWS Lambdaと言われるサービス #### Serverless
# Serverless ### 僕たちはサーバー管理から開放される - サーバーの管理が不要 - 柔軟なスケーリング - 価値に対する支払い - 自動化された高可用性 [AWSのServerless説明](https://aws.amazon.com/jp/serverless/) #### Serverless良いよ!
## PHP on AWS Lambda!
# PHP on AWS Lambda! - AWS Lambdaは公式にPHPをサポートしていない - カスタムランタイムを利用 - PHP実行出来るファイルレイヤーを配置する
# !!! Caution !!! - 公式サポートしていない - カスタムランタイムは自分で責任を持つ必要有 - サーバーに責任を持つ - カスタムランタイム責任を持つ サーバーを責任もって構築するより負荷低いのでは…?
## デプロイの方法 話してる時間はないので僕のスライドか 本日の弊社社員のAdventCalendarを見てください - スライド - [brefPHP](https://slide.seike460.com/slides/cakefest2019#/) - 社員のAdvent Calendar - [k-masatany.com:AWS SAM + Bref で 楽々 PHP on Lambda](https://k-masatany.com/blog/easily-php-on-lambda-with-aws-sam+brefg) - キーワード - bref - Serverless Framework - Laravel Vapor
## パフォーマンス、利便性
###### パフォーマンス、利便性 Laravel をAWS Lambda で動作させて レスポンスを見ながら、利便性も見ます
# EC2版 - EC2 - t2.nano (1CPU / 0.5G Memory) - PHP 7.3 
# Lambda版 - Lambda - 1CPU / 0.5G Memory 
###### Apache Benchmark まずはLaravel Welcome ページでRDSへのアクセスなしの速度 
###### EC2版 (200Request 100Connection) Requests per second: 11.01 [#/sec] (mean) ``` This is ApacheBench, Version 2.3 <$Revision: 1843412 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking xxx.xxx.xxx.xxx (be patient) Server Software: Apache/2.4.41 Server Hostname: xxx.xxx.xxx.xxx Server Port: 443 SSL/TLS Protocol: TLSv1.2,ECDHE-RSA-AES256-GCM-SHA384,2048,256 Server Temp Key: ECDH P-256 256 bits Document Path: / Document Length: 2752 bytes Concurrency Level: 100 Time taken for tests: 18.161 seconds Complete requests: 200 Failed requests: 0 Total transferred: 673980 bytes HTML transferred: 550400 bytes Requests per second: 11.01 [#/sec] (mean) Time per request: 9080.293 [ms] (mean) Time per request: 90.803 [ms] (mean, across all concurrent requests) Transfer rate: 36.24 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 121 3110 1988.8 3232 6819 Processing: 399 4146 2305.7 4267 7368 Waiting: 381 4122 2300.6 4267 7368 Total: 725 7257 2858.7 7942 12789 Percentage of the requests served within a certain time (ms) 50% 7942 66% 8861 75% 9391 80% 9749 90% 10248 95% 10792 98% 11730 99% 12755 100% 12789 (longest request) ```
###### Lambda版 (200Request 100Connection) Requests per second: 107.20 [#/sec] (mean) ``` This is ApacheBench, Version 2.3 <$Revision: 1843412 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking hogefuga.execute-api.ap-northeast-1.amazonaws.com (be patient) Server Software: Server Hostname: hogefuga.execute-api.ap-northeast-1.amazonaws.com Server Port: 443 SSL/TLS Protocol: TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128 Server Temp Key: ECDH P-256 256 bits TLS Server Name: hogefuga.execute-api.ap-northeast-1.amazonaws.com Document Path: /dev/ Document Length: 2426 bytes Concurrency Level: 100 Time taken for tests: 1.866 seconds Complete requests: 200 Failed requests: 0 Total transferred: 674578 bytes HTML transferred: 485200 bytes Requests per second: 107.20 [#/sec] (mean) Time per request: 932.844 [ms] (mean) Time per request: 9.328 [ms] (mean, across all concurrent requests) Transfer rate: 353.10 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 32 111 116.5 56 514 Processing: 39 322 460.9 64 1376 Waiting: 39 322 460.9 64 1376 Total: 74 433 512.1 123 1697 Percentage of the requests served within a certain time (ms) 50% 123 66% 216 75% 590 80% 1159 90% 1309 95% 1505 98% 1565 99% 1627 100% 1697 (longest request) ```
# ある意味当たり前 そもそも応対しているリソース量が全然違う - LambdaのBackendはContainer - Requestに応じてContainerがScaleしている - 激安だけど、クラウド破産気をつけて 
Lambda単体では良い RDSなどのRDBMSへのアクセスを考える
# EC2版 - EC2 - t2.nano (1CPU / 0.5G Memory) - PHP 7.3 - RDS - db.m5.large - PostgreSQL11.2 
# Lambda版 - Lambda - 1CPU / 0.5G Memory - RDS - db.m5.large - PostgreSQL11.2 
###### EC2版 (200Request 100Connection) Requests per second: 8.52 [#/sec] (mean) ``` This is ApacheBench, Version 2.3 <$Revision: 1843412 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking xxx.xxx.xxx.xxx (be patient) Server Software: Apache/2.4.41 Server Hostname: xxx.xxx.xxx.xxx Server Port: 443 SSL/TLS Protocol: TLSv1.2,ECDHE-RSA-AES256-GCM-SHA384,2048,256 Server Temp Key: ECDH P-256 256 bits Document Path: /login Document Length: 4858 bytes Concurrency Level: 100 Time taken for tests: 23.462 seconds Complete requests: 200 Failed requests: 0 Total transferred: 1095170 bytes HTML transferred: 971600 bytes Requests per second: 8.52 [#/sec] (mean) Time per request: 11730.913 [ms] (mean) Time per request: 117.309 [ms] (mean, across all concurrent requests) Transfer rate: 45.58 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 125 2912 2220.0 3382 6340 Processing: 432 6454 3461.5 7721 11613 Waiting: 426 6375 3464.5 7500 11530 Total: 841 9366 3830.3 10394 15339 Percentage of the requests served within a certain time (ms) 50% 10394 66% 11176 75% 12140 80% 12655 90% 13971 95% 14601 98% 14890 99% 15281 100% 15339 (longest request) ```
###### Lambda版 (200Request 100Connection) Requests per second: 96.27 [#/sec] (mean) ``` This is ApacheBench, Version 2.3 <$Revision: 1843412 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking hogefuga.execute-api.ap-northeast-1.amazonaws.com (be patient) Server Software: Server Hostname: hogefuga.execute-api.ap-northeast-1.amazonaws.com Server Port: 443 SSL/TLS Protocol: TLSv1.2,ECDHE-RSA-AES128-GCM-SHA256,2048,128 Server Temp Key: ECDH P-256 256 bits TLS Server Name: hogefuga.execute-api.ap-northeast-1.amazonaws.com Document Path: /dev/login Document Length: 5110 bytes Concurrency Level: 100 Time taken for tests: 2.078 seconds Complete requests: 200 Failed requests: 0 Total transferred: 1211346 bytes HTML transferred: 1022000 bytes Requests per second: 96.27 [#/sec] (mean) Time per request: 1038.778 [ms] (mean) Time per request: 10.388 [ms] (mean, across all concurrent requests) Transfer rate: 569.40 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 19 84 84.4 74 324 Processing: 99 582 284.9 547 1133 Waiting: 99 576 279.4 547 1128 Total: 155 667 256.0 622 1166 Percentage of the requests served within a certain time (ms) 50% 622 66% 726 75% 891 80% 961 90% 1062 95% 1075 98% 1076 99% 1128 100% 1166 (longest request) ```
# Cold Start 良さそう!でも Cold Startに注意 - 初回アクセス時 Container イメージの展開 -> 応答 - 初期動作が遅い - アクセスが無いと消える VPC内に配置する時は顕著になると言われていた - 改善する変更が入ったと報告 - 実際に改善されているように感じる [Announcing improved VPC networking for AWS Lambda functions](https://aws.amazon.com/jp/blogs/compute/announcing-improved-vpc-networking-for-aws-lambda-functions/)
# まとめ ###### パフォーマンス - 動作する速度としては普通のPHPとして使える - Scaleが必要な処理には爆発的な効果を発揮 - cold startに注意 ###### 利便性 - LaravelなどのFrameworkも動くので、普通のPHPとして使える - VPCの中に置けば、RDSなどのRDBMS等と連携して使える - RDSのコネクション問題 - ScalableなDynamoDBの使用も考慮
PHPをServerlessに利用できる事は価値がある ###### 「全てはServerlessになる」そんな未来を信じています カスタムランタイム部分は自己責任! ###### Re:inventで公式PHP来ないかなぁ(来ないだろうなぁ…
# Who? ###### Fusic Co., Ltd.  ###### 清家史郎 ([@seike460](https://twitter.com/seike460))  ###### Evangelist / Engineer ###### FullStack Backend (PHP、Go)
We are Hiring in Fukuoka And Maybe Tokyo! Thank you!  https://fusic.github.io
Swipe to navigate
Previous
Next
Related Slides
PHPで作るWebSocketサーバー
2024/6/1
View
PHPを書く理由、PHPを書いていて良い理由
2024/1/1
View
有効な使い方を正しく理解して実装する PHP8.3の最新機能の「ウラ側」
2023/11/1
View