Upload
sandeepmathoor8218
View
240
Download
0
Embed Size (px)
Citation preview
8/2/2019 App Engine Whats Hot in Java
1/33
1
8/2/2019 App Engine Whats Hot in Java
2/33
Whats Hot inJava for App EngineToby ReyeltsDon SchwarzMay 19, 2010
2
8/2/2019 App Engine Whats Hot in Java
3/33
Ask questions and take notes
View live notes and ask questions about
this session at:
http://bit.ly/appengine6
3
3
http://bit.ly/appengine6http://bit.ly/appengine6http://bit.ly/appengine68/2/2019 App Engine Whats Hot in Java
4/33
Agenda
Java support: one year later
Dance Dance Robot
Demo
Code study
Improvements
New functionality
Performance optimizations Improved compatibility
4
4
8/2/2019 App Engine Whats Hot in Java
5/33
App Engine for Java: one year later
We host 100,000 Java applications
Over 1/3rd of all App Engine apps
We serve 1000s of requests per second
Also host many applications with large traffic spikes
e.g. Gigya Socialize
5
5
8/2/2019 App Engine Whats Hot in Java
6/33
Demo
6
8/2/2019 App Engine Whats Hot in Java
7/33
Game Design
7
Transport
7
8/2/2019 App Engine Whats Hot in Java
8/33
Game Design
8
Task Queues
8
8/2/2019 App Engine Whats Hot in Java
9/33
Game Design
9
Storage
9
8/2/2019 App Engine Whats Hot in Java
10/33
Channel Service
Asynchronous Server Client Communication
Channel-based
Bi-directional
Server
Send messages via ChannelService object Receive messages in a web hook
Client
JavaScript library
Receive server messages in a callback
Built on Gmail chat client (Google Talk)
10
10
8/2/2019 App Engine Whats Hot in Java
11/33
Server API
Channel Service
/*** ChannelService allows you to manage two-way connections
* with clients.
*/
publicinterfaceChannelService {
/**
* Creates a channel associated with the provided applicationKey
*/String createChannel(String applicationKey);
/**
* Sends a ChannelMessage to the client.
*/
void sendMessage(ChannelMessage message);
/*** Parse the incoming message in request. This method
* should only be called within a channel webhook.
*/
ChannelMessage parseMessage(HttpServletRequest request);
}
11
11
8/2/2019 App Engine Whats Hot in Java
12/33
Client API
Channel Service
12
Languages JavaScript
Java (Google Web Toolkit)
Sample codevar channel = new wnd.goog.appengine.Channel(channelId);
var socket = channel.open();
socket.onopen = function(event) {
// socket is now fully functional
};
socket.onmessage = function(event) {
// handle string msg (event.data)
};
socket.send(msg);
12
8/2/2019 App Engine Whats Hot in Java
13/33
Task Queue Service
Allows you to do work in the background
Up to 50 requests/sec of offline requests
Works in DevAppServer
Automatic execution at specified rates
Can see individual tasks and execute manually
Tasks can take part in a datastore transaction
Enqueue a task only when a commit succeeds
13
13
8/2/2019 App Engine Whats Hot in Java
14/33
Blobstore Service
Allows users to upload large files
File upload handled by our infrastructure
You get a callback with a blob reference
Can query, delete existing blobs
Blobs can be served back to the user (streaming)
Or retrieved a chunk at a time programatically
Images API can take blobs as input source
Useful for thumbnailing user-provided images
14
14
8/2/2019 App Engine Whats Hot in Java
15/33
Appstats
Easy to use profiling of API calls for perf tuning
In Java, usesApiProxy wrapper technique
Mentioned in last years Google I/O session
Stores API call data to memcache
Built-in servlet renders results and timing stats
15
15
8/2/2019 App Engine Whats Hot in Java
16/33
New functionality
16
8/2/2019 App Engine Whats Hot in Java
17/33
Datastore improvements
Cursors
Can iterate over results across HTTP requests
No more 1000 query limit
Bulk ID allocation
Makes bulk upload feasible
Opt-in to eventual consistency
Can speed up queries if stale data is good enough
Statistics
Admin Console graphs of entity counts, sizes Can be queried programmatically also
Many JDO/JPA improvements
17
17
8/2/2019 App Engine Whats Hot in Java
18/33
URLFetch improvements
Deadlines are now configurable
Up to 10 secs per request
Asynchronous API calls
Make up to 10 simultaneous calls from each request
Future-based API:
Future fetchAsync(HTTPRequest)
Other APIs will expose asynchronous APIs in the future
18
18
8/2/2019 App Engine Whats Hot in Java
19/33
Better integration through web hooks
XMPP API
Can send and receive XMPP messages
Incoming email
Receive email as an HTTP callback
Google Wave API v2
Allows active Wave robots as well as passive
19
19
8/2/2019 App Engine Whats Hot in Java
20/33
Unit testing support
Run unit tests using local API implementations
Unit testing infrastructure in a separate jar
appengine-testing.jar
ConfiguresApiProxy to discover API impls on classpath
TestConfig classes let you configure each API
Datastore disk usage disabled by default
Easily specify max memcache size
20
20
8/2/2019 App Engine Whats Hot in Java
21/33
Performance optimizations
21
8/2/2019 App Engine Whats Hot in Java
22/33
Precompilation
Process application bytecode at deployment time
Allows many Java libraries to work in our sandbox
Saves time during loading requests
Opportunity for more expensive optimizations
Occasionally need to re-process bytecode for all apps
Process each unique file only once
Total bytecode: only ~35 GB
22
Application files (checksums)
Never-before-seen files
Compilation chunks
22
8/2/2019 App Engine Whats Hot in Java
23/33
Loading request latency (before and after)
Precompilation results
23
ORM
JRuby
(Rack)
Rhino(Helma NG)
Real-world App #1
Real-world App #2
0 5 10 15 20
Application time API calls Garbage collection
Hotspot compilation Bytecode processing
23
8/2/2019 App Engine Whats Hot in Java
24/33
Reflection Optimizations
Big improvements
Caching reflection access checks
Failure can be expensive
Sample Grails app
11K (!) reflective methods calls in loading request
50% against three methods
Conclusion 10% faster startup for Groovy and JRuby
24
24
8/2/2019 App Engine Whats Hot in Java
25/33
getMethod(java.lang.String.indexOf)
getMethod(ReflectTestTarget.foo)
invoke(java.lang.String.indexOf)
getDeclaredFields
getDeclaredMethods(java.lang.Object)
getConstructors(java.lang.Object)
getConstructors(java.lang.String)
getConstructors(CustomURLClassLoader)
setAccessible succeeded
0 15 30 45 60
Reflection Performance Part 1
Old New
25
8/2/2019 App Engine Whats Hot in Java
26/33
getDeclaredFieldFailed
getDeclaredMethods(java.lang.String)
getDeclaredMethods(CustomURLClassLoader)
getDeclaredMethods(org.mortbay.jetty.Response)
setAccessible failed
0 625 1250 1875 2500
Reflection Performance Part 2
Old New
18,000!
26
8/2/2019 App Engine Whats Hot in Java
27/33
Future performance improvements
API call and I/O latency
Much faster memcache calls
Reduced JIT and GC time
Improved parallelization
Reserved instances
Dedicated JVMs to reduce loading requests
Will cost money, details coming soon Grants greater visibility into use of JVMs
27
27
8/2/2019 App Engine Whats Hot in Java
28/33
Improved Compatibility
28
8/2/2019 App Engine Whats Hot in Java
29/33
Opened up more of the JRE
Libraries
JAXB (javax.xml.bind)
StAX (javax.xml.stream)
XPath (javax.xml.xpath)
Additional classes
javax.annotation.Resource
javax.annotation.Resources
java.util.zip.ZipConstants
Many inner classes required for serialization
29
29
8/2/2019 App Engine Whats Hot in Java
30/33
More supported libraries
Just to name a few
Hessian (4.0.6)
JDOM (1.1)
Jersey (1.1.5)
MyFaces (2.0.0)
OpenAMF
PureMVC
Restlet (2.0M5)
Struts 2
Tapestry (5.1)
VRaptor (3)
Vaadin (6.1)
Wicket
...
30
30
8/2/2019 App Engine Whats Hot in Java
31/33
DevAppServer Sandbox Emulation
New
WhiteList enforced
Works for reflection, too.
Reflection permissions enforced
How?
Bytecode instrumented by JVM agent
Runtime shim modifies app behavior
All perfect then?
Unfortunately still a few corner cases
31
31
8/2/2019 App Engine Whats Hot in Java
32/33
Resources
Speakers:
Toby Reyelts
Don Schwarz
Questions and notes:
http://bit.ly/appengine6
Demo source code:
http://code.google.com/p/dance-dance-robot http://dance-dance-robot.appspot.com
32
32
http://dance-dance-android.appspot.com/http://code.google.com/p/dance-dance-androidhttp://bit.ly/appengine6http://dance-dance-android.appspot.com/http://dance-dance-android.appspot.com/http://code.google.com/p/dance-dance-androidhttp://code.google.com/p/dance-dance-androidhttp://bit.ly/appengine6http://bit.ly/appengine6mailto:[email protected]:[email protected]:[email protected]:[email protected]8/2/2019 App Engine Whats Hot in Java
33/33