搜索
首页Javajava教程AWS SnapStart - Part Measuring cold and warm starts with Java using different garbage collection algorithms

AWS SnapStart - Part Measuring cold and warm starts with Java using different garbage collection algorithms

Introduction

In the previous parts of our series, we measured the cold starts of the Lambda function with Java 21 runtime without SnapStart enabled, with SnapStart enabled and also applied DynamoDB invocation priming optimization with different Lambda memory settings, Lambda deployment artifact sizes, Java compilation options, (a)synchronous HTTP clients and the usage of different Lambda layers. For all these measurements we used default garbage collection algorithms G1.

In this article we'd like to explore the impact of Java garbage collection algorithms on the performance of the Lambda function with Java 21 runtime. We'll also re-measure everything for the G1 to have comparable results with the same minor Java 21 version in use for all garbage collection algorithms.

Java Garbage collection algorithms

For our measurements we'll use the following Java collection algorithms with their default setting (please refer to the linked documentation for more detailed information about each algorithm):

  • Garbage-First (G1) Garbage Collector. This is the garbage collection algorithm used by default. You can set it explicitly in AWS SAM template by adding -XX:+UseG1GC to the JAVA_TOOL_OPTIONS environment variable.
  • The Parallel Collector. You can set it explicitly in AWS SAM template by adding -XX:+UseParallelGC to the JAVA_TOOL_OPTIONS environment variable.
  • Shenandoah GC. Oracle JDK doesn't provide it, but Amazon Corretto 21 JDK does. You can set it explicitly in AWS SAM template by adding -XX:+UseShenandoahGC to the JAVA_TOOL_OPTIONS environment variable.
  • The Z Garbage Collector. There are 2 different ZGC algorithms: default and the newer one- generational. You can set it explicitly in AWS SAM template by adding -XX:+UseZGC or -XX:+UseZGC -XX:+ZGenerational to the JAVA_TOOL_OPTIONS environment variable.

Measuring cold and warm starts with Java 21 using different garbage collection algorithms

In our experiment we'll use slightly modified application introduced in part 9. You can the find application code here. There are basically 2 Lambda functions which both respond to the API Gateway requests and retrieve product by id received from the API Gateway from DynamoDB. One Lambda function GetProductByIdWithPureJava21LambdaWithGCAlg can be used with and without SnapStart and the second one GetProductByIdWithPureJava21LambdaAndPrimingWithGCAlg uses SnapStart and DynamoDB request invocation priming.

The results of the experiment below were based on reproducing more than 100 cold and approximately 100.000 warm starts with experiment which ran for approximately 1 hour. For it (and experiments from my previous article) I used the load test tool hey, but you can use whatever tool you want, like Serverless-artillery or Postman. We run experiments by giving Lambda functions 1024 MB memory and using JAVA_TOOL_OPTIONS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1" (Java client compilation without profiling) which has a very good trade off between cold and warm start times.

Unfortunately I couldn't make Lambda function start with The Z Garbage Collector (with both default and generational one) running into the error :

Failed to commit memory (Operation not permitted)
[error][gc] Forced to lower max Java heap size from 872M(100%) to 0M(0%)
[error][gc] Failed to allocate initial Java heap (512M)
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

It tried out bigger memory setting as 1024 like 2048 MB and even more MBs, but the same error still appeared.

Let's look into the results of our measurements with other 3 garbage collection algorithms.

Abbreviation c is for the cold start and w is for the warm start.

Cold (c) and warm (w) start time without SnapStart enabled in ms:

GC Algorithm c p50 c p75 c p90 c p99 c p99.9 c max w p50 w p75 w p90 w p99 w p99.9 w max
G1 3655.17 3725.25 3811.88 4019.25 4027.30 4027.83 5.46 6.10 7.10 16.79 48.06 1929.79
Parallel Collector 3714.10 3789.09 3857.87 3959.44 4075.89 4078.25 5.55 6.20 7.10 15.38 130.13 2017.92
Shenandoah 3963.40 4019.25 4096.30 4221.00 4388.78 4390.76 5.82 6.45 7.39 17.06 71.02 2159.21

Cold (c) and warm (w) start time with SnapStart enabled without Priming in ms:

GC Algorithm c p50 c p75 c p90 c p99 c p99.9 c max w p50 w p75 w p90 w p99 w p99.9 w max
G1 1867.27 1935.68 2152.02 2416.57 2426.25 2427.35 5.47 6.11 7.05 17.41 51.24 1522.04
Parallel Collector 1990.62 2047.12 2202.07 2402.12 2418.99 2419.32 5.68 6.35 7.45 18.04 147.83 1577.21
Shenandoah 2195.47 2301.07 2563.37 3004.89 3029.01 3030.36 5.73 6.41 7.51 17.97 75.00 1843.34

Cold (c) and warm (w) start time with SnapStart enabled and with DynamoDB invocation Priming in ms:

GC Algorithm c p50 c p75 c p90 c p99 c p99.9 c max w p50 w p75 w p90 w p99 w p99.9 w max
G1 833.50 875.34 1089.53 1205.26 1269.56 1269.8 5.46 6.10 7.16 16.39 46.19 499.13
Parallel Collector 900.18 975.12 1058.41 1141.94 1253.17 1253.99 5.82 6.61 7.75 16.87 49.64 487.73
Shenandoah 1065.84 1131.71 1331.96 1473.44 1553.59 1554.95 5.77 6.40 7.39 17.20 65.06 500.48

Conclusion

In this article we explored the impact of Java garbage collection algorithms (G1, Parallel Collector and Shenandoah) on the performance of the Lambda function with Java 21 runtime. We saw quite a bit of a difference between the performance of those algorithms. Using the default settings with G1 (default one) we experience ( sometimes by far) the lowest cold and warm start times. By using SnapStart with priming of the DynamoDB request the performance results are as expected much closer to each other.

Please refer to the documentation of each garbage collection algorithm to tune settings like mix and max memory which can provide significant improvement in performance and do your own measurements.

以上是AWS SnapStart - Part Measuring cold and warm starts with Java using different garbage collection algorithms的详细内容。更多信息请关注PHP中文网其他相关文章!

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
说明JVM如何充当Java代码和基础操作系统之间的中介。说明JVM如何充当Java代码和基础操作系统之间的中介。Apr 29, 2025 am 12:23 AM

JVM的工作原理是将Java代码转换为机器码并管理资源。1)类加载:加载.class文件到内存。2)运行时数据区:管理内存区域。3)执行引擎:解释或编译执行字节码。4)本地方法接口:通过JNI与操作系统交互。

解释Java虚拟机(JVM)在Java平台独立性中的作用。解释Java虚拟机(JVM)在Java平台独立性中的作用。Apr 29, 2025 am 12:21 AM

JVM使Java实现跨平台运行。1)JVM加载、验证和执行字节码。2)JVM的工作包括类加载、字节码验证、解释执行和内存管理。3)JVM支持高级功能如动态类加载和反射。

您将采取哪些步骤来确保Java应用程序在不同的操作系统上正确运行?您将采取哪些步骤来确保Java应用程序在不同的操作系统上正确运行?Apr 29, 2025 am 12:11 AM

Java应用可通过以下步骤在不同操作系统上运行:1)使用File或Paths类处理文件路径;2)通过System.getenv()设置和获取环境变量;3)利用Maven或Gradle管理依赖并测试。Java的跨平台能力依赖于JVM的抽象层,但仍需手动处理某些操作系统特定的功能。

Java是否需要特定于平台的配置或调整区域?Java是否需要特定于平台的配置或调整区域?Apr 29, 2025 am 12:11 AM

Java在不同平台上需要进行特定配置和调优。1)调整JVM参数,如-Xms和-Xmx设置堆大小。2)选择合适的垃圾回收策略,如ParallelGC或G1GC。3)配置Native库以适应不同平台,这些措施能让Java应用在各种环境中发挥最佳性能。

哪些工具或库可以帮助您解决Java开发中特定于平台的挑战?哪些工具或库可以帮助您解决Java开发中特定于平台的挑战?Apr 29, 2025 am 12:01 AM

Osgi,Apachecommonslang,JNA和JvMoptionsareeForhandlingForhandlingPlatform-specificchallengesinjava.1)osgimanagesdeppedendendencenciesandisolatescomponents.2)apachecommonslangprovidesitorityfunctions.3)

JVM如何在不同平台上管理垃圾收集?JVM如何在不同平台上管理垃圾收集?Apr 28, 2025 am 12:23 AM

JVMmanagesgarbagecollectionacrossplatformseffectivelybyusingagenerationalapproachandadaptingtoOSandhardwaredifferences.ItemploysvariouscollectorslikeSerial,Parallel,CMS,andG1,eachsuitedfordifferentscenarios.Performancecanbetunedwithflagslike-XX:NewRa

为什么Java代码可以在不同的操作系统上运行,而无需修改?为什么Java代码可以在不同的操作系统上运行,而无需修改?Apr 28, 2025 am 12:14 AM

Java代码可以在不同操作系统上无需修改即可运行,这是因为Java的“一次编写,到处运行”哲学,由Java虚拟机(JVM)实现。JVM作为编译后的Java字节码与操作系统之间的中介,将字节码翻译成特定机器指令,确保程序在任何安装了JVM的平台上都能独立运行。

描述编译和执行Java程序的过程,突出平台独立性。描述编译和执行Java程序的过程,突出平台独立性。Apr 28, 2025 am 12:08 AM

Java程序的编译和执行通过字节码和JVM实现平台独立性。1)编写Java源码并编译成字节码。2)使用JVM在任何平台上执行字节码,确保代码的跨平台运行。

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

将Eclipse与SAP NetWeaver应用服务器集成。

Atom编辑器mac版下载

Atom编辑器mac版下载

最流行的的开源编辑器

SecLists

SecLists

SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版