Programming For Performance: Alosh Bennett
Programming For Performance: Alosh Bennett
Alosh Bennett
What is performance?
Overall feel of the system, its quickness and responsiveness.
Is perceived as
Responsiveness of the system
Throughput
Scalability
Startup time
Other factors
Reliability of the system
Availability
How to build a performing system?
Requirements Gathering
Scope of the application
What it is and what it is not.
Real world estimation of usage
Application Architecture
Blueprint of the project
Identify the technologies
Components of the application
Interaction
Pseudocode
Logic of individual components
Algorithms and Data Structures
Coding
Coding standards
Good practices
Blog
jsp or php
Online Transaction site
Industry grade server – Apache, glassfish, weblogic
J2ee or similar framework
Database – mysql, oracle, postgres
Rich content website
Javafx, flex, htm5
Avoid applets
Task Automation
Scripting languages – python, perl, shell
Avoid java, C
Concurrent processing with multiple processors
Scala over java
Mathematical modeling – Computation intensive
Functional programming over Object Oriented
XML Parsing in java
DOM Parser
SAX Parser
Stax Parser
Application Architecture – Harness the processing power
Multi-threaded model
Threads work on the same data
The data is not transferred between workers
Ideal when the job at hand involves huge data
Eg.
Windows registry
All processes work on the same registers
Different processes read/update different part of registry.
Input/Output
File systems and other IO are slow
Not good at reading/writing a byte at a time
Read a chunk of data and pass it to application one byte at a time
Network
Sending/fetching data across network is slow and unreliable
Take youtube for example
Player doesn’t fetch a frame at a time and show it to user
Keep reading over the network whether video is playing or paused
Write the frames into a buffer
Player reads from the buffer and plays the video
Bulk action is always cheaper than repeating it for each set of data
Common overhead is spread across the dataset
Uploading photos to Picasa
Authenticate user credentials and login
Establish a connection
Upload a picture
Close the connection
For uploading 10 pictures, you wouldn’t repeat the four steps 10 times
Bulk upload
Authenticate user credentials and login
Establish a connection
Upload first picture
Upload second picture
…
Upload last picture
Close the connection
Arrays
Easy to loop
Random access of elements
Insert and delete in the middle is difficult
Good at searching – log(n)
Link Lists
Easy to loop
Random access of elements is not possible
Insert and delete in the middle is easy
Bad at search – log(n)
Use of XML
XML is a great tool to exchange information in a platform neutral manner
XML takes considerable bandwidth on the wire
Avoid unnecessary conversion of object to XML and back
Use the right parser
DOM vs SAX vs Stax
Evaluate other formats like JSON
Logging
Excessive logging is trouble
Never log to System.err or System.out
Use logging frameworks
Responsive Application
Benchmarking
Measurement of memory, time and CPU usage of the application
Compare benchmarks of different approaches
Profiling
Profiling tells more about your code execution paths
What methods are called often?
What methods are using the largest percentage of time?
What methods are calling the most-used methods?
What methods are allocating a lot of memory?
Profiling tools
VirtualVM
Netbeans Profiler
Graceful Degradation
How should your application behave when to load is too much to handle?
System should never become completely useless
System should never crash
The application could refuse to take new requests and display a message
In certain cases, its possible to degrade the quality of the results and still keep
up the response time
Eg. Search engines
Voice transmission over the network
http://java.sun.com/docs/books/performance/1st_edition/html/JPTOC.fm.html
http://www.javaperformancetuning.com/tips/index.shtml
http://en.wikipedia.org/wiki/Sorting_algorithm
http://java.sun.com/developer/onlineTraining/collections/Collection.html
Thank You