Camelcasecon 20190522 Qua
Total Page:16
File Type:pdf, Size:1020Kb
I’m an Open Source enthusiast since I got in touch with Linux back in 1994 while trying to study Mathematics in Göttingen and got tired to go to the institute or data center to compile C programs for Unix. In 1999 I got infected by the Java virus and worked as a Java Developer at a startup company which went IPO. While looking for another application-server I stumbled upon JBoss in 2001 and decided to write my Diploma Thesis on Computer Science at the University of Applied Science in Dortmund with and about JBoss in 2004. I joined a Telecommunications Company in Düsseldorf by then, where I worked in various positions as Software Developer, Tester, Integration Lead, Project Manager and Operation Specialist. In 2012 I got hired by Red Hat as a Consultant and continued my Middleware journey with JBoss and other products, but got tempted in 2015 by the dark side (they have cookies) and changed into a Pre-Sales role. Challenges for Java (now and future) CONTAINER JAVA // @ro14nd // k8spatterns.io 1996 CONTAINER JAVA // @ro14nd // k8spatterns.io 1999 CONTAINER JAVA // @ro14nd // k8spatterns.io 2009 CONTAINER JAVA // @ro14nd // k8spatterns.io 2019 https://www.tiobe.com/tiobe-index/ VM VM 10 per APP APP Server CONTAINER CONTAINER 100 per LIBS LIBS Server GUEST OS GUEST OS APP APP HYPERVISOR LIBS LIBS HOST OS HOST OS SERVER SERVER PHYSICAL SERVER VIRTUAL MACHINE CONTAINER INSTANCE 27 HRS 12 MINS 10 SECS F F F F F F F F F F F F F F F F F F F F MICRO MICRO MICRO MICRO MICRO SERVICE SERVICE SERVICE SERVICE SERVICE F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F MICRO MICRO MICRO MICRO MICRO SERVICE SERVICE SERVICE SERVICE SERVICE F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F MONOLITH MICRO MICRO MICRO MICRO MICRO F F F F F F F F F F F F F F F F F F F F SERVICE SERVICE SERVICE SERVICE SERVICE F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F F MICRO MICRO MICRO MICRO MICRO SERVICE SERVICE SERVICE SERVICE SERVICE F F F F F F F F F F F F F F F F F F F F ● 1 monolith ≈ 20 microservices ≈ 200 functions ● Scale to 1 vs scale to 0 ● Start up time 62.9% Node.js 20.8% Python 6.1% 6.4% Go Java 6.1% Java 3.8% C# https://serverless.com/blog/2018-serverless-community-survey-huge-growth-usage/ Agility, Scalability, Faster Business Reactivity App 1 App 2 App 3 App 4 App 5 Data Data Data Data Container platform HotSpot Heap NodeJS Go Go NodeJS Go Go HotSpot Heap NodeJS Go Go NodeJS Go Go HotSpot Heap NodeJS Go Go NodeJS Go Go HotSpot Heap NodeJS Go Go Node Node Node Container platform ● Startup overhead ○ # of classes, bytecode, JIT ● Memory overhead ○ # of classes, metadata, compilation ● Multi tenancy Heap Metaspace off-heap RSS What is Quarkus? Supersonic. Subatomic. Java. https://quarkus.io a Red Hat sponsored project Cloud Native, Microservices, Serverless https://github.com/quarkusio/quarkus How does it work? Runnable java app Hotspot Runnable & Image Wiring & Provision Compile Assemble (curate) (augment) AOT Native Native Executable & Compilation Image app.jar frameworks Native-app (GraalVM) Steps ● Metadata processing, such as reading annotations, XML descriptors etc. ○ Output is recorded bytecode which is responsible for directly instantiating the relevant runtime services. ○ Processed once at build time, which reduces startup time and memory consumption ● Enforce opinionated and sensible defaults based on the close world view of the application (don’t run unused services) ● Dead code elimination ● Send metadata to GraalVM for example classes in need of reflection Concepts ● Favor build time work over runtime work ● Unified configuration into a single file, application.properties Sulong (LLVM) Truffle Graal Compiler JVM CI Substrate VM Java HotSpot VM https://github.com/oracle/graal What are the advantages? REST + CRUD Quarkus + GraalVM Quarkus + OpenJDK Traditional Cloud-Native Stack 35 MB 130 MB 218 MB REST + CRUD Quarkus + GraalVM 0.055 Seconds Quarkus + OpenJDK 2.5 Seconds Traditional Cloud-Native Stack 9.5 Seconds A cohesive platform for optimized developer joy: ● Based on standards, but not limited ● Unified configuration ● Zero config, live reload in the blink of an eye ● Streamlined code for the 80% common usages, flexible for the 20% ● No hassle native executable generation Eclipse Vert.x Hibernate RESTEasy Apache Camel Eclipse MicroProfile Netty Kubernetes OpenShift Jaeger Prometheus Apache Kafka Infinispan @Inject @Inject @Stream(”kafka”) SayService say; Publisher<String> reactiveSay; @GET @GET @Produces(MediaType.TEXT_PLAIN) @Produces(MediaType.SERVER_SENT_EVENTS) public String hello() { public Publisher<String> stream() { return say.hello(); return reactiveSay; } } ● Combine both Reactive and imperative development in the same application ● Inject the EventBus or the Vertx context ● Use the technology that fits your use-case @Entity @Produces("application/json") public class Todo extends PanacheEntity { @Consumes("application/json") @Column(unique=true) @NotBlank public class TodoResource { public String title; @GET public String url; Public List<Todo> getAll() { public boolean completed; return Todo.listAll(Sort.by("order")); @Column(name=”ordering”) } public int order; } } ● Similar to ActiveRecord in Ruby on Rails ● Works with Transactions (@Transactional) ● Extendable @QuarkusTest public class GreetingResourceTest { @Test public void testHelloEndpoint() { given() .when().get("/hello") .then() .statusCode(200) .body(is("hello")); } @Test public void testGreetingEndpoint() { String uuid = UUID.randomUUID().toString(); given() .pathParam("name", uuid) .when().get("/hello/greeting/{name}") .then() .statusCode(200) .body(is("hello " + uuid)); } } Where does it fit? ● Greenfield applications ● Microservice-Architectures ● Serverless applications ● Brownfield applications, depends on effort for migration How to create applications For Quarkus (current version 0.15) the following components should be installed ● IDE (f.e. CodeReady Studio) ● Open JDK 8 (Download for Windows) ● Apache Maven 3.5.3+ (Download) (works with Gradle, too) ● GraalVM 0.16 (Download Community Edition) Also an environment variable GRAALVM_HOME needs to be set and pointing to the GraalVM installation. For ease of use this should also be done for JAVA_HOME and MAVEN_HOME. export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk export MAVEN_HOME=/home/jcordes/Software/Maven/apache-maven-3.5.4 export GRAALVM_HOME=/usr/lib/jvm/graalvm mvn io.quarkus:quarkus-maven-plugin:0.15.0:create \ -DprojectGroupId=de.camelcasecon \ -DprojectArtifactId=getting-started \ -DclassName="de.camelcasecon.quickstart.GreetingResource" \ -Dpath="/hello" mvn compile quarkus:dev curl -v "http://localhost:8080/hello" ● Live-Reloading: Just change the code ● List and add extensions: mvn quarkus:list-extensions mvn quarkus:add-extension -Dextensions="groupId:artifactId" ● Compile to native code: ./mvnw package -Pnative How to port applications ● Change Maven dependencies (use quarkus.io/quarkus-bom/${quarkus-version}) ● CDI: Replace javaee-api with quarkus-arc ● EJB Timer: Replace with quarkus-scheduler ● JAX-RS: Replace resteasy with quarkus-resteasy ● JPA: Move persistence.xml info to application.properties, use quarkus-hibernate-orm ● ... ● Register for reflection via Quarkus Processor @buildstep method (ReflectiveClassBuildItem) or @RegisterForReflection annotation on class level ● Include resources via @buildstep method (SubstrateResourceBuildItem) ● Delay class initialization via @buildstep method (RuntimeInitializedClassBuildItem) ● Manage Proxy Classes via @buildstep method (SubstrateProxyDefinitionBuildItem) ● ... ● Augmentation step of Quarkus generates classes for various purposes, these can be viewed with ./mvnw clean install -Dquarkus.debug.generated-classes-dir=./target/app-generated-classes https://quarkus.io/guides/writing-native-applications-tips https://developers.redhat.com/blog/2019/04/12/migrating-java-applications-to-quarkus-lessons-learned/ Support Status CONTEXTS AND DEPENDENCY INJECTION @ConversationScoped not supported Decorators not supported Portable Extensions not supported BeanManager - only the following methods are partially supported implemented: getBeans(), createCreationalContext(), getReference(), resolve(), getContext(), getEvent() and createInstance() Specialization not supported beans.xml descriptor content is ignored not supported Passivation and passivating scopes not supported Transitive interceptor bindings and interceptor not supported methods on superclasses are not implemented yet What Support Status Dynamic Class Loading / Unloading Not supported Reflection Mostly supported Dynamic Proxy Mostly supported Java Native Interface (JNI) Mostly supported Unsafe Memory Access Mostly supported Static Initializers Partially supported InvokeDynamic Bytecode and Method Not supported Handles What Support Status Synchronized, wait, and notify Supported Finalizers Not supported References Mostly supported Threads Supported Identity Hash Code Supported Security Manager Not supported JVMTI, JMX, other native VM interfaces Not supported JCA Security Services Supported The future ● GraalVM 0.19 support, this will also allow for native applications on Windows ● Supporting more frameworks Resources ● Quarkus Website ● Quarkus Guides ● Quarkus on Github ● Quarkus Quickstarts ● Quarkus: Supersonic, subatomic Java | DevNation Live https://learn.openshift.com/middleware/courses/middleware-quarkus/ .