Bug #2198
Sometimes unable to generate the reports from the GUI.
Start date:
03/17/2022
Due date:
05/20/2022
% Done:
100%
Estimated time:
Added by Ayush Khandelwal over 2 years ago. Updated over 2 years ago.
100%
The followings are the things I did to find the reason for java.lang.OutOfMemoryError: Java heap space
Tested the top traffic by adding system.gc() at the end of the loop(loop for collecting and processing 100 by 100 logs every time until the size of the logs) - the memory usage is not increasing continuously
Tested the top traffic by not adding system.gc() at the end of the loop(loop for collecting and processing 100 by 100 logs every time until the size of the logs) - the memory usage is increasing continuously
converted the static methods to normal methods(without adding system.gc() at the end of the loop)
private static String getLogEntries(String accessToken, String nextPageToken, String projectId , String startTime , String endTime, SERVICE serviceType)
private static JsonObject getTheRequestBody(String projectId, String startTime, String endTime, String nextPageToken, SERVICE serviceType)
private static String getTracesEntries(String accessToken, String nextPageToken, String projectId , String startTime , String endTime)
- the memory usage was still increasing continuously.
Added the code parts inside the loop in a separate method
- the memory usage was still increasing continuously.
Non-static Inner Class may cause memory leaks. TopTrafficMaps is an inner class present in the ExcelGeneration.java, I checked whether it is defined as static or not. TopTrafficMaps is a static inner class.
To do:
Do the profiling technique to detect the memory leak. There are some profiling tools like JProfiler which can be integrated into the eclipse.
TopTrafficMaps class is the class that has three maps where we are storing the details of the logs in the maps for every 100 by 100 logs. Instead of using TopTrafficMaps, we can write the logs directly into the respective sheets of the workbook and see whether the memory usage is constantly increasing for this.
Used Gson Streaming:
You can use JSON Object/ JSON Array only if the size of your json data is less than 1MB. Else you should go with JSONReader. JSONReader actually use streaming approach while JSONObject and JSONArray eventually load all the data on RAM at once which causes OutOfMemoryException in case of bigger json.
(reference:
https://sites.google.com/site/gson/streaming
https://stackoverflow.com/questions/14742902/parse-json-data-using-jsonreader-or-jsonobject-jsonarray
)
Untraceable. so, closing it for now