我有一個java程序使用以下邏輯:Java程序的性能問題
i) Open a socket server and wait for messages from client
ii) Read messages received(fixed length records of about 233 bytes).
iii) on each message receive, call a process function.
iv) process function does follwing
- add the record to the string builder.
- if (length of stringbuilder > configured buffer size) {
process this buffer
} else {
add the new record to buffer
}
現在當我嘗試這個節目有100萬條記錄,每233個字節,大約需要5分30秒結束。我想減少這個時間。大量的時間在這個過程函數中被浪費了。
我正在檢查是否可以得到一些關於如何重新組織這個過程()以獲得更好的性能的建議。 我的用例是獲取記錄並讀取它們,直到達到配置的緩衝區大小(如50 Mb或500 MB或1 GB)。一旦達到此大小,處理它並寫入文件系統。
@ user656189如果時間花在流程函數上而不是數據傳輸上,我們需要看到的是您在流程函數中所做的事情,您不覺得嗎? – 2011-04-27 23:09:47
您是否考慮過在您的IDE中使用某種形式的性能測試插件來查看瓶頸位置? – Endophage 2011-04-27 23:10:15
@Endophage - cud你建議一些選擇嗎? – user656189 2011-04-28 20:41:04