Slide 1

Slide 1 text

01

Slide 2

Slide 2 text

02

Slide 3

Slide 3 text

Timeline 03

Slide 4

Slide 4 text

04

Slide 5

Slide 5 text

05

Slide 6

Slide 6 text

06

Slide 7

Slide 7 text

07

Slide 8

Slide 8 text

08

Slide 9

Slide 9 text

Definitions 09

Slide 10

Slide 10 text

Cloud-native Cloud native technologies empower organizations to build and run scalable applications in modern, dynamic environments such as public, private, and hybrid clouds. Containers, service meshes, micro-services, immutable infrastructure, and declarative APIs exemplify this approach. “ 10

Slide 11

Slide 11 text

Cloud-native These techniques enable loosely coupled systems that are resilient, manageable, and observable. Combined with robust automation, they allow engineers to make high-impact changes frequently and predictably with minimal toil. “ 11

Slide 12

Slide 12 text

Serverless I don't want to care about servers. “ 12

Slide 13

Slide 13 text

13

Slide 14

Slide 14 text

14

Slide 15

Slide 15 text

15

Slide 16

Slide 16 text

16

Slide 17

Slide 17 text

17

Slide 18

Slide 18 text

18

Slide 19

Slide 19 text

19

Slide 20

Slide 20 text

20

Slide 21

Slide 21 text

21

Slide 22

Slide 22 text

22

Slide 23

Slide 23 text

23

Slide 24

Slide 24 text

Make JAR, not WAR 24

Slide 25

Slide 25 text

Fat-less app 25

Slide 26

Slide 26 text

Container-awareness Inside Linux containers, OpenJDK versions 8 and later can correctly detect the container-limited number of CPU cores and available RAM. For all currently supported OpenJDK versions this is turned on by default. “ 26

Slide 27

Slide 27 text

27

Slide 28

Slide 28 text

28

Slide 29

Slide 29 text

29

Slide 30

Slide 30 text

Container support Container support is enabled by default since Java 10 Some settings and parameters are back-ported to Java 8 Can be disabled with -XX:-UseContainerSupport • • • 30

Slide 31

Slide 31 text

Container support -XX:ActiveProcessorCount=count -XX:InitialRAMPercentage=mem -XX:MaxRAM=mem -XX:MaxRAMPercentage=pct -XX:MinRAMPercentage=pct • • • • • 31

Slide 32

Slide 32 text

GC 32

Slide 33

Slide 33 text

1791 33

Slide 34

Slide 34 text

Image size 34

Slide 35

Slide 35 text

35

Slide 36

Slide 36 text

36

Slide 37

Slide 37 text

Tangle 37

Slide 38

Slide 38 text

38

Slide 39

Slide 39 text

39

Slide 40

Slide 40 text

40

Slide 41

Slide 41 text

41

Slide 42

Slide 42 text

Log4shell 42

Slide 43

Slide 43 text

Observability In software, observability is the ability to ask new questions of the health of your running services without deploying new instrumentation. “ 43

Slide 44

Slide 44 text

The three pillars Metrics Logs Traces • • • 44

Slide 45

Slide 45 text

Prometheus 45

Slide 46

Slide 46 text

Prometheus architecture 46

Slide 47

Slide 47 text

Exporters 47

Slide 48

Slide 48 text

JMX exporter 48

Slide 49

Slide 49 text

JMX exporter https://github.com/prometheus/jmx_exporter 49

Slide 50

Slide 50 text

JMX exporter java -javaagent:./jmx_prometheus_javaagent-0.16.1.jar=8080:config. 01. 50

Slide 51

Slide 51 text

Spring Actuator 51

Slide 52

Slide 52 text

Akka 52

Slide 53

Slide 53 text

Prometheus Client for Java import io.prometheus.client.Counter; class YourClass { static final Counter requests = Counter.build() .name("requests_total").help("Total requests.").register(); void processRequest() { requests.inc(); // Your code here. } } 01. 53

Slide 54

Slide 54 text

Traces 54

Slide 55

Slide 55 text

Definition A trace is a data/execution path through the system, and can be thought of as a directed acyclic graph of spans. 55

Slide 56

Slide 56 text

Trace/Span 56

Slide 57

Slide 57 text

Jaeger 57

Slide 58

Slide 58 text

Jaeger architecture 58

Slide 59

Slide 59 text

Instrumentation 59

Slide 60

Slide 60 text

Get tracer Tracer tracer = Configuration.fromEnv().getTracer(); 01. 60

Slide 61

Slide 61 text

Access span Span span = tracer.scopeManager().activeSpan(); if (span != null) { span.log("..."); } 01. 02. 03. 04. 61

Slide 62

Slide 62 text

Create span Span span = tracer.buildSpan("someWork").start(); try (Scope scope = tracer.scopeManager().activate(span)) { // Do things. } catch(Exception ex) { Tags.ERROR.set(span, true); span.log(Map.of(Fields.EVENT, "error", Fields.ERROR_OBJECT, ex, Fields.MESSAGE, ex.getMessage())); } finally { span.finish(); } 01. 02. 03. 04. 05. 06. 07. 08. 09. 10. 62

Slide 63

Slide 63 text

Ignore parent span Span span = tracer. buildSpan("someWork"). ignoreActiveSpan(). start(); 01. 02. 03. 04. 63

Slide 64

Slide 64 text

JFR 64

Slide 65

Slide 65 text

Java Flight Recorder It was first introduced in JRockit. Many features of JRockit including JFR were merged into Oracle HotSpot at version 8. Till version 11, JFR/JMC was considered a commercial feature ( - XX:+UnlockCommercialFeatures -XX:+FlightRecorder ). In 11, JFR became free, but JMC (Mission Control UI) was removed from JDK, but remained a separate utility. • • • • 65

Slide 66

Slide 66 text

jcmd jcmd JFR.start duration=60s filename=recording.jfr jcmd JFR.start jcmd JFR.dump name=1 filename=recording.jfr jcmd JFR.stop 01. 02. 03. 04. 66

Slide 67

Slide 67 text

jfr jfr print --events CPULoad,GarbageCollection recording.jfr jfr print --categories "GC,JVM,Java*" recording.jfr jfr summary recording.jfr jfr metadata recording.jfr 01. 02. 03. 04. 67

Slide 68

Slide 68 text

Custom events import jdk.jfr.Event; public class RestCallEvent extends Event { public String path; public String key; public long dataSize; } 01. 02. 03. 04. 05. 06. 07. 68

Slide 69

Slide 69 text

Custom events event.begin(); // do something event.key = key; event.dataSize = val.length(); // do something event.end(); event.commit(); 01. 02. 03. 04. 05. 06. 07. 69

Slide 70

Slide 70 text

JFR Streaming (Java 14) try (var rs = new RecordingStream()) { rs.enable("jdk.CPULoad").withPeriod(Duration.ofSeconds(1)); rs.enable("jdk.JavaMonitorEnter").withThreshold(Duration.ofMilli rs.onEvent("jdk.CPULoad", event -> { System.out.println(event.getFloat("machineTotal")); }); rs.onEvent("jdk.JavaMonitorEnter", event -> { System.out.println(event.getClass("monitorClass")); }); rs.start(); 01. 02. 03. 04. 05. 06. 07. 08. 09. 10. 70

Slide 71

Slide 71 text

JFR Streaming (Java 14) Configuration c = Configuration.getConfiguration("default"); try (var rs = new RecordingStream(c)) { rs.onEvent("jdk.GarbageCollection", System.out::println); rs.onEvent("jdk.CPULoad", System.out::println); rs.onEvent("jdk.JVMInformation", System.out::println); rs.start(); } } 01. 02. 03. 04. 05. 06. 07. 08. 71

Slide 72

Slide 72 text

AWS CodeGuru 72

Slide 73

Slide 73 text

AWS X-ray 73

Slide 74

Slide 74 text

Serverless 74

Slide 75

Slide 75 text

If it were 2005... Jetty/Tomcat/Ruby/PHP (on a server) MySQL, PostgreSQL, HSQL, Sqlite (on a server) File system (on a server) • • • 75

Slide 76

Slide 76 text

If it were 2015... Jetty/Tomcat/Ruby/PHP (in a container on a server) or PaaS in the cloud MySQL, PostgreSQL, HSQL, Sqlite (on a server or in a container on a server) or DaaS in the cloud File system (in a volume on a server) or object storage in the cloud • • • 76

Slide 77

Slide 77 text

In 2022... CDN + FaaS + LB in the cloud DaaS in the cloud Object storage in the cloud • • • 77

Slide 78

Slide 78 text

FaaS JVM choices 78

Slide 79

Slide 79 text

GCP 79

Slide 80

Slide 80 text

GCP (512m) -XX:MaxRAM=512m -XX:MaxRAMPercentage=70 01. 02. 80

Slide 81

Slide 81 text

GCP (512m) Copy MarkSweepCompact • • 81

Slide 82

Slide 82 text

GCP (4096m) -XX:MaxRAM=4096m -XX:MaxRAMPercentage=70 01. 02. 82

Slide 83

Slide 83 text

GCP (4096m) G1 Young G1 Old • • 83

Slide 84

Slide 84 text

Azure 84

Slide 85

Slide 85 text

Azure -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Xverify:none -Djava.net.preferIPv4Stack=true 01. 02. 03. 04. 85

Slide 86

Slide 86 text

GC PS Scavenge PS MarkSweep • • 86

Slide 87

Slide 87 text

AWS (512) -XX:MaxHeapSize=445645k -XX:MaxMetaspaceSize=52429k -XX:ReservedCodeCacheSize=26214k -XX:+UseSerialGC 01. 02. 03. 04. 87

Slide 88

Slide 88 text

AWS (4096) -XX:MaxHeapSize=3948544k -XX:MaxMetaspaceSize=163840k -XX:ReservedCodeCacheSize=81920k -XX:+UseSerialGC 01. 02. 03. 04. 88

Slide 89

Slide 89 text

AWS -javaagent:/var/runtime/amzn-log4j-security-jdk11-0.1alpha.jar -Xshare:on -XX:SharedArchiveFile=/var/lang/lib/server/runtime.jsa -XX:-TieredCompilation -Djava.net.preferIPv4Stack=true 01. 02. 03. 04. 05. 89

Slide 90

Slide 90 text

CDS Class Data Sharing It contains 1300+ core library classes loaded by the bootstrap class loader It is stored in a format that can be loaded very quickly, compared to loading from a JAR file • • • 90

Slide 91

Slide 91 text

Dynamic CDS -XX:ArchiveClassesAtExit=cds.jsa 01. 91

Slide 92

Slide 92 text

JVM FaaS on clouds AWS: Serial, only JIT C2, shared class data, memory set explicitly GCP: Serial or G1, auto-tuning memory pools Azure: Parallel, only JIT C1 • • • 92

Slide 93

Slide 93 text

JIT 93

Slide 94

Slide 94 text

JVMCI 94

Slide 95

Slide 95 text

Graal Compiler Graal Compiler = JIT Compiler written in Java Added in Java 10 Removed in Java 17 • • • 95

Slide 96

Slide 96 text

Graal VM OpenJDK with Graal compiler Truffle framework Tooling for other languages (Python, Node.js, Ruby etc.) Native image + Substrate VM • • • • 96

Slide 97

Slide 97 text

Modes JVM Native • • 97

Slide 98

Slide 98 text

Native 98

Slide 99

Slide 99 text

Nice and shiny? Requires extra tooling (platform image, C++ compiler) Compilation time could be quite long for larger code bases "Closed-world" approach requires extra configuration for handling reflection, dynamic proxies etc. Some runtime tooling is not available (no way to get a memory dump) • • • • 99

Slide 100

Slide 100 text

Reflection native-image -H:ReflectionConfigurationFiles=r.json ... 01. 100

Slide 101

Slide 101 text

Reflection { { "name": "java.lang.String$CaseInsensitiveComparator", "queriedMethods": [ { "name": "compare" } ] } ] 01. 02. 03. 04. 05. 06. 07. 08. 09. 101

Slide 102

Slide 102 text

Hmmm... Long compilation times Extra configuration or code changes are required Not all Java functionality is supported • • • 102

Slide 103

Slide 103 text

Why bother? improved startup time (= faster scaling) reduced memory usage (= cheaper) reduced image size better performance (?) better security (?) ideal for serverless/ML workloads • • • • • • 103

Slide 104

Slide 104 text

Community! Spring Native (native image support for Spring/Spring Boot) Quarkus (RedHat's baby, lots of integrations, community work, build-time code generation) Micronaut (no reflection, build-time code generation) Helidon (Oracle's baby, support for jlink) • • • • 104

Slide 105

Slide 105 text

Quarkus 105

Slide 106

Slide 106 text

Helidon 106

Slide 107

Slide 107 text

Infra-as-code 107

Slide 108

Slide 108 text

CDK 108

Slide 109

Slide 109 text

Infra-as-Java Bucket bucket = Bucket.Builder .create(this, targetBucket).build(); PolicyStatement statement1 = PolicyStatement.Builder.create() .effect(Effect.ALLOW) .actions(asList("s3:GetBucket", "s3:PutObject")) .resources(asList("arn:aws:s3:::" + bucket.getBucketName() + "/* .build(); 01. 02. 03. 04. 05. 06. 07. 08. 109

Slide 110

Slide 110 text

Infra-as-Java Vpc vpc = new Vpc(this, "VPC"); AutoScalingGroup asg = AutoScalingGroup.Builder .create(this,"ASG") .vpc(vpc) .instanceType(InstanceType.of(BURSTABLE2, MICRO)) .machineImage(new AmazonLinuxImage()) .build(); 01. 02. 03. 04. 05. 06. 07. 08. 110

Slide 111

Slide 111 text

Infra-as-Java HealthCheck.Builder healthCheckBuilder = new HealthCheck.Builder(); HealthCheck healthCheck = healthCheckBuilder.port(80).build(); LoadBalancer lb = LoadBalancer.Builder.create(this,"LB") .vpc(vpc) .internetFacing(Boolean.TRUE) .healthCheck(healthCheck) .build(); 01. 02. 03. 04. 05. 06. 07. 08. 111

Slide 112

Slide 112 text

Conclusion JVM ecosystem has many options for different load types. It makes it useful for any cloud-native/serverless/containerized environment. Community is vibrant and responsive. • • • 112

Slide 113

Slide 113 text

113

Slide 114

Slide 114 text

Future 114

Slide 115

Slide 115 text

Project Loom Thread.startVirtualThread( () -> { System.out.println("Hello World"); } ); 01. 02. 03. 04. 05. 115

Slide 116

Slide 116 text

Alibaba's Dragonwell https://dragonwell-jdk.io/ 116

Slide 117

Slide 117 text

Project Leyden The primary goal of this Project is to address the long-term pain points of Java's slow startup time, slow time to peak performance, and large footprint. “ 117

Slide 118

Slide 118 text

Thank you! 118

Slide 119

Slide 119 text

Questions? 119

Slide 120

Slide 120 text

120