老舊web上雲端
Post on 28-Jul-2015
168 Views
Preview:
TRANSCRIPT
老舊 Web + 老舊機器
IT人蔘的
困境Linux www.iradiopop.com 2.6.26.8-57.fc8 #1 SMP Thu Dec 18 18:59:49 EST 2008 x86_64 x86_64 x86_64 GNU/Linux
檢討
request
business logic
cache
db query
舊機器的 CPU 比雲端還快,
所以「原本快的變慢了」
for(…) { for(…) { for(…) { /* 很暴⼒力地過濾資料 */ } } }
惡搞 Active Cache
Active Cache
資料過期前(時),主動重抓資料
現有的 Library
guava CacheLoader
BUT legacy code 太難改,
決定以不改 code 為目標
惡搞 Active Cache
使用 AOP 插入 Advice
讓 business logic 支援 Active Cache
1. 將 method call 轉成 cache key
2. 註冊 method call 至 cache refresh scheduler
active cache
惡搞 Active Cache
request business logic
KEYCached Refresh Scheduler
business logic
method call to cache key
register key + method call to scheduler
active cache
惡搞 Active Cache
request business logic
Cached Refresh Scheduler
cache storage
auto refresh
business logic
使用者看到的
business logic
真正的
business logic
惡搞 Active Cache
ActiveCache 本來是為了「減少等待時間」設計
放在雲端上,恰巧減少了 Busy Job 搶資源的問題.
經由 cache refresh scheduler 限制 Loading
實作 Active Cache
methodA(userInfo, str, int, map, otherPojo)
key = signature_ + args[0] + args[1] + args[⋯]
=> methodA_User@a3a4a3a5_str_3_{a:3,b:3}_
=> methodA_user1_str_3_{a:3,b:3}_ 有些物件 toString 後的結果不合用,換成其他特徵代替
實作 Active Cache
有些物件,沒有 getter 能取得特徵!
用 AOP 攔截建構子參數,製作識別資料
methodB(userList, comparator)
=> methodB_user1_user2_⋯_comparator@1a2b
=> methodB_user1_user2_⋯_cmp@SortByDate
實作 Active Cache
Active Cache 如何知道該更新了?
是 User 呼叫的就吐 Cache
是 Scheduler 呼叫的就 Refresh
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
stacktrace 看到 HttpServlet.service 就當他是 User 唄
遠方
好遠. 夭壽遠
filter
CDN
HTTP 304
原來我們這麼近
request / response
服務直到世界的盡頭
利用 CDN 傳遞動態資料,適合簡單的 RESTFUL Service
cached url
遠方服務直到世界的盡頭
如何使 Cache Expire ?
CDN invalidation 很慢,換路徑很快
http://cdn/time-window-token-r/cache-key
http://cdn/time-window-token-g/cache-key
http://cdn/time-window-token-b/cache-key
⼩小⼼心安全問題,不要放敏感資料
top related