當遇到效能問題時,我們該怎麼辦?
分治策略
1.首先我們應將整個專案細分成多個模組
2.測試每乙個模組的效能,找出每乙個模組的問題,分而治之
3.每乙個模組的效能都解決了,那麼整合到一起的專案效能問題舊解決了
如何gettickcount測試單個介面的呼叫時間?
1.系統api
gettickcount(); //時間解析度大概15ms~16ms
2.#include
clock(); //時間解析度大概1ms
如何記錄測試資料?
1.直接呼叫vs提供的outputdebugstring()輸出至vs的output視窗
2.寫入檔案
測試案例**
例一:輸出至vs output視窗
void
timetest
(wchar_t
* pstr, bool bbegin)
; dword dtime =
clock()
; bbegin ?
wsprintfw
(szbuf,l"%s:,begin: %d\r\n"
,pstr,dtime)
:wsprintfw
(szbuf,l"%s:,end : %d\r\n"
,pstr,dtime)
;outputdebugstring
(szbuf)
;}
例二:寫入檔案
void
testlocaltime
(const tchar* pstr, bool bbegin)
; dword dtime =
clock()
; bbegin ?
wsprintfw
(szbuf, l"%s:,begin: %d\r\n"
, pstr, dtime)
:wsprintfw
(szbuf, l"%s:,end : %d\r\n"
, pstr, dtime)
; file *pfile =
null
; pfile =
fopen
("c:\\test\\1.txt"
,"ab");
if(!pfile)
return
;int len =
wcslen
(szbuf)
;fwrite
(szbuf,
sizeof
(tchar)
,wcslen
(szbuf)
, pfile)
;fclose
(pfile)
;}
Web專案效能問題常見定位方法梳理
定位方法 kill 3或者jstack先分析執行緒堆疊,找到當前block的執行緒。常見於 外部介面呼叫無返回或者網路io阻塞無響應 死鎖 死迴圈 定位方法 這一類問題普遍比較難定位 1 尋找hs err pid log這樣的jvm日誌 2 使用jvm引數在jvm crash時寫入到dump檔案中 ...
Web專案效能問題常見定位方法梳理
定位方法 kill 3或者jstack先分析執行緒堆疊,找到當前block的執行緒。常見於 外部介面呼叫無返回或者網路io阻塞無響應 死鎖 死迴圈 定位方法 這一類問題普遍比較難定位 1 尋找hs err pid log這樣的jvm日誌 2 使用jvm引數在jvm crash時寫入到dump檔案中 ...
Web專案效能問題常見定位方法梳理
定位方法 kill 3或者jstack先分析執行緒堆疊,找到當前block的執行緒。常見於 外部介面呼叫無返回或者網路io阻塞無響應 死鎖 死迴圈 定位方法 這一類問題普遍比較難定位 1 尋找hs err pid log這樣的jvm日誌 2 使用jvm引數在jvm crash時寫入到dump檔案中 ...