[{"data":1,"prerenderedAt":399},["ShallowReactive",2],{"content-svc-lambda-guides-effectively-running-java-on-serverless-challenge":3},{"markdown":4,"frontMatterAttributes":5,"bodyRaw":11,"menu":12,"menuType":390,"isCollapseableMenu":15,"nextDocItem":59,"previousDocItem":44,"contributorPaths":391,"contentName":398,"slug":55,"readingTime":29},"\u003Cp>Java was built with a notion of running a server all the time.\nWith serverless computing like AWS Lambda, that is not the case anymore, as they offer ephemeral compute.\nTherefore, we see some churn when running Java applications on Serverless.\u003C\u002Fp>\n\u003Cp>In AWS Lambda, when a request comes in, the service checks if an execution environment is ready and available.\nIf available, the service assigns the request to that execution environment and the code in the Lambda function \nhandler gets executed.\nThis is termed as a &quot;Warm Start&quot; as the execution environment was already available and warm.\nHowever, if an execution environment is not available, for example,\nthe first request coming in, the service allocates a new\nexecution environment.\nThis involves downloading the Lambda function code to the execution environment, starting the runtime, \ninitializing the function code, and then executing the code.\nThis results in longer than normal response time and is termed as a “Cold Start.” \u003C\u002Fp>\n\u003Cp>\u003Cimg src=\"\u002Fassets\u002Fexternal\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Fassets\u002Fchallenge_cold_start.png\" alt=\"ChallengeColdStart\">\u003C\u002Fp>\n\u003Cp>Java frameworks like Spring Boot often perform expensive operations during initial JVM startup time.\nTherefore, we witness a longer cold start time than any other Lambda runtime.\u003C\u002Fp>\n\u003Cp>A \u003Ca href=\"https:\u002F\u002Fdocs.aws.amazon.com\u002Flambda\u002Flatest\u002Fdg\u002Flambda-runtime-environment.html\">Lambda execution environment\u003C\u002Fa> \nsupports only one request at a time.\nAn execution environment processes a single request at the same time. \nWhile a single execution environment is processing a request, it cannot process other requests.\nTherefore, for another request a new execution environment will be needed,\nand therefore going through the initialization process again. \u003C\u002Fp>\n\u003Cp>\u003Cimg src=\"\u002Fassets\u002Fexternal\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Fassets\u002Fchallenge.png\" alt=\"Challenge\">\u003C\u002Fp>\n\u003Cp>There are some interesting projects like \u003Ca href=\"https:\u002F\u002Fopenjdk.org\u002Fprojects\u002Fcrac\u002F\">Project CRaC\u003C\u002Fa> \nand \u003Ca href=\"https:\u002F\u002Fopenjdk.org\u002Fprojects\u002Fleyden\u002F\">Project Leyden\u003C\u002Fa> \nthat you can follow which aims to address some of those challenges.\u003C\u002Fp>\n\u003Cp>Meanwhile, there are best practices and built-in capabilities which AWS Lambda provides that you can incorporate\nto reduce cold start times compared to running on server-based compute options.\u003C\u002Fp>\n",{"title":6,"order":7,"authors":8},"Challenges",5,[9,10],"Dhiraj Mahapatro","Maximilian Schellhorn","Java was built with a notion of running a server all the time.\nWith serverless computing like AWS Lambda, that is not the case anymore, as they offer ephemeral compute.\nTherefore, we see some churn when running Java applications on Serverless.\n\nIn AWS Lambda, when a request comes in, the service checks if an execution environment is ready and available.\nIf available, the service assigns the request to that execution environment and the code in the Lambda function \nhandler gets executed.\nThis is termed as a \"Warm Start\" as the execution environment was already available and warm.\nHowever, if an execution environment is not available, for example,\nthe first request coming in, the service allocates a new\nexecution environment.\nThis involves downloading the Lambda function code to the execution environment, starting the runtime, \ninitializing the function code, and then executing the code.\nThis results in longer than normal response time and is termed as a “Cold Start.” \n\n![ChallengeColdStart](\u002Fassets\u002Fexternal\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Fassets\u002Fchallenge_cold_start.png)\n\nJava frameworks like Spring Boot often perform expensive operations during initial JVM startup time.\nTherefore, we witness a longer cold start time than any other Lambda runtime.\n\nA [Lambda execution environment](https:\u002F\u002Fdocs.aws.amazon.com\u002Flambda\u002Flatest\u002Fdg\u002Flambda-runtime-environment.html) \nsupports only one request at a time.\nAn execution environment processes a single request at the same time. \nWhile a single execution environment is processing a request, it cannot process other requests.\nTherefore, for another request a new execution environment will be needed,\nand therefore going through the initialization process again. \n\n![Challenge](\u002Fassets\u002Fexternal\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Fassets\u002Fchallenge.png)\n\nThere are some interesting projects like [Project CRaC](https:\u002F\u002Fopenjdk.org\u002Fprojects\u002Fcrac\u002F) \nand [Project Leyden](https:\u002F\u002Fopenjdk.org\u002Fprojects\u002Fleyden\u002F) \nthat you can follow which aims to address some of those challenges.\n\nMeanwhile, there are best practices and built-in capabilities which AWS Lambda provides that you can incorporate\nto reduce cold start times compared to running on server-based compute options.\n",[13,33,56,185,238,295,311,350,372],{"title":14,"collapsible":15,"isCollapsed":16,"content":17},"Introduction",false,true,[18],{"title":19,"order":20,"authors":21,"callout":22,"prerequisite":26,"time":29,"path":30,"id":31,"link":32},"Getting Started",1,[9],{"title":23,"description":24,"link":25},"Watch this video","This Devoxx Belgium 2023 presentation shows effectively running Java on Serverless","https:\u002F\u002Fyoutu.be\u002Fu3tgOE8qFjI?t=5549",[27,28],"Understanding of Java","Understanding of AWS Lambda","2 min","1-introduction","1-introduction.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002F1-introduction",{"title":34,"collapsible":15,"isCollapsed":15,"content":35},"History",[36,44,51],{"title":37,"order":38,"authors":39,"time":40,"path":41,"id":42,"link":43},"Evolution of Java",3,[9],"1 min","history","history.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Fhistory",{"title":45,"order":46,"authors":47,"time":29,"path":48,"id":49,"link":50},"Evolution of Compute",4,[9],"compute","compute.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Fcompute",{"title":6,"order":7,"authors":52,"time":29,"path":53,"id":54,"link":55},[9,10],"challenge","challenge.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Fchallenge",{"title":57,"collapsible":15,"isCollapsed":16,"content":58},"Best Practices",[59,77,87,93,110,127,145,161,175],{"title":60,"order":61,"youtubeVideoID":62,"authors":63,"callout":65,"resources":68,"time":73,"path":74,"id":75,"link":76},"Lambda Snapstart",6,"ZbnAithBNYY",[64,9],"Vipan Kumar",{"title":23,"description":66,"link":67},"This serverless office hours session dives deeper into Lambda SnapStart.","https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=Y5b8_KToeDY",[69],{"link":70,"text":71,"type":72},"https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=IIKe2dx9Ag0","Spring IO (Barcelona)","video","8 min","snapstart","snapstart.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Fsnapstart",{"title":78,"order":61,"authors":79,"callout":80,"time":40,"path":84,"id":85,"link":86},"Tiered Compilation",[64],{"title":81,"description":82,"link":83},"Read this blog","This AWS blog explains Tiered compilation in details","https:\u002F\u002Faws.amazon.com\u002Fblogs\u002Fcompute\u002Fincreasing-performance-of-java-aws-lambda-functions-using-tiered-compilation\u002F","tiered-compilation","tiered-compilation.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Ftiered-compilation",{"title":88,"order":61,"authors":89,"time":40,"path":90,"id":91,"link":92},"Utilize initialization phase",[9],"init-heavy-lifting","init-heavy-lifting.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Finit-heavy-lifting",{"title":94,"order":61,"authors":95,"youtubeVideoID":97,"resources":98,"time":106,"path":107,"id":108,"link":109},"Using RDS Proxy",[96,9],"Sonali Jena","ZQOqmMn_8jw",[99,103],{"link":100,"text":101,"type":102},"https:\u002F\u002Faws.amazon.com\u002Fgetting-started\u002Fhands-on\u002Fset-up-shared-database-connection-amazon-rds-proxy\u002F","Shared DB connections with RDS Proxy","user guide",{"link":104,"type":102,"text":105},"https:\u002F\u002Fdocs.aws.amazon.com\u002FAmazonRDS\u002Flatest\u002FAuroraUserGuide\u002Frds-proxy.html","RDS Proxy","4 min","rds-proxy","rds-proxy.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Frds-proxy",{"title":111,"order":61,"authors":112,"callout":113,"prerequisite":117,"resources":119,"time":29,"path":124,"id":125,"link":126},"Choice of HTTP Clients",[64,9],{"title":114,"description":115,"link":116},"Read this Blog","This blog explains how AWS CRT HTTP Client offers faster startup time and small memory footprint","https:\u002F\u002Faws.amazon.com\u002Fblogs\u002Fdeveloper\u002Fannouncing-availability-of-the-aws-crt-http-client-in-the-aws-sdk-for-java-2-x\u002F",[118],"Before moving on to HTTP clients, the first and foremost requirement to improve performance in Lambda functions is to upgrade from AWS SDK Java v1 to AWS SDK Java v2 as soon as possible. Version 2 of the AWS SDK was released in Nov 2018 with a lot of performance upgrades.",[120],{"link":121,"type":122,"text":123},"https:\u002F\u002Faws.amazon.com\u002Fblogs\u002Fdeveloper\u002Faws-sdk-for-java-2-x-released\u002F","blog","AWS SDK for Java v2","http-clients","http-clients.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Fhttp-clients",{"title":128,"order":61,"authors":129,"youtubeVideoID":130,"resources":131,"time":106,"path":142,"id":143,"link":144},"Hexagonal Architecture",[64],"kRFg6fkVChQ",[132,136,139],{"link":133,"text":134,"type":135},"https:\u002F\u002Fdocs.aws.amazon.com\u002Fprescriptive-guidance\u002Flatest\u002Fhexagonal-architectures\u002Fwelcome.html","Hexagonal architecture","guidance",{"link":137,"text":138,"type":122},"https:\u002F\u002Faws.amazon.com\u002Fblogs\u002Fcompute\u002Fdeveloping-portable-aws-lambda-functions\u002F","Portable Lambda functions",{"link":140,"type":122,"text":141},"https:\u002F\u002Faws.amazon.com\u002Fblogs\u002Fcompute\u002Fdeveloping-evolutionary-architecture-with-aws-lambda\u002F","Building evolutionary architecture on AWS Lambda","hexagonal","hexagonal.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Fhexagonal",{"title":146,"order":61,"authors":147,"youtubeVideoID":149,"resources":150,"time":29,"path":158,"id":159,"link":160},"Powertools for AWS Lambda",[148],"Lavanya Tangutur","dH2GP6Lydj8",[151,155],{"link":152,"text":153,"type":154},"https:\u002F\u002Fgithub.com\u002Faws-powertools\u002Fpowertools-lambda-java","Powertools for AWS Lambda (Java)","github",{"link":156,"type":122,"text":157},"https:\u002F\u002Faws.amazon.com\u002Fblogs\u002Fopensource\u002Fsimplifying-serverless-best-practices-with-aws-lambda-powertools-java\u002F","Best practices with Powertools","powertools","powertools.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Fpowertools",{"title":162,"order":61,"authors":163,"youtubeVideoID":164,"callout":165,"resources":169,"time":40,"path":172,"id":173,"link":174},"Lambda Power tuning ",[148,9],"z8wGSykEauI",{"title":166,"description":167,"link":168},"Watch the video","This video covers a variety of AWS Lambda performance and cost optimization techniques including use of Power tuning.","https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=z8wGSykEauI",[170,171],{"link":100,"text":101,"type":102},{"link":104,"type":102,"text":105},"powertuning","powertuning.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Fpowertuning",{"title":176,"order":61,"authors":177,"resources":178,"time":29,"path":182,"id":183,"link":184},"Using Graviton2",[9],[179],{"link":180,"text":181,"type":122},"https:\u002F\u002Faws.amazon.com\u002Fblogs\u002Fcompute\u002Fmigrating-aws-lambda-functions-to-arm-based-aws-graviton2-processors\u002F","Using Arm-based Graviton2 processors","graviton","graviton.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Fgraviton",{"title":186,"collapsible":15,"isCollapsed":16,"content":187},"Java frameworks",[188,203,212,228],{"title":189,"order":190,"authors":191,"resources":192,"time":29,"path":200,"id":201,"link":202},"Micronaut",7,[148,9],[193,197],{"link":194,"text":195,"type":196},"https:\u002F\u002Fgithub.com\u002Faws-samples\u002Fserverless-java-frameworks-samples\u002Ftree\u002Fmain","Serverless Java Frameworks","GitHub",{"link":198,"text":199,"type":196},"https:\u002F\u002Fgithub.com\u002Faws-samples\u002Fserverless-patterns\u002Ftree\u002Fmain\u002Fapigw-lambda-rds-snapstart","Micronaut with RDS","micronaut","micronaut.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Fmicronaut",{"title":204,"order":190,"authors":205,"resources":206,"time":29,"path":209,"id":210,"link":211},"Quarkus",[148,9],[207],{"link":194,"text":208,"type":196},"Quarkus sample application","quarkus","quarkus.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Fquarkus",{"title":213,"order":190,"authors":214,"resources":215,"time":106,"path":225,"id":226,"link":227},"Spring",[148,10],[216,217,221],{"link":194,"text":208,"type":196},{"link":218,"text":219,"type":220},"https:\u002F\u002Fcatalog.workshops.aws\u002Fjava-on-aws-lambda\u002Fen-US","Java on AWS Lambda","workshop",{"link":222,"text":223,"type":224},"https:\u002F\u002Faws.amazon.com\u002Fblogs\u002Fdevops\u002Fdeveloping-with-java-and-spring-boot-using-amazon-codewhisperer\u002F","Build Spring Boot using Amazon CodeWhisperer","Blog","springboot","springboot.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Fspringboot",{"title":229,"order":190,"authors":230,"resources":231,"time":29,"path":235,"id":236,"link":237},"GraalVM Native Image",[148,9],[232,234],{"link":194,"text":233,"type":196},"GraalVM sample application",{"link":218,"text":219,"type":220},"graalvm","graalvm.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Fgraalvm",{"title":239,"collapsible":15,"isCollapsed":16,"content":240},"Testing a Java application",[241,258,267,277,286],{"title":242,"order":243,"authors":244,"callout":246,"resources":250,"time":254,"path":255,"id":256,"link":257},"Testing Serverless",8,[245],"Lorenzo Micheli",{"title":247,"description":248,"link":249},"Read the Serverless testing guide","This guide dives deeper into Serverless testing","https:\u002F\u002Fserverlessland.com\u002Ftesting",[251],{"link":252,"text":253,"type":196},"https:\u002F\u002Fgithub.com\u002Faws-samples\u002Fserverless-test-samples\u002Ftree\u002Fmain\u002Fjava-test-samples","Serverless Java test samples","3 min","testing","testing.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Ftesting",{"title":259,"order":243,"authors":260,"callout":261,"resources":262,"time":106,"path":264,"id":265,"link":266},"Unit Testing",[245],{"title":247,"description":248,"link":249},[263],{"link":252,"text":253,"type":196},"unit","unit.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Funit",{"title":268,"order":243,"authors":269,"callout":270,"resources":271,"time":273,"path":274,"id":275,"link":276},"Integration Testing",[245,9],{"title":247,"description":248,"link":249},[272],{"link":252,"text":253,"type":196},"5 min","integration","integration.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Fintegration",{"title":278,"order":243,"authors":279,"callout":280,"resources":281,"time":254,"path":283,"id":284,"link":285},"Functional Testing",[245,9],{"title":247,"description":248,"link":249},[282],{"link":252,"text":253,"type":196},"functional","functional.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Ffunctional",{"title":287,"order":243,"authors":288,"callout":289,"resources":290,"time":29,"path":292,"id":293,"link":294},"Load Testing",[9],{"title":247,"description":248,"link":249},[291],{"link":252,"text":253,"type":196},"load","load.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Fload",{"title":296,"collapsible":15,"isCollapsed":16,"content":297},"Local Development",[298,305],{"title":299,"order":300,"authors":301,"time":40,"path":302,"id":303,"link":304},"IntelliJ",10,[9],"intellij","intellij.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Fintellij",{"title":306,"order":300,"authors":307,"time":40,"path":308,"id":309,"link":310},"Visual Studio Code",[9],"vscode","vscode.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Fvscode",{"title":312,"collapsible":15,"isCollapsed":16,"content":313},"Infrastructure as Code",[314,321,327,337],{"title":315,"order":316,"authors":317,"time":29,"path":318,"id":319,"link":320},"CloudFormation",9,[96],"cloudformation","cloudformation.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Fcloudformation",{"title":322,"order":316,"authors":323,"time":273,"path":324,"id":325,"link":326},"AWS CDK",[96],"cdk","cdk.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Fcdk",{"title":328,"order":316,"authors":329,"resources":330,"time":29,"path":334,"id":335,"link":336},"AWS SAM",[96],[331],{"link":332,"text":333,"type":122},"https:\u002F\u002Faws.amazon.com\u002Fblogs\u002Fcompute\u002Fbuilding-serverless-java-applications-with-the-aws-sam-cli\u002F","Java Serverless AWS SAM CLI","sam","sam.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Fsam",{"title":338,"order":316,"authors":339,"resources":340,"time":29,"path":347,"id":348,"link":349},"Terraform",[9],[341,344],{"link":342,"type":196,"text":343},"https:\u002F\u002Fgithub.com\u002Faws-samples\u002Fserverless-patterns\u002Ftree\u002Fmain\u002Fapigw-lambda-snapstart-terraform","Java sample with Terraform",{"link":345,"text":346,"type":102},"https:\u002F\u002Fdocs.aws.amazon.com\u002Fserverless-application-model\u002Flatest\u002Fdeveloperguide\u002Fwhat-is-terraform-support.html","AWS SAM CLI Terraform support","terraform","terraform.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Fterraform",{"title":351,"collapsible":15,"isCollapsed":16,"content":352},"Benchmarking",[353],{"title":354,"order":355,"youtubeVideoID":356,"authors":357,"resources":358,"time":40,"path":369,"id":370,"link":371},"Performance Benchmarking",11,"wmEIMWigXGc",[9],[359,361,363,366],{"link":360,"text":219,"type":220},"https:\u002F\u002Fcatalog.workshops.aws\u002Fjava-on-aws-lambda\u002Fen-US\u002F01-migration\u002F02-optimizations\u002Fbenchmark",{"link":194,"text":362,"type":196},"Benchmark: Micronaut, Quarkus, and SpringBoot",{"link":364,"text":365,"type":196},"https:\u002F\u002Fgithub.com\u002Faws-samples\u002Fserverless-graalvm-demo","GraalVM native image on AWS Lambda Benchmarking",{"link":367,"text":368,"type":196},"https:\u002F\u002Fgithub.com\u002Faws-samples\u002Fserverless-kotlin-demo","Benchmark Kotlin on Serverless","benchmark","benchmark.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Fbenchmark",{"title":373,"collapsible":15,"isCollapsed":16,"content":374},"Migration",[375],{"title":376,"order":377,"authors":378,"youtubeVideoID":379,"resources":380,"time":40,"path":387,"id":388,"link":389},"Migration Guide",12,[9],"u3tgOE8qFjI",[381,385],{"link":382,"text":383,"type":384},"https:\u002F\u002Fserverlessland.com\u002Fcontent\u002Fservice\u002Flambda\u002Fpaved-path\u002Fjava-replatforming\u002Fintroduction","Java re-platforming guide","Guide",{"link":218,"text":219,"type":386},"Workshop","migration","migration.md","\u002Fcontent\u002Fservice\u002Flambda\u002Fguides\u002Feffectively-running-java-on-serverless\u002Fmigration","LIST",[392,393,394,395,396,397],"content\u002Fcontributors\u002Fdhiraj-mahapatro.json","content\u002Fcontributors\u002Fsonali-jena.json","content\u002Fcontributors\u002Flavanya-tangutur.json","content\u002Fcontributors\u002Fvipan-kumar.json","content\u002Fcontributors\u002Florenzo-micheli.json","content\u002Fcontributors\u002Fmaximilian-schellhorn.json","Effectively running Java on Serverless",1792578873331]