Macro Process: when play a music on a web page
Remote request - Local prepare - Remote reply - Local process
- Step 0, Browser prepare
- DNS
- Step 1, Browser Send DNS request
- Step 2, Prepare DNS reply
- Step 3, Send DNS reply
- Step 4, Browser Process DNS reply
- Web Server
- Step 5, Browser Send webpage request
- Step 6, Prepare webpage reply
- Step 7, Send webpage reply
- Step 8, Browser Process webpage
- Music player
- Step 9, Browser Request music player
- Step 10, Prepare music palyer
- Step 11, Send music player
- Step 12, Browser process music player
- File Server
- Step 13, Browser request MP3 file
- Step 14, Prepare MP3 file
- Step 15, Send MP3 file
- Step 16, Browser Play MP3 file
How to Collect failure log
- when user access webpage, server log it
- when user can play music, user send a log to server
- without user send, server cannot determine whether music is successfully palyed
Failure sub problems: music cannot be played
Local Client can bypass DNS Server part
DNS Server part
- Step1, Check local Hosts file
- HOSTS hijack, someone modify hosts file, point website to somewhere
- Solution: hosts file analysis by our software
- Step2, DNS server analysis by ISP (Internaet Service Provider)
- some ISP fails to update the latest DNS after changing server address
- Solution: talk to ISP
- Check itself or ask others (poison form others)
- Send IP address back (hijacked by middleman)
- Blocked by some companies' networking
- Step1, Check local Hosts file
Web Server part
Peak time: reverse proxy with more servers, nigix
do the similar job to load balancer
receptionist, dispatch request, reduce thread change,
More than load balancer: cache, group request
Reduce the size of webpage: simplify content, compress/merge images, lazy load
More cacheable pages: change dynamic webpage into static webpage
server side caching
client side caching
User may just close....webpage, failure cannot rule out
Music Player
Step 13, network error: repair / remove failure server.
Step 14, failing to find MP3 file: URL may expired. Server need sync clock routinely
Step 15, connection timeout: Optimize CDN(COntent Delivery Network), Compress MP3 with lower bitrate, Pre-loading
Step 16, play MP3 failure: maybe a bug in audio transcoding, re-transcoding the bad files
Other: user just close, versions of flash platers, iOS device may not support, develop HTML5 player
Validate Improvement
- daily active users? No, it depends on too many factors
- one day retention rate? Yes, how many user re-enter or come back to the webpage. more is valuable.
Rate Limit - limit Query Per Second
algorithm of gap: limit the gap between two request
- bad case: maybe overhead. Change to time-bucket, 1second 1bucket
- Time Example: 1.1, 1.5, 1.6, 1.7, 1.8, 1.9 -> 6 request in 1s
How to limit requests in every one second?
- Save space without Database: reuse one time-bucket. When found current time != previous time, clean current bucket
- Database? : use 1 second as the key. when new comes, check current 1 second
How to limit requests in any one second? 1.2, 1.3, 1.5, 1.7, 1.9, 2.1 -> 6 request in 0.9s
- use requestList, every request will check previous 5th time, >1s OK, <1s drop
- reuse requestList
Follow up
- How to save space with 10^9 query per hour?
- Counter: simple one
- Batch queries: group request, 10^3 request one group
- How to support multiple threads?
- lock
- How to limiter on users?
- <uid, requestList>
- How to support query with different quotas?
- acquire(quota) -> Token Bucket