{"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 \u3084\u3063\u3055\u3093<\/code> \u3067\u3054\u3056\u3044\u307e\u3059\u3002<\/p>\n

\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
\n
AWS\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>\n

Lambda\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

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
\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>\n

CloudWatch Logs Insight\u3092\u5229\u7528\u3057\u305f\u30e1\u30e2\u30ea\u30b5\u30a4\u30ba\u306e\u5206\u6790<\/h4>\n

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

\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

\"\u904e\u5270\u306b\u30d7\u30ed\u30d3\u30b8\u30e7\u30cb\u30f3\u30b0\u3055\u308c\u305f\u30e1\u30e2\u30ea\u30b5\u30a4\u30ba\u3092\u8abf\u3079\u308b\"
\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

\"\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\"<\/p>\n

\u30e1\u30e2\u30ea\u6b8b\u91cf\u304c 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

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
\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>\n

CloudWatch 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

\"Lambda\u306e5\u5206\u9593\u9694\u306e\u30ec\u30a4\u30c6\u30f3\u30b7\u30fc\u7d71\u8a08\u3092\u8abf\u3079\u308b\"<\/p>\n

Lambda\u306e\u5b9f\u884c\u6642\u9593\u306e \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

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

\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

\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\n\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
\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
\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

\u300cCloudWatch Contributor Insights for DynamoDB\u300d\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u3067\u3001
\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