平民  website

 performance

TonyQ

What's performance


Fast Feedback.

When to tune performance

Design ?
Implement ?
QA ? 
Production ?
Maintain ?

平民 Style

救火 STYLE

Who to tune performance

CASE STUDY 

A Story


Scenario

  1. Traffic increased
  2. New service released

Another Story 


SCENARIO

  1. Code issue

More detail

How to tune performance?

Profiling, 

Profiling, 

PROFILING 

Never write code 

for performance ?



NEVER WRITE CODE 

FOR PERFORMANCE 


BEFORE PROFILING

Profiling tools

Browser 


Database


Slow query log

      Ex. MySQL
[mysqld]
long_query_time=1
log-slow-queries=/var/log/mysql/log-slow-queries.log

server side

Find hot pages


$GLOBAL_TIME_START = microtime(TRUE);
$GLOBAL_TIME_LAST = microtime(TRUE);

function watch($MSG){
	global $GLOBAL_TIME_START;
	global $GLOBAL_TIME_LAST;
	$now = MICROTIME(TRUE);

	echo(",during:" .round($now - $GLOBAL_TIME_LAST,4) .",past:".round($now - $GLOBAL_TIME_START,4)).",DETAIL: $MSG
"; $GLOBAL_TIME_LAST = $now; }

PROFILING SAMPLE #1



PROFILING SAMPLE #2




PROFILING SAMPLE #3


front-end


function stopwatch(cb){
var start = new Date().getTime();
var ret = cb();
var end = new Date().getTime();
log(end-start );  return ret;
}

GA



Performance FAQ


Why it's so slow 

Don't Guess !

Profiling!

What we found so far

Database

BAD QUERY

join is evil

Order by rand()


ex. mysql  (with 91693 records)
SELECT * 
FROM  `KeyWords` 
ORDER BY RAND( ) 
LIMIT 4  
//查詢花費 1.7222 秒

"Hot!" info...

Third party dependency

youtube

facebook

email(smtp)

.
.
.

And others we didn't find


FRAMEWORK ISSUE

Avalanche multiplication

SOLUTIONS


MEthod

  • Refine Process
  • Cache
  • Index
  • Separate Long Operations

Refine process

KNOW YOUR PROCESS First.


ex. mysql  (with 91693 records)

SELECT *  from KeyWords ORDER BY RAND( ) 
LIMIT 4  
//查詢花費 1.7222 秒
vs
SELECT a . * FROM ( 
  SELECT a.No FROM KeyWords a  ORDER BY RAND( ) LIMIT 4 
) AS a2 INNER JOIN KeyWords a ON a.No = a2.No
//查詢花費 0.1377 秒

Cache

Counter cache
select sum(nums) from orderitems where UserID = 5;
vs 
select shopNums from user where UserID = 5; 

Cache

Page cache

Index "NEWS" / "HOT" Info ,
NOT REALLY required to be so HOT.

10 mins cache to save your database.

Cache

Cache third-party info if possible.

Cache


Not always cool!

DB Index

好的 Index 帶你上天堂
沒做 Index 帶你住套房

search index

Use search engine to do the search job.

  • Google custom search.
  • Lucense search engine.

Separate long operation

Email


Don't send mail during a form submit.

Facebook api


getFriendList...etc


SPLIT REQUESTS

Summary 

Profile your system!
Finding issue is way more difficult than fixing it.

Q & A

special thanks


資料使用授權:
Mamibuy 華人第一嬰兒用品推薦網站
5945


工商服務

JavaScript.tw

  • 台北(每兩週)
  • 台中(每月)
  • 高雄(每六週)

致力推廣 JS 及web 前端相關議題!
http://fb.javascript.tw 

JSDC.tw

五月中!
JSDC rocks! yep!
積極尋找贊助中!歡迎來信!
(hq@jsdc.tw)

Thanks

website performance

By TonyQ Wang

website performance

  • 8,090