Your SlideShare is downloading. ×
0
Jetty 9
The Next-Generation
Servlet Engine

Simone Bordet
sbordet@intalio.com
Simone Bordet
 Simone Bordet
 sbordet@intalio.com
 @simonebordet

 Open Source Contributor
 Jetty, CometD, MX4J, Foxt...
Agenda
 Jetty Introduction
 Web History and Evolution
 Web Protocols
 Jetty Features & Performance
 The future: HTTP ...
Jetty
 The Jetty Servlet Container
 Implemented the Servlet Specification since 1.0

 Jetty 7 → Servlet 2.5
 Jetty 8, ...
History
&
Evolution

Simone Bordet
sbordet@intalio.com
w3c.org 1996
HTTP 1.0 protocol designed to serve these pages:

1 HTML File, 600 Bytes
Simone Bordet
sbordet@intalio.com
Evolution – I/O
 Technologies evolved over the years
 Scalability limited by blocking I/O
 Advent of NIO (asynchronous ...
Evolution – CPU
 Multicore CPUs everywhere
 JDK enhanced with atomic primitives
 Rethink locking for “mechanical sympat...
w3c.org 2013

1 HTML, 33.5 KiB - 4 CSS, 12 KiB – 2 JS 31 KiB - 27 Images, 61.5 KiB
34 Resources, 138 KiB
Simone Bordet
sbo...
cnn.com 2013

172 Resources, 1.2 MiB
Simone Bordet
sbordet@intalio.com
Web Explosion
 The Web Exploded
 Assumptions, protocols and technologies valid in 1996

are still our best choice ?

WE ...
HTTP Limits
 HTTP is an old protocol
 Not bidirectional
 No multiplexing
 No resource correlation

 Today's Web conte...
WebSocket

Simone Bordet
sbordet@intalio.com
WebSocket
 Effort Initiated by Browser Vendors to
 Bidirectional low latency communications
 Replace Comet HTTP “hacks”...
WebSocket Upgrade
 Runs on port 80 (or 443 for wss)
 Uses HTTP/1.1 Upgrade mechanism
REQUEST
GET / HTTP/1.1
Host: localh...
HTTP Performance
 Jetty-7.6, CometD-2.4, chat application
 HTTP

Simone Bordet
sbordet@intalio.com
WebSocket Performance
 Jetty-7.6, CometD-2.4, chat application
 WebSocket

Simone Bordet
sbordet@intalio.com
WebSocket Deployment
 Browsers

 Java Servers

 Firefox 11 (Android 15)

 Jetty 7, Jetty 8, Jetty 9

 Internet Explor...
SPDY

Simone Bordet
sbordet@intalio.com
SPDY is LIVE!
 SPDY is a live experiment to improve HTTP
 Addresses HTTP 1.1 limits
 Designed to be faster and better t...
SPDY & Jetty
 Jetty 7 & Jetty 8
 SPDY added by mocking HTTP wire protocol
 Multiplexing requires mock protocol per chan...
SPDY Protocol Initiation
 SPDY uses TLS (aka SSL) connection on port 443
 TLS extended with Next Protocol Negotiation

...
SPDY Multiplexing
 Multiplexing is built-in
SYN_STREAM

SYN_REPLY

SYN_STREAM

SYN_REPLY
SYN_REPLY

DATA

DATA

SYN_STREA...
SPDY Multiplexing
 Multiplexing
 Allows to make better use of TCP connections


Reduces TCP slow start

 Uses less res...
SPDY Push
 SPDY Push
 Server pushes secondary resources that are associated

to a primary resource
 Works in collaborat...
SPDY Push
HTTP/1.1
index.html
application.js
style.css

image1.png

Push
Cache

SPDY/3 + PUSH

Simone Bordet
sbordet@intal...
SPDY Clients
 Desktop

 Mobile

 Firefox 13

 Android Browser 4.1

 Chrome 4

 Chrome for Android 18.0

 Opera 12.1...
DEMO

Simone Bordet
sbordet@intalio.com
Jetty 9.1

Simone Bordet
sbordet@intalio.com
Jetty 9.1
 Polyglot (HTTP, WebSocket, SPDY, FastCGI)
 Servlet 3.1 ready
 Great as a production server too
 Not a monol...
Jetty 9.1 Performance
 Great performance
 Easy to push it to 70k or more requests/s


These are Servlet requests not ju...
Servlet 3.1
public void service(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletExcep...
Servlet 3.1
public class AsyncReader implements ReadListener {
private final AsyncContext asyncContext;
...
public void on...
Servlet 3.1
public class AsyncWriter implements WriteListener {
private final AsyncContext asyncContext;
...
public void o...
Servlet 3.1
Echo Servlet Blocking I/O
public class SyncServlet extends HttpServlet
{
protected void service(HttpServletReq...
Jetty 9.1
 Jetty HttpClient
 High Performance HttpClient with fluent API


70% faster than Jetty 8's HttpClient

 Plug...
HTTP 2.0
 HTTP 2.0 work has started
 IETF HTTPbis working group rechartered

 Two proposals received:
 Google - SPDY a...
Conclusions

Simone Bordet
sbordet@intalio.com
Conclusions
 The Web is evolving
 Web Protocols are evolving
 Servers must keep the pace with new Web Protocols

 Try ...
Questions
&
Answers

Simone Bordet
sbordet@intalio.com
Upcoming SlideShare
Loading in...5
×

Jetty 9 – The Next Generation Servlet Container

5,506

Published on

Jetty has always been known to be a technology leader in several areas—from Jetty Continuations (later standardized as Servlet 3 asynchronous servlets) to WebSocket to SPDY—delivering exceptional production performance.
Jetty 9 is not only a great production server but provides features such as the Jetty Maven plug-in and embedded Jetty that help you in application development and integration testing. This session covers Jetty 9’s scalability, stability, performance, and features such as the new HTTP client and how to configure Jetty for optimal production performance.

Published in: Technology

Transcript of "Jetty 9 – The Next Generation Servlet Container"

  1. 1. Jetty 9 The Next-Generation Servlet Engine Simone Bordet sbordet@intalio.com
  2. 2. Simone Bordet  Simone Bordet  sbordet@intalio.com  @simonebordet  Open Source Contributor  Jetty, CometD, MX4J, Foxtrot, LiveTribe, JBoss, Larex  Lead Architect at Intalio/Webtide  Jetty's SPDY and HTTP client maintainer  CometD project leader  Web messaging framework  JVM tuning expert Simone Bordet sbordet@intalio.com
  3. 3. Agenda  Jetty Introduction  Web History and Evolution  Web Protocols  Jetty Features & Performance  The future: HTTP 2.0 Simone Bordet sbordet@intalio.com
  4. 4. Jetty  The Jetty Servlet Container  Implemented the Servlet Specification since 1.0  Jetty 7 → Servlet 2.5  Jetty 8, 9 → Servlet 3.0  Jetty 9.1 → Servlet 3.1  Mostly known for its component-based architecture  Very easy to embed  Very easy to use for automated tests  Great for production too ! Simone Bordet sbordet@intalio.com
  5. 5. History & Evolution Simone Bordet sbordet@intalio.com
  6. 6. w3c.org 1996 HTTP 1.0 protocol designed to serve these pages: 1 HTML File, 600 Bytes Simone Bordet sbordet@intalio.com
  7. 7. Evolution – I/O  Technologies evolved over the years  Scalability limited by blocking I/O  Advent of NIO (asynchronous I/O)  Servers became more scalable, C10K now possible  Jetty 6 – one of the first NIO Servlet containers  Jetty innovates: Jetty Continuations  Portable way to suspend/resume requests  Jetty spun off the CometD project at http://cometd.org  Scalable Web Messaging Framework  Servlet 3.0 incorporated Jetty Continuations concepts  Servlet 3.1 expands to asynchronous I/O Simone Bordet sbordet@intalio.com
  8. 8. Evolution – CPU  Multicore CPUs everywhere  JDK enhanced with atomic primitives  Rethink locking for “mechanical sympathy”  Jetty 9 core rewrite taking that in account  Keep thread context switching at minimum  Reduce/Eliminate false sharing  Use concurrent data structures  Avoid synchronized in favor of atomic state machines  Jetty 9.1 is 30+% faster than Jetty 8  And implements more features Simone Bordet sbordet@intalio.com
  9. 9. w3c.org 2013 1 HTML, 33.5 KiB - 4 CSS, 12 KiB – 2 JS 31 KiB - 27 Images, 61.5 KiB 34 Resources, 138 KiB Simone Bordet sbordet@intalio.com
  10. 10. cnn.com 2013 172 Resources, 1.2 MiB Simone Bordet sbordet@intalio.com
  11. 11. Web Explosion  The Web Exploded  Assumptions, protocols and technologies valid in 1996 are still our best choice ? WE CAN DO BETTER ! Simone Bordet sbordet@intalio.com
  12. 12. HTTP Limits  HTTP is an old protocol  Not bidirectional  No multiplexing  No resource correlation  Today's Web content forces too many hacks  Comet techniques to fake bidirectionality  Browsers to open multiple connections   Due to HTTP's lack of multiplexing TCP slow start gets in the way  Domain sharding imposes additional overhead on servers  Would like to use pipelining, but cannot  Does not work reliably Simone Bordet sbordet@intalio.com
  13. 13. WebSocket Simone Bordet sbordet@intalio.com
  14. 14. WebSocket  Effort Initiated by Browser Vendors to  Bidirectional low latency communications  Replace Comet HTTP “hacks”  Implement rich web applications within the browser  Standardized  IETF – RFC 6455 wire protocol  W3C – HTML 5 Javascript API  JCP – JSR 356 Java API  Jetty 7 was one of the first Servlet containers to support WebSocket (2009)  Jetty 9.1 supports JSR 356 Simone Bordet sbordet@intalio.com
  15. 15. WebSocket Upgrade  Runs on port 80 (or 443 for wss)  Uses HTTP/1.1 Upgrade mechanism REQUEST GET / HTTP/1.1 Host: localhost:8080 Origin: http://localhost:8080 Connection: Upgrade Upgrade: websocket Sec-WebSocket-Key: SbdIETLKHQ1TNBLeZFZS0g== Sec-WebSocket-Version: 13 RESPONSE HTTP/1.1 101 Switching Protocols Connection: Upgrade Upgrade: websocket Sec-WebSocket-Accept: y4yXRUolfnFfo3Jc5HFqRHNgx2A= Simone Bordet sbordet@intalio.com
  16. 16. HTTP Performance  Jetty-7.6, CometD-2.4, chat application  HTTP Simone Bordet sbordet@intalio.com
  17. 17. WebSocket Performance  Jetty-7.6, CometD-2.4, chat application  WebSocket Simone Bordet sbordet@intalio.com
  18. 18. WebSocket Deployment  Browsers  Java Servers  Firefox 11 (Android 15)  Jetty 7, Jetty 8, Jetty 9  Internet Explorer 10 PP5  Jetty 9.1 (JSR 356)  Chrome 16 (Android 18)  Glassfish  Safari 6 (iOS 6)  Resin 4  Opera 12.1 (Mini N/A)  Tomcat 7 (alpha)  Blackberry 7.0  Tomcat 8 (JSR 356)  Jetty Client 7, 8, 9 73% browser coverage (mobile too) (http://caniuse.com/websockets) Simone Bordet sbordet@intalio.com
  19. 19. SPDY Simone Bordet sbordet@intalio.com
  20. 20. SPDY is LIVE!  SPDY is a live experiment to improve HTTP  Addresses HTTP 1.1 limits  Designed to be faster and better than HTTP  Already widely deployed!  Google, Twitter, Facebook, WordPress, Webtide, etc.  Chrome & Firefox & IE 11  The SPDY protocol replaces HTTP on the wire  But it's transparent for applications Simone Bordet sbordet@intalio.com
  21. 21. SPDY & Jetty  Jetty 7 & Jetty 8  SPDY added by mocking HTTP wire protocol  Multiplexing requires mock protocol per channel  Jetty 9  Re-architected to separate wire protocol from semantics  HTTP semantics shared between HTTP, SPDY & FastCGI  HTTP, SPDY, WebSocket, TLS 1st class citizens  Use SPDY now!  ZERO changes to your existing web applications  Your use case can make Jetty, SPDY & HTTP 2.0 better Simone Bordet sbordet@intalio.com
  22. 22. SPDY Protocol Initiation  SPDY uses TLS (aka SSL) connection on port 443  TLS extended with Next Protocol Negotiation  New framing protocol over TLS  Intermediaries don't know it is not HTTP wrapped in TLS  Transports existing HTTP Semantics (GET, POST, HEAD etc)  Client and Server application don't know it is not HTTP Simone Bordet sbordet@intalio.com
  23. 23. SPDY Multiplexing  Multiplexing is built-in SYN_STREAM SYN_REPLY SYN_STREAM SYN_REPLY SYN_REPLY DATA DATA SYN_STREAM SYN_REPLY Simone Bordet sbordet@intalio.com
  24. 24. SPDY Multiplexing  Multiplexing  Allows to make better use of TCP connections  Reduces TCP slow start  Uses less resources on the server  Responses may be sent out of order  Without waiting for slow responses  Key point: reducing round trip waits  Caused by limited connections and lack of multiplexing Simone Bordet sbordet@intalio.com
  25. 25. SPDY Push  SPDY Push  Server pushes secondary resources that are associated to a primary resource  Works in collaboration with browser's cache for a better user experience  Jetty is one of the first SPDY servers that provides automated push functionalities  Totally transparent for applications  Based on the “Referrer” header  To associate primary and secondary resources  Using “If-Modified-Since” header to avoid unnecessary pushes Simone Bordet sbordet@intalio.com
  26. 26. SPDY Push HTTP/1.1 index.html application.js style.css image1.png Push Cache SPDY/3 + PUSH Simone Bordet sbordet@intalio.com index.html appliction.js style.css Image1.png
  27. 27. SPDY Clients  Desktop  Mobile  Firefox 13  Android Browser 4.1  Chrome 4  Chrome for Android 18.0  Opera 12.1  Firefox Android 15.0  Jetty Client 7, 8, 9 55% browser coverage (mobile too) (http://caniuse.com/spdy) Simone Bordet sbordet@intalio.com
  28. 28. DEMO Simone Bordet sbordet@intalio.com
  29. 29. Jetty 9.1 Simone Bordet sbordet@intalio.com
  30. 30. Jetty 9.1  Polyglot (HTTP, WebSocket, SPDY, FastCGI)  Servlet 3.1 ready  Great as a production server too  Not a monolithic server  Pick only the modules you need  Tons of configuration possibilities  Easy to customize  “Jetty was one of the first servers to ...”  Early adopters find the edge features they want in Jetty  Late adopters benefit of the experience Jetty gathered Simone Bordet sbordet@intalio.com
  31. 31. Jetty 9.1 Performance  Great performance  Easy to push it to 70k or more requests/s  These are Servlet requests not just http ones  Easy to get it to 250k connections  Servlet 3.1 on par with Servlet 3.0  But with less threads  Intalio/Webtide commercial support Simone Bordet sbordet@intalio.com
  32. 32. Servlet 3.1 public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { AsyncContext asyncContext = request.startAsync(request, response); asyncContext.setTimeout(0); ReadListener reader = new AsyncReader(asyncContext); ServletInputStream input = request.getInputStream(); input.setReadListener(reader); } Simone Bordet sbordet@intalio.com
  33. 33. Servlet 3.1 public class AsyncReader implements ReadListener { private final AsyncContext asyncContext; ... public void onDataAvailable() throws IOException { ServletInputStream input = asyncContext.getRequest().getInputStream(); ... } public void onAllDataRead() throws IOException { ... } } Simone Bordet sbordet@intalio.com
  34. 34. Servlet 3.1 public class AsyncWriter implements WriteListener { private final AsyncContext asyncContext; ... public void onWritePossible() throws IOException { ServletOutputStream output = asyncContext.getResponse().getOutputStream(); ... if (finishedWriting) asyncContext.complete() } } Simone Bordet sbordet@intalio.com
  35. 35. Servlet 3.1 Echo Servlet Blocking I/O public class SyncServlet extends HttpServlet { protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { byte[] buffer = new byte[BUFFER_SIZE]; while (true) { int read = request.getInputStream().read(buffer, 0, BUFFER_SIZE); if (read < 0) break; response.getOutputStream().write(buffer, 0, read); } } } Echo Servlet Async I/O public static class AsyncServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { AsyncContext asyncContext = request.startAsync(request, response); asyncContext.setTimeout(0); Echoer echoer = new Echoer(asyncContext); request.getInputStream().setReadListener(echoer); response.getOutputStream().setWriteListener(echoer); } private class Echoer implements ReadListener, WriteListener { private final byte[] buffer = new byte[BUFFER_SIZE]; private final AsyncContext asyncContext; private final ServletInputStream input; private final ServletOutputStream output; private boolean complete; private Echoer(AsyncContext asyncContext) throws IOException { this.asyncContext = asyncContext; this.input = asyncContext.getRequest().getInputStream(); this.output = asyncContext.getResponse().getOutputStream(); } @Override public void onDataAvailable() throws IOException { while (input.isReady()) { int read = input.read(buffer); output.write(buffer, 0, read); if (!output.isReady()) return; } if (input.isFinished()) { complete = true; asyncContext.complete(); } } @Override public void onAllDataRead() throws IOException { } @Override public void onWritePossible() throws IOException { if (input.isFinished()) { if (!complete) asyncContext.complete(); } else { onDataAvailable(); } } @Override public void onError(Throwable failure) { failure.printStackTrace(); } } } Simone Bordet sbordet@intalio.com
  36. 36. Jetty 9.1  Jetty HttpClient  High Performance HttpClient with fluent API  70% faster than Jetty 8's HttpClient  Pluggable transports (HttpClient can speak SPDY)  HTTP Proxy  SPDY Proxy  Jetty FastCGI  Jetty can serve PHP / Python / Ruby / etc. Simone Bordet sbordet@intalio.com
  37. 37. HTTP 2.0  HTTP 2.0 work has started  IETF HTTPbis working group rechartered  Two proposals received:  Google - SPDY as the basis  Microsoft – WebSocket framing with HTTP semantics  SPDY Adopted as the starting point  Unlikely to require TLS or NPN  Will define precise interactions with proxies  Early draft available  http://tools.ietf.org/html/draft-ietf-httpbis-http2-06 Simone Bordet sbordet@intalio.com
  38. 38. Conclusions Simone Bordet sbordet@intalio.com
  39. 39. Conclusions  The Web is evolving  Web Protocols are evolving  Servers must keep the pace with new Web Protocols  Try WebSocket today  Production ready  Try SPDY today  Check your application is ready for the future  Check the future is ready for your application Simone Bordet sbordet@intalio.com
  40. 40. Questions & Answers Simone Bordet sbordet@intalio.com
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×