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.
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. Agenda
Jetty Introduction
Web History and Evolution
Web Protocols
Jetty Features & Performance
The future: HTTP 2.0
Simone Bordet
sbordet@intalio.com
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
6. w3c.org 1996
HTTP 1.0 protocol designed to serve these pages:
1 HTML File, 600 Bytes
Simone Bordet
sbordet@intalio.com
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. 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
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. 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
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
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. 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. 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. 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. 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. 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
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. 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
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. 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. 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. 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. 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
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