LoginSignup
3
5

More than 3 years have passed since last update.

ALBのターゲットにLambda(VPC)を使った場合、初回アクセスはやはり遅いのか?

Last updated at Posted at 2019-01-16

(2019-09-27 Update)

[発表] Lambda 関数が VPC 環境で改善されます
https://aws.amazon.com/jp/blogs/news/announcing-improved-vpc-networking-for-aws-lambda-functions/

本記事で案内した内容は、上記記事にあるように、随時改善していくものと思われます。

概要

2018/11/30 に、アプリケーションロードバランサー(ALB)のターゲットに AWS Lambda が選択可能になりました。

Lambda を VPC 内で動かす場合、最初のリクエストは VPC 内にアクセスするための ENI の作成処理を含むためレイテンシが大きくなることが知られています。

そこで、ALBでターゲットにした場合も同様のことが起こるか確かめて見たいと思います。

参考資料

こちらの公式サンプルを元に ALB + Lambda の環境を構築して検証します。
https://aws.amazon.com/jp/blogs/news/lambda-functions-as-targets-for-application-load-balancers/

構成

  • ターゲットのヘルスチェックをは実施しません。ヘルスチェックを実行すると、LambdaがInvokeされるので今回はあえて無効にします。
  • ベンチマークには ApacheBench Version 2.3 を使います。
  • 非VPC、VPC(初回)、VPC(2回目)を検証します。 スクリーンショット 2019-01-16 23.45.01.png

比較

Lambda (非VPC)

比較のため、まずは非VPCで実行してみます。

Total 389 msec

$ ab -c 1 -n 1 http://xxxxxxxxxxx.us-east-1.elb.amazonaws.com/
This is ApacheBench, Version 2.3 <$Revision: 1826891 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking xxxxxxxxxxx.us-east-1.elb.amazonaws.com (be patient).....done


Server Software:        awselb/2.0
Server Hostname:        xxxxxxxxxxx.us-east-1.elb.amazonaws.com
Server Port:            80

Document Path:          /
Document Length:        138 bytes

Concurrency Level:      1
Time taken for tests:   0.389 seconds
Complete requests:      1
Failed requests:        0
Non-2xx responses:      1
Total transferred:      288 bytes
HTML transferred:       138 bytes
Requests per second:    2.57 [#/sec] (mean)
Time per request:       389.126 [ms] (mean)
Time per request:       389.126 [ms] (mean, across all concurrent requests)
Transfer rate:          0.72 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:   389  389   0.0    389     389
Waiting:      389  389   0.0    389     389
Total:        389  389   0.0    389     389

Lambda (VPC) 初回

初回アクセス時の結果です。およそ30秒。
非常に時間がかかっています。

Total 29237.875 msec

$ ab -c 1 -n 1 http://xxxxxxxxxxx.us-east-1.elb.amazonaws.com/
This is ApacheBench, Version 2.3 <$Revision: 1826891 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking xxxxxxxxxxx.us-east-1.elb.amazonaws.com (be patient).....done


Server Software:        awselb/2.0
Server Hostname:        xxxxxxxxxxx.us-east-1.elb.amazonaws.com
Server Port:            80

Document Path:          /
Document Length:        138 bytes

Concurrency Level:      1
Time taken for tests:   29.238 seconds
Complete requests:      1
Failed requests:        0
Non-2xx responses:      1
Total transferred:      288 bytes
HTML transferred:       138 bytes
Requests per second:    0.03 [#/sec] (mean)
Time per request:       29237.875 [ms] (mean)
Time per request:       29237.875 [ms] (mean, across all concurrent requests)
Transfer rate:          0.01 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing: 29238 29238   0.0  29238   29238
Waiting:    29238 29238   0.0  29238   29238
Total:      29238 29238   0.0  29238   29238

Lambda (VPC) 2回目

初回実行から30秒後に実行した結果です。
非VPC構成のときとさほど変わらない結果となりました。

Total 395 msec

$ ab -c 1 -n 1 http://xxxxxxxxxxx.us-east-1.elb.amazonaws.com/
This is ApacheBench, Version 2.3 <$Revision: 1826891 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking xxxxxxxxxxx.us-east-1.elb.amazonaws.com (be patient).....done


Server Software:        awselb/2.0
Server Hostname:        xxxxxxxxxxx.us-east-1.elb.amazonaws.com
Server Port:            80

Document Path:          /
Document Length:        138 bytes

Concurrency Level:      1
Time taken for tests:   0.395 seconds
Complete requests:      1
Failed requests:        0
Non-2xx responses:      1
Total transferred:      288 bytes
HTML transferred:       138 bytes
Requests per second:    2.53 [#/sec] (mean)
Time per request:       395.414 [ms] (mean)
Time per request:       395.414 [ms] (mean, across all concurrent requests)
Transfer rate:          0.71 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:   395  395   0.0    395     395
Waiting:      395  395   0.0    395     395
Total:        395  395   0.0    395     395

まとめ

やはり、同じようにVPC内への最初のリクエストは遅くなる結果になりました。

環境 時間(msec)
非VPC 389
VPC(初回) 29,238
VPC(2回目) 395

また、当然ですがVPC内で利用する場合は、以下の情報にも気をつけて、VPC に充分な数の ENI またはサブネット IP を確保する必要があります。

VPC 対応の Lambda 関数をセットアップするためのガイドライン
https://docs.aws.amazon.com/ja_jp/lambda/latest/dg/vpc.html#vpc-setup-guidelines

3
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5