lecture 6 - nus computing - homeooiwt/cs3283/lect6.pdf · 2017-02-17 · 2. people want to get...
TRANSCRIPT
Lecture 6 Performance
17 February 2017
Software Resources• CPU
• Memory
• Network
• Battery
• Disk
“People will visit a Web site less often if it is slower than a close
competitor by more than 250 ms.”
“Half a second delay caused a 20% drop in
traffic”
“We tried delaying the page in increments of 100 milliseconds and found that even
very small delays would result in substantial and costly drops in revenue”
“We tried delaying the page in increments of 100 milliseconds and found that even
very small delays would result in substantial and costly drops in revenue”
Page load time of <1s feels immediate
Response time of <200ms feels instantaneous
Reduce size of Web page• Optimize the images
• Load only necessary scripts
• Minimize the scripts / CSS / HTML
Easy. Not focus of this lecture.
Improve Performance• Faster DB accesses
• Better data structures and algorithms
• Fewer connections / downloads
• Etc.
Need Deep CS Knowledge
“Premature optimization is the root of all evil”
- Don Knuth
“Make it run Make it right Make it fast”
— Kent Beck
Tips
• If you can’t stand how slow your code is, optimize now (after making your code works correctly)
• Otherwise, wait until you have most of the features done
while (performance is bad) find bottleneck remove bottlebeck
Use code profiler (there is one for every language I used)
Typical Profiler Output• function name
• absolute time spent in function
• % of time spent in function
• how many times the function is called
• parent functions, etc.
Example of Performance Issues
Unnecessary Disk I/O
What every programmer should know
Unnecessary Memory Copies
Unnecessary Format Conversion
Unexpected Interactions Between Components
Unexpected Locking
Unexpected SQL / database access
Slow SQL Queries (esp using ORM)
Unnecessary Network Communications
Bad data structures and algorithms
def concat1(): out_str = '' for num in xrange(loop_count): out_str += ‘a ‘ return out_str
def concat2(): return ‘ ‘.join([‘a’ for num in xrange(loop_count)])
Memory leaks
Garbage Collection
Common Techniques for Improving Performance
Pre-computation
Caching
Pre-fetching
Pipelining Threading
Parallelizing
Your Task
• Find performance bottleneck (if any)
• Optimize it away
• Report what you did and the performance gain
• Example: https://nus-mtp.github.io/1516/images/polaris-proj-report-6.1.pdf
Sometime, you can make things feel faster
The Psychology of Waiting Line
(David Maister)
1. Occupied time feels shorter than unoccupied time
Example: Amazon, Facebook
2. People want to get started
Example: YouTube
3. Uncertain waits are longer than known, finite waits
4. Unexplained waits are longer than explained waits
5. Unfair waits are longer than equitable waits
6. The more valuable the service, the longer the customer will wait
7. Solo wait feel longer than group waits
The case of fake progress bar..