Anúncio
Anúncio

Mais conteúdo relacionado

Apresentações para você(20)

Similar a HTTP/2 Comes to Java: Servlet 4.0 and what it means for the Java/Jakarta EE ecosystem(20)

Anúncio

Mais de Edward Burns(20)

Último(20)

Anúncio

HTTP/2 Comes to Java: Servlet 4.0 and what it means for the Java/Jakarta EE ecosystem

  1. HTTP/2 on Java And what it means for the Java/Jakarta EE ecosystem Ed Burns @edburns Principal Architect Java on Azure Developer Experiences 2020-07
  2. HTTP/2 Comes to Java Servlet 4.0 and what it means to the Java/Jakarta EE Ecosystem Ed Burns @edburns Principal Architect Java on Azure Developer Experiences 2020-07
  3. • Brief Personal Journey • Java/Jakarta EE on Azure • Servlet 4 • HTTP/2 and Servlet 4 • New Improvements • Summary My Plan for Your Time Investment
  4. Professional Biography Client NCSA Mosaic (1994) SGI Cosmo Web Authoring Sun Netscape 6 OJI Server J2EE JSF (2002) Oracle Java EE Servlet, JSF, Bean Validation, etc. Microsoft Azure Cloud (2019) Books
  5. Starting on the Client: Birth of a Big Thing Oil and Chemistry Building at University of Illinois in Urbana-Champaign Home of NCSA Mosaic First Graphical Web Browser Gratis and Free software Built on prior work really well Ubiquitous (cross platform) Delivered something everyone wanted Easy to author: copy and paste from view source!
  6. Cobbles existing things together in an exciting new way. Simplicity: HTTP/1.0, TCP/IP sockets Anyone can add new servers, no need to ask permission. Leverages network effect Dabbling on the Server
  7. Birth of the Monolith: Spring and J2EE Addressed shared pain points Transparent development process Spring rode the crest of vendor marketing efforts, differentiated with operational excellence J2EE had multi-vendor concept, strong community governance Photo: Les Chatfield
  8. My First “War”: Web Frameworks Good variety of “good enough” tools Created a component ecosystem Lots of buzz around this space due to “Web Framework Wars”
  9. The Cloud: Birth of Another Big Thing 2004: Sun Utility Computing before it’s time…and at the wrong home
  10. I’m Ready for the Cloud My response to cloud disruption Get out from inside of the monolith Work with the hosting platform Monolith Microservices Helps enterprises scale
  11. Java EE on Azure with Oracle WebLogic Azure Marketplace Solution for WebLogic Published, maintained and supported by Oracle Based on Oracle Linux 7.6, Oracle JDK and WebLogic 12c R2 (12.2.1.3) Bring your own license Supports common use-cases such as load-balancing and clustering
  12. WebLogic Server on Azure IaaS Script file ARM template Virtual Network Admin Server Public IP Admin Server NIC Admin Sever VM Managed Sever Public IPs Managed Server NICs Managed Server VMs Storage
  13. WebLogic on Azure IaaS Four Azure Application Offers in the Marketplace • Create a single VM with WebLogic Admin Only domain pre-configured • Create an N-node WebLogic cluster with the admin server on one VM and cluster members on other VMs • Create an N-node WebLogic cluster as in the preceding offer, but with an Azure LoadBalancer automatically configured for the cluster • Create an N-node WebLogic dynamic cluster with the admin server on one VM and managed servers in a Dynamic cluster on the other nodes
  14. How WebLogic and Coherence work on Azure Kubernetes Service © Microsoft Corporation Azure Kubectl Kubernetes Kebectl create… Install Domain inputs (yaml) Customer Tenancy WLS Domain Image Operator Image Kubernetes cluster Domain Secrets Operator WebLogic Domain(s) WLS Cluster AS MS MS MSMS MS PVLogs Open Source Helm Charts Open Source Kubernetes Operators • Oracle WebLogic https://aka.ms/wlsoperator • Oracle Coherence https://aka.ms/cohoperator
  15. Demo Java EE 8 on Azure: Servlet 4.0 • Server Push • Mapping
  16. HTTP/2 Perception is Reality (especially with Web Browsers)
  17. HTTP/2 Perception is Reality (especially with Web Browsers)
  18. HTTP/2 Perception is Reality (especially with Web Browsers) Reduced perception of latency
  19. HTTP/2 Perception is Reality (especially with Web Browsers) Reduced perception of latency Header field compression
  20. HTTP/2 Perception is Reality (especially with Web Browsers) Reduced perception of latency Header field compression Multiple concurrent exchanges
  21. HTTP/2 is really just a new transport layer underneath HTTP/1.1 – same request/response model – no new methods – no new headers – no new usage patterns from application layer – no new usage of URL spec and other lower level specs Network Programming Review
  22. Standing on the Shoulders
  23. Network Programming Review
  24. Network Programming Review
  25. Network Programming Review
  26. Network Programming Review
  27. Network Programming Review
  28. Network Programming Review
  29. Network Programming Review
  30. • HTTP/1.0 – Sockets are a throwaway resource – Specification says very little about how sockets are to be used – Browsers free to open many sockets to the same server Network Programming Review Credit: chrisjstanley flickr The Socket Angle
  31. Network Programming Review The Socket Angle • HTTP/2 – Sockets seen as a scarce resource – Specification says much about how they are to be used – Only one open per server
  32. Network Programming Review The Socket Angle Client ServerClient Server Client Server Client Server Client Server Client Server
  33. Network Programming Review Solution in HTTP/2 Client Server
  34. Network Programming Review • HTTP/1.0 was designed to be easy to implement with contemporary development practices of 1991 – text based protocol – leaves flow control to the TCP layer – easy to write a parser – simple socket lifecycle The Adoption Angle
  35. Network Programming Review • HTTP/2 is much more complicated to implement – state machine – flow control – header compression – binary framing (arguably easier than text based for parsing) The Adoption Angle
  36. HTTP/2 Big Ticket Feature Review • Request/Response multiplexing • Binary Framing • Stream Prioritization • Server Push • Header Compression • Upgrade from HTTP/1.1 • ALPN • 101 Switching Protocols
  37. HTTP/2 Request Response Multiplexing • Fully bi-directional • Enabled by defining some terms – Connection A TCP socket – Stream A “channel” within a connection – Message A logical message, such as a request or a response – Frame The smallest unit of communication in HTTP/2. Lets the protocol do more things with a single TCP connection
  38. HTTP/2 Request Response Multiplexing • Fully bi-directional • Enabled by defining some terms – Connection A TCP socket – Stream A “channel” within a connection – Message A logical message, such as a request or a response – Frame The smallest unit of communication in HTTP/2. Lets the protocol do more things with a single TCP connection Back pressure?
  39. HTTP/2 Request Response Multiplexing • Fully bi-directional • Enabled by defining some terms – Connection A TCP socket – Stream A “channel” within a connection – Message A logical message, such as a request or a response – Frame The smallest unit of communication in HTTP/2. Lets the protocol do more things with a single TCP connection Flow control
  40. HTTP/2 Request Response Multiplexing Connections, Streams, Messages, Frames
  41. HTTP/2 Request Response Multiplexing • Once you break the communication down into frames, you can interweave the logical streams over a single TCP connection. • Yet another idea from the 1960s is new again. Connections, Streams, Messages, Frames Browser ServerSingle TCP connection for HTTP 2 STREAM'4' HEADERS' STREAM'9' HEADERS' STREAM'7' DATA' STREAM'7' HEADERS' STREAM'2' HEADERS' STREAM'2' DATA'
  42. HTTP/2 Binary Framing • Solves Head-Of-Line (HOL) blocking problem • Type field can be DATA, HEADERS, PRIORITY, RST_STREAM, SETTINGS, PUSH_PROMISE, PING, GOAWAY, WINDOW_UPDATE, CONTINUATION Enabled by dumping newline delimited ASCII Length (24) Type (8) Flags (8) R Stream Identifier (31) Frame Payload (0 …)
  43. HTTP/2 Header Compression • Observation: most of the headers are the same in a given connection – Host: Accept: user-agent: etc. • Why send them every time? • Have the server and the client keep tables of headers, then just send references and updates to the tables. Known as HPACK
  44. HTTP/2 Stream Prioritization • Stream Dependency in HEADERS Frame • PRIORITY frame type • An additional 40 bytes – Stream id (31) – Weight (8): [1, 256] – Exclusive bit (1) • Only a suggestion A B C 4 12 A B CD 4 16 12 exclusive = 0 A B C D 4 12 16 exclusive = 1
  45. HTTP/2 Server Push • Eliminates the need for resource inlining. • Lets the server populate the browser’s cache in advance of the browser asking for the resource to put in the cache. • No corresponding JavaScript API, but can be combined with SSE – Server pushes stuff into the browser’s cache. – Server uses SSE to tell the browser to go fetch it (but we know it’s already in the browser’s cache).
  46. HTTP/2 Upgrade from HTTP/1.1 • Not secure (h2c) – We have to use port 80 – Use existing 101 Switching Protocols from HTTP/1.1 – No Browsers implement this! • Secure (h2) – Application Layer Protocol Negotiation (ALPN) Secure or not-secure?
  47. • Allow frameworks to effectively leverage server push – flexible strategies for leveraging push • Leverage ALPN Abstractions Endure Servlet API is Well Positioned to Enable HTTP/2 Optimizations
  48. • Request/Response multiplexing • Binary Framing/Flow Control • Stream Prioritization • Server Push • Header Compression • Upgrade from HTTP/1.1 – ALPN – 101 Switching Protocols HTTP/2 Features Servlet 4.0 Big Ticket New Features
  49. • Request/Response multiplexing • Binary Framing/Flow Control • Stream Prioritization • Server Push • Header Compression • Upgrade from HTTP/1.1 – ALPN – 101 Switching Protocols HTTP/2 Features Potentially Exposed in Servlet API Servlet 4.0 Big Ticket New Features
  50. Servlet 4.0 Big Ticket New Features • HTTP/2 Required, including ALPN and HPACK • HTTP/2 Server Push – Push resource to client for a given url and headers – Not at all a replacement for WebSocket – Really useful for frameworks that build on Servlet, such as JSF – Builder API • Ease of Use
  51. javax.servlet.http.PushBuilder
  52. Server Push via Builder API Servlet 4.0 Big Ticket New Features
  53. Server Push public class FacesServlet implements Servlet { public void service(ServletRequest req, ServletResponse resp) throws IOException, ServletException { //.. HttpServletRequest request = (HttpServletRequest) req; try { ResourceHandler handler = context.getApplication().getResourceHandler(); if (handler.isResourceRequest(context)) { handler.handleResourceRequest(context); } else { lifecycle.attachWindow(context); lifecycle.execute(context); lifecycle.render(context); } } } Example of Potential Use from JSF
  54. Server Push public class ExternalContextImpl extends ExternalContext { //… public String encodeResourceURL(String url) { if (null == url) { String message = MessageUtils.getExceptionMessageString (MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "url"); throw new NullPointerException(message); } ((HttpServletRequest) request).getPushBuilder().path(url).push(); return ((HttpServletResponse) response).encodeURL(url); } //… } Example of Potential Use from JSF
  55. Reactive Programming ResponsiveResponsive Message DrivenMessage Driven ResilientResilientElasticElastic image credit: reactivemanifesto.org
  56. Non-blocking IO in Servlet 3.1 • ServletInputStream – #setReadListener, #isReady • ServletOutputStream – #setWriteListener, #isReady • ReadListener – #onDataAvailable, #onAllDataRead, #onError • WriteListener – #onWritePossible, #onError
  57. Non-blocking IO in Servlet 3.1 • ServletInputStream – #setReadListener, #isReady • ServletOutputStream – #setWriteListener, #isReady • ReadListener – #onDataAvailable, #onAllDataRead, #onError • WriteListener – #onWritePossible, #onError Flow control
  58. • Add Java SE 8 default methods – ServletContextAttributeListener, ServletContextListener, ServletRequestAttributeListener, ServletRequestListener, HttpSessionActivationListener, HttpSessionAttributeListener, HttpSessionBindingListener, HttpSessionListener • Add default to Filter#init, #destroy • Add GenericFilter and HttpFilter • <default-context-path> element in web.xml • Add Cookie[] getCookie(String name) to HttpServletRequest Servlet 4.0 Small Change
  59. Servlet 4.0 Small Change • Mapping javax.servlet.http.HttpServletRequest. getMapping() • javax.servlet.http.Mapping – MappingMatch getMatchType() – String getMatchValue() – String getPattern() • javax.servlet.http.MappingMatch enum – CONTEXT_ROOT, DEFAULT, EXACT, EXTENSION, IMPLICIT, PATH, UNKNOWN Discover current Active Mapping
  60. @Deprecate some methods and classes – ServletContext: getServlet(), getServlets(), getServletNames(), log() – ServletRequestWrapper: getRealPath() – SingleThreadModel – UnavailableException – HttpServletResponse: encodeUrl(), encodeRedirectUrl(), setStatus() – HttpServletResponseWrapper: encodeUrl(), encodeRedirectUrl(), setStatus() – HttpSession: getSessionContext(), getValue(), getValueNames(), putValue(), removeValue() – HttpSessionContext Servlet 4.0 Small Change
  61. • HttpConstraint • HttpMethodConstraint • MultipartConfig • ServletSecurity • WebFilter • WebInitParam • WebListener • WebServlet • … • PostConstruct • PreDestroy • Resource • Resources • DeclareRoles • RunAs • DataSourceDefinition • DataSourceDefinitions • … • • AroundConstruct • AroundInvoke • AroundTimeout • ExcludeClassInterceptors • ExcludeDefaultInterceptors • Interceptors • … Servlet 4.0 Small Change Clarify exactly which annotations are not scanned when metadata-complete="true"
  62. • Be willing to adapt and change your focus • The cloud has disrupted everything • Azure is a great cloud for Java workloads Summary
Anúncio