Memory leak in XDocReport version 2.0.1
This is one of my interesting tasks that I have been assigned in my company.
When I arrived my workplace about 2 weeks. My leader gave me a task which would fix the issue existed since 3 years.(I dont knew this :-) then I think it is a simple issue and very excited with this task)
All I know about this issues is that it is a restful webservice built by Java and running in Tomcat. It always stops working after running 3 4 working days. And Catalia logs throw "Out of heap memory".
So I wondered that what caused this exciting issues. I thought that if I fix it completely then I will got an unforgettable memory in my life.
The first step: Get all source code and run it in my localhost to see what happened
The is no thing happened. :-( . Then I watch the source code carefully and I saw a synchonized block code in a service. I thought that it can caused this issue when so many Request call this service at the same time. Then I use Jmetter to call about 500 request in a period of time. And the Server Stoped working.
As you saw. That time I am confident to fix this error. But ...... It is not the root cause. Because I try to remove the block code and Server still died when it recived about 500 Request.
So what is the root cause............
I saw this service carefully again and saw everything there is Java core code except XDocReport codes.
So I thougt that maybe the library caused Memory leak. I removed it and run server again and request 500 times and NO Error happened.
It is clearly now. So What I have to do now, I can not remove the block code. Because this service generate a report.
IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in, TemplateEngineKind.Velocity);
Searching google and it says that Memory leak in this XdocReport version 2.0.1
Because
When I arrived my workplace about 2 weeks. My leader gave me a task which would fix the issue existed since 3 years.(I dont knew this :-) then I think it is a simple issue and very excited with this task)
All I know about this issues is that it is a restful webservice built by Java and running in Tomcat. It always stops working after running 3 4 working days. And Catalia logs throw "Out of heap memory".
So I wondered that what caused this exciting issues. I thought that if I fix it completely then I will got an unforgettable memory in my life.
The first step: Get all source code and run it in my localhost to see what happened
The is no thing happened. :-( . Then I watch the source code carefully and I saw a synchonized block code in a service. I thought that it can caused this issue when so many Request call this service at the same time. Then I use Jmetter to call about 500 request in a period of time. And the Server Stoped working.
As you saw. That time I am confident to fix this error. But ...... It is not the root cause. Because I try to remove the block code and Server still died when it recived about 500 Request.
So what is the root cause............
I saw this service carefully again and saw everything there is Java core code except XDocReport codes.
So I thougt that maybe the library caused Memory leak. I removed it and run server again and request 500 times and NO Error happened.
It is clearly now. So What I have to do now, I can not remove the block code. Because this service generate a report.
IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in, TemplateEngineKind.Velocity);
Searching google and it says that Memory leak in this XdocReport version 2.0.1
Because
Because loadReport() default cached template
return loadReport( sourceStream, templateEngineKind, true ); <--- cache
return loadReport( sourceStream, templateEngineKind, true ); <--- cache
So About 500 Request will out of memory. To check this I used JVisualVM to check heap memory.
To fix this, I change my code to
IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in, false,TemplateEngineKind.Velocity);
This will not be cache and not memory leak
You can change the lib to 2.0.2( not memory leak anymore)
That is the best memories in my life
Comments
Post a Comment