{"id":598,"date":"2019-12-19T08:40:00","date_gmt":"2019-12-18T23:40:00","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2019\/12\/19\/serverless-performance-tuning"},"modified":"2019-12-19T08:40:00","modified_gmt":"2019-12-18T23:40:00","slug":"serverless-performance-tuning","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2019\/12\/19\/serverless-performance-tuning\/","title":{"rendered":"\u3059\u3050\u306b\u59cb\u3081\u3089\u308c\u308bServerless\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0"},"content":{"rendered":"
\u3053\u306e\u8a18\u4e8b\u306fAWS Lambda\u3068Serverless #1 Advent Calendar 2019<\/a>\u306e19\u65e5\u76ee \u3067\u3059<\/p>\n \u30b5\u30f3\u30bf\u306bNintendo Switch<\/strong>\u3092\u304f\u3060\u3055\u3044\u3068\u304a\u9858\u3044\u3057\u305f2\u5150\u306e\u7236 \u3053\u306e\u8a18\u4e8b\u3067\u306f\u3059\u3050\u306b\u59cb\u3081\u3089\u308c\u308bServerless\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0<\/strong>\u3068\u984c\u3057\u307e\u3057\u3066\u3001Lambda, DynamoDB\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3044\u305f\u3057\u307e\u3059\uff01<\/p>\n \u307e\u305f\u3001Serverless\u306e\u76e3\u8996\u306b\u3064\u3044\u3066\u306f\u5f0a\u793e\u4e0b\u689d\u306e\u8a18\u4e8b\u3001 Lambda\u306f\u9069\u5207\u306a\u30e1\u30e2\u30ea\u30b5\u30a4\u30ba\u3092\u6307\u5b9a\u3059\u308c\u3070\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u78ba\u4fdd\u3067\u304d\u307e\u3059\u3002 CloudWatch Logs Insight\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u5b9f\u969b\u306eLambda\u3067\u5b9f\u884c\u3055\u308c\u305f\u30ed\u30b0\u3092\u5206\u6790\u3057\u9069\u5207\u306a\u30e1\u30e2\u30ea\u30b5\u30a4\u30ba\u3092\u78ba\u8a8d\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n <\/p>\n \u30e1\u30e2\u30ea\u6b8b\u91cf\u304c Lambda\u306f\u30e1\u30e2\u30ea\u30b5\u30a4\u30ba\u306b\u6bd4\u4f8b\u3057\u3066CPU\u30d1\u30ef\u30fc\u3082\u5272\u308a\u5f53\u3066\u3089\u308c\u307e\u3059\u3002 <\/p>\n Lambda\u306e\u5b9f\u884c\u6642\u9593\u306e Lambda\u306f\u7121\u9650\u306b\u30b9\u30b1\u30fc\u30eb\u3057\u307e\u3059\u304c\u3001DynamoDB\u306f\u30d7\u30ed\u30d3\u30b8\u30e7\u30cb\u30f3\u30b0\u30aa\u30d7\u30b7\u30e7\u30f3\u306b\u3088\u3063\u3066\u30b9\u30b1\u30fc\u30eb\u65b9\u6cd5\u304c\u7570\u306a\u308a\u307e\u3059\u3002\u3067\u3059\u306e\u3067\u3001\u904b\u7528\u4e2d\u306eDynamoDB\u306e\u30ad\u30e3\u30d1\u30b7\u30c6\u30a3\u30e6\u30cb\u30c3\u30c8\u306f\u30dc\u30c8\u30eb\u30cd\u30c3\u30af\u306b\u306a\u308a\u3084\u3059\u3044\u30dd\u30a4\u30f3\u30c8\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n \u30ef\u30fc\u30af\u30ed\u30fc\u30c9\u306b\u5408\u308f\u305b\u3066\u9069\u5207\u306a\u30d7\u30ed\u30d3\u30b8\u30e7\u30cb\u30f3\u30b0\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u9078\u629e\u3057\u307e\u3059\u3002<\/p>\n \u300cCloudWatch Contributor Insights for DynamoDB\u300d\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u3067\u3001 \u6709\u52b9\u5316\u306fDynamoDB\u306e\u30c6\u30fc\u30d6\u30eb\u6bce\u306b\u884c\u3044\u307e\u3059\u3002 \u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30e1\u30c8\u30ea\u30af\u30b9\u3068\u3057\u3066\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002 \u3053\u308c\u306b\u3088\u308a\u3001 Lambda\u3092\u5229\u7528\u3059\u308b\u5834\u5408\u306f\u3001AWS X-Ray\u306b\u3088\u308b\u30c8\u30ec\u30fc\u30b9\u3092\u3059\u3050\u306b\u6709\u52b9\u5316\u3067\u304d\u307e\u3059\u3002 <\/p>\n X-Ray\u306e\u30c8\u30ec\u30fc\u30b9\u30c7\u30fc\u30bf\u306b\u3088\u308a\u3001\u51e6\u7406\u6642\u9593\u3092\u78ba\u8a8d\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002 Serverless\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0\u3068\u3057\u3066\u3001\u3059\u3050\u306b\u59cb\u3081\u3089\u308c\u308b\u5185\u5bb9\u3092\u7d39\u4ecb\u3044\u305f\u3057\u307e\u3057\u305f\u3002\u3082\u3061\u308d\u3093\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0\u306e\u65b9\u6cd5\u306f\u3053\u308c\u3089\u3060\u3051\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u4f8b\u3048\u3070\u3001 \u5c11\u3057\u3067\u3082\u304a\u5f79\u306b\u7acb\u3064\u60c5\u5831\u3092\u63d0\u4f9b\u3092\u51fa\u6765\u3066\u3044\u308c\u3070\u5e78\u3044\u3067\u3059\u3002<\/p>\n \u305c\u3072\u4ee5\u4e0b\u306e\u30da\u30fc\u30b8\u3082\u5408\u308f\u305b\u3066\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n\u3084\u3063\u3055\u3093<\/code> \u3067\u3054\u3056\u3044\u307e\u3059\u3002<\/p>\n
\nAWS\u30b5\u30fc\u30d0\u30fc\u30ec\u30b9\u30b7\u30b9\u30c6\u30e0\u306b\u304a\u3051\u308b\u76e3\u8996\u306e\u30b3\u30c4<\/a>\u3082\u3054\u53c2\u7167\u3044\u305f\u3060\u3051\u308c\u3070\u3068\u601d\u3044\u307e\u3059\uff01<\/p>\nLambda\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0<\/h2>\n
Lambda\u306e\u30e1\u30e2\u30ea\u30b5\u30a4\u30ba<\/h3>\n
\n\u3057\u304b\u3057\u306a\u304c\u3089\u3001\u5168\u3066\u306eLambda\u3092\u6700\u5927\u30e1\u30e2\u30ea\u30b5\u30a4\u30ba\u3067\u5229\u7528\u3059\u308b\u3053\u3068\u306f\u30b3\u30b9\u30c8\u306e\u5897\u52a0\u306b\u7e4b\u304c\u308a\u307e\u3059\u3002\u3067\u306f\u3001\u3069\u306e\u3088\u3046\u306b\u3057\u3066\u9069\u5207\u306a\u30e1\u30e2\u30ea\u30b5\u30a4\u30ba\u3092\u6e2c\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\nCloudWatch Logs Insight\u3092\u5229\u7528\u3057\u305f\u30e1\u30e2\u30ea\u30b5\u30a4\u30ba\u306e\u5206\u6790<\/h4>\n
\u904e\u5270\u306b\u30d7\u30ed\u30d3\u30b8\u30e7\u30cb\u30f3\u30b0\u3055\u308c\u305f\u30e1\u30e2\u30ea\u30b5\u30a4\u30ba\u3092\u8abf\u3079\u308b\u30af\u30a8\u30ea\u306e\u4f8b<\/h5>\n
filter @type = "REPORT"\n| stats max(@memorySize \/ 1024 \/ 1024) as provisonedMemoryMB,\n min(@maxMemoryUsed \/ 1024 \/ 1024) as smallestMemoryRequestMB,\n avg(@maxMemoryUsed \/ 1024 \/ 1024) as avgMemoryUsedMB,\n max(@maxMemoryUsed \/ 1024 \/ 1024) as maxMemoryUsedMB,\n provisonedMemoryMB - maxMemoryUsedMB as overProvisionedMB<\/code><\/pre>\n
\n923MB\u306e overProvisionedMB<\/code> \u304c\u78ba\u8a8d\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n
\u30d7\u30ed\u30d3\u30b8\u30e7\u30cb\u30f3\u30b0\u3055\u308c\u305f\u30e1\u30e2\u30ea\u30b5\u30a4\u30ba\u304c\u5c11\u306a\u3044Lambda\u3092\u8abf\u3079\u308b\u30af\u30a8\u30ea\u306e\u4f8b<\/h4>\n
filter @type = "REPORT"\n| fields (@memorySize \/ 1024 \/ 1024) as memorySize, (@maxMemoryUsed \/ 1024 \/ 1024) as maxMemoryUsed, memorySize - maxMemoryUsed as RemainingMemorySize, @logStream, @message\n# \u30e1\u30e2\u30ea\u6b8b\u91cf\u304c50MB\u3092\u5207\u3063\u3066\u3044\u308b\u5b9f\u884c\u3092\u62bd\u51fa\n| filter RemainingMemorySize < 50\n| stats count(*)<\/code><\/pre>\n
50MB<\/code> \u3092\u4e0b\u56de\u3063\u3066\u3044\u308b\u5b9f\u884c\u56de\u6570\u3092\u78ba\u8a8d\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n
Lambda\u306e\u51e6\u7406\u6642\u9593<\/h3>\n
\n\u3067\u3059\u306e\u3067\u3001\u30e1\u30e2\u30ea\u6d88\u8cbb\u304c\u5c11\u306a\u3044\u304b\u3089\u3068\u30e1\u30e2\u30ea\u30b5\u30a4\u30ba\u3092\u4e0b\u3052\u307e\u3059\u3068\u3001CPU\u30d1\u30ef\u30fc\u3082\u4e0b\u304c\u3063\u3066\u3057\u307e\u3046\u3068\u3053\u308d\u304cLambda\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u30c1\u30e5\u30fc\u30cb\u30f3\u30b0\u306e\u96e3\u3057\u3044\u3068\u3053\u308d\u3060\u3068\u601d\u3044\u307e\u3059\u3002\u3053\u308c\u306b\u3064\u3044\u3066\u3082\u3001CloudWatch Logs Insight\u3092\u5229\u7528\u3057\u3066\u5206\u6790\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\nCloudWatch Logs Insight\u3092\u5229\u7528\u3057\u305f\u51e6\u7406\u6642\u9593\u306e\u5206\u6790<\/h3>\n
Lambda\u306e5\u5206\u9593\u9694\u306e\u30ec\u30a4\u30c6\u30f3\u30b7\u30fc\u7d71\u8a08\u3092\u8abf\u3079\u308b<\/h4>\n
filter @type = "REPORT"\n| stats avg(@duration), max(@duration), min(@duration) by bin(5m)<\/code><\/pre>\n
\u5e73\u5747<\/code> \u3001
\u6700\u5927<\/code> \u3001
\u6700\u5c0f<\/code> \u6642\u9593\u3092\u78ba\u8a8d\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n
DynamoDB<\/h2>\n
DynamoDB\u306e\u30d7\u30ed\u30d3\u30b8\u30e7\u30cb\u30f3\u30b0\u30aa\u30d7\u30b7\u30e7\u30f3<\/h3>\n
\u904b\u7528\u3059\u308b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306b\u5408\u308f\u305b\u3066\u30d7\u30ed\u30d3\u30b8\u30e7\u30cb\u30f3\u30b0\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u6307\u5b9a\u3059\u308b<\/h4>\n
\n\n
\n \n\u30e2\u30fc\u30c9<\/th>\n \u6700\u9069\u306a\u30b1\u30fc\u30b9<\/th>\n \u9069\u7528\u4f8b<\/th>\n<\/tr>\n<\/thead>\n \n \u30aa\u30f3\u30c7\u30de\u30f3\u30c9\u30e2\u30fc\u30c9<\/td>\n \u30fb\u672a\u77e5\u306e\u30ef\u30fc\u30af\u30ed\u30fc\u30c9
\u30fb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30c8\u30e9\u30d5\u30a3\u30c3\u30af\u304c\u4e88\u6e2c\u3067\u304d\u306a\u3044\u3002<\/td>\n\u30fb\u30b9\u30d1\u30a4\u30af\u30a2\u30af\u30bb\u30b9\u304c\u767a\u751f\u3059\u308b\u30ef\u30fc\u30af\u30ed\u30fc\u30c9
\u30fb\u666e\u6bb5\u306f\u983b\u7e41\u306b\u5229\u7528\u3055\u308c\u306a\u3044\u958b\u767a\u30ef\u30fc\u30af\u30ed\u30fc\u30c9<\/td>\n<\/tr>\n\n \u30d7\u30ed\u30d3\u30b8\u30e7\u30f3\u30c9\u30e2\u30fc\u30c9<\/td>\n \u30fb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30c8\u30e9\u30d5\u30a3\u30c3\u30af\u304c\u4e88\u6e2c\u3067\u304d\u308b
\u30fb\u30c8\u30e9\u30d5\u30a3\u30c3\u30af\u304c\u4e00\u5b9a\u307e\u305f\u306f\u5f90\u3005\u306b\u5909\u5316\u3059\u308b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\u3059\u308b\u3002<\/td>\n\u30fb\u30b9\u30d1\u30a4\u30af\u30a2\u30af\u30bb\u30b9\u304c\u767a\u751f\u3057\u306a\u3044\u4e00\u5b9a\u306e\u30ef\u30fc\u30af\u30ed\u30fc\u30c9<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n Contributor Insights\u306b\u3088\u308b\u983b\u7e41\u306b\u5229\u7528\u3055\u308c\u308b\u30af\u30a8\u30ea\u306e\u78ba\u8a8d<\/h3>\n
\n\u4ee5\u4e0b\u306e\u30eb\u30fc\u30eb\u304c\u4f5c\u6210\u3055\u308c\u3001\u8996\u899a\u5316\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<\/p>\n\n
Contributor Insights for DynamoDB\u306e\u6709\u52b9\u5316<\/h4>\n
\n<\/p>\n
\n<\/p>\n\u30b9\u30ed\u30c3\u30c8\u30ea\u30f3\u30b0\u3055\u308c\u305f\u9805\u76ee<\/code> \u3092\u78ba\u8a8d\u3057\u30dc\u30c8\u30eb\u30cd\u30c3\u30af\u3092\u8abf\u67fb\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n
AWS X-Ray\u306b\u3088\u308bE2E\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306e\u78ba\u8a8d<\/h2>\n
\n<\/p>\n
\n\u307e\u305f\u3001API Gateway\u306e\u30c8\u30ec\u30fc\u30b9\u30c7\u30fc\u30bf\u3082\u6709\u52b9\u5316\u3059\u308b\u3053\u3068\u3067API Gateway\u306e\u30ec\u30a4\u30c6\u30f3\u30b7\u30fc\u3082\u6e2c\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<\/p>\n\u304a\u308f\u308a\u306b<\/h2>\n
DataDog<\/code> \u306a\u3069\u306eSaaS\u3092\u5229\u7528\u3057\u3066\u5f97\u3089\u308c\u305f\u60c5\u5831\u304b\u3089\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u78ba\u8a8d\u3059\u308b\u624b\u6cd5\u3082\u3054\u3056\u3044\u307e\u3059\u3002<\/p>\n