Birt Memory Usage [message #889849] |
Tue, 19 June 2012 18:05  |
Eclipse User |
|
|
|
So I have an RCP that makes use of BIRT to generate reports but what I am noticing is the significant memory usage. The key problem I have is that it does not free up the memory after it has produced the document. So on the first run of a BIRT report (producing a PDF file with a table and chart) the memory usage goes up by 60 to 70 MB which never then frees up after the report has run .... then each time I run the report the memory usage increases by 4MB
I've followed the standard tutorials on the web to create the report generator so pretty sure I am not doing anything stupid in the code.... Is this a common issue? Or where can I go to find out more info? Any info appreciated!
|
|
|
|
|
Re: Birt Memory Usage [message #889942 is a reply to message #889939] |
Wed, 20 June 2012 06:36   |
Eclipse User |
|
|
|
To make sure I have not made any rookie mistakes please see main body of code below.... any feedback appreciated!
// Set up engine config ready for engine
EngineConfig engineConfig = new EngineConfig();
engineConfig.setLogConfig("./birtlogs", Level.SEVERE);
// Create a new report engine factory
IReportEngineFactory factory = (IReportEngineFactory)Platform.createFactoryObject
(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
// Create a new report engine
IReportEngine engine = factory.createReportEngine(engineConfig);
engine.changeLogLevel(Level.WARNING);
try {
// Set up the report design, attached to the report engine
IReportRunnable reportDesign = engine.openReportDesign(rptDesignPath);
//Get designhandle
ReportDesignHandle reportDesignHandle = (ReportDesignHandle) reportDesign.getDesignHandle();
ElementFactory designFactory = reportDesignHandle.getElementFactory();
//delete exisiting data source this is to set the correct location as specified by user
for (int i = 0; i < reportDesignHandle.getDataSources().getCount(); i++){
if (reportDesignHandle.getDataSources().get(i).getName().equalsIgnoreCase("Data Source")){
reportDesignHandle.getDataSources().dropAndClear(i);
}
}
// ...and add in the required filename...
OdaDataSourceHandle dsHandle = designFactory.newOdaDataSource("Data Source", "org.eclipse.datatools.enablement.oda.xml");
dsHandle.setProperty("FILELIST", inputFilePath);
//add the new data source to the report
reportDesignHandle.getDataSources().add(dsHandle);
// OK, so now we've reset the data source to point at our XML file,
// we need to reset all the OdaDataSets (straight, not joined ones) to
// use the new data source. It did actually have exactly the same name,
// but when we deleted the source it upset them all and they forgot it.
List<DataSetHandle> dataSets = reportDesignHandle.getAllDataSets();
for (DataSetHandle dSetHandle : dataSets){
if (dSetHandle instanceof OdaDataSetHandle){
dSetHandle.setDataSource("Data Source");
}
}
// Create the task ready for running and rendering the report now
IRunAndRenderTask task = engine.createRunAndRenderTask(reportDesign);
task.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY , RunBirt.class.getClassLoader());
RenderOption options = new RenderOption();
options.setOption(IPDFRenderOption.PDF_HYPHENATION, true);
//run the task
options.setOutputFileName(outputFilePath);
//set the output format
//but postscript does not follow
//the same as the others so have to change this.
if (mimeConstantSelected.equalsIgnoreCase("ps")){
options.setOutputFormat("postscript");
} else {
options.setOutputFormat(mimeConstantSelected);
}
//set the render options
task.setRenderOption(options);
//run the task
task.run();
//if errors in task
if (task.getErrors().size() > 0) {
MessageDialog.openError(null, "BIRT", task.getErrors().toString());
}
//tidy
task.close();
engine.destroy();
} catch(Exception e){
//tidy up
engine.destroy();
//throw error
throw new Exception(e.getMessage());
}
|
|
|
Re: Birt Memory Usage [message #890068 is a reply to message #889942] |
Wed, 20 June 2012 17:47   |
Eclipse User |
|
|
|
Stacey
Are you stopping and starting the report engine for every report
iteration? If so that should not be done. Create one report engine for
the life of your application and use it to create task for each report
generation/render operation. Wrap the creation of the engine in a
singleton. Take a look at the BirtEngine class example here:
http://wiki.eclipse.org/Servlet_Example_%28BIRT%29_2.1
The example is older but revised copies are listed below and not much
changed with 3.7 API with the exception of setting birt home.
Jason
On 6/20/2012 6:36 AM, Stacey Hopkins wrote:
> To make sure I have not made any rookie mistakes please see main body of
> code below.... any feedback appreciated!
>
> // Set up engine config ready for engine
> EngineConfig engineConfig = new EngineConfig();
> engineConfig.setLogConfig("./birtlogs", Level.SEVERE);
>
> // Create a new report engine factory
> IReportEngineFactory factory =
> (IReportEngineFactory)Platform.createFactoryObject
>
> (IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
>
> // Create a new report engine
> IReportEngine engine = factory.createReportEngine(engineConfig);
> engine.changeLogLevel(Level.WARNING);
>
> try {
> // Set up the report design, attached to the report engine
> IReportRunnable reportDesign =
> engine.openReportDesign(rptDesignPath);
> //Get designhandle
> ReportDesignHandle reportDesignHandle =
> (ReportDesignHandle) reportDesign.getDesignHandle();
> ElementFactory designFactory =
> reportDesignHandle.getElementFactory();
>
> //delete exisiting data source this is to set the correct
> location as specified by user
> for (int i = 0; i <
> reportDesignHandle.getDataSources().getCount(); i++){
> if
> (reportDesignHandle.getDataSources().get(i).getName().equalsIgnoreCase("Data
> Source")){
> reportDesignHandle.getDataSources().dropAndClear(i);
> }
> }
>
> // ...and add in the required filename...
> OdaDataSourceHandle dsHandle =
> designFactory.newOdaDataSource("Data Source",
> "org.eclipse.datatools.enablement.oda.xml");
> dsHandle.setProperty("FILELIST", inputFilePath);
>
> //add the new data source to the report
> reportDesignHandle.getDataSources().add(dsHandle);
>
> // OK, so now we've reset the data source to point at our
> XML file,
> // we need to reset all the OdaDataSets (straight, not
> joined ones) to
> // use the new data source. It did actually have exactly
> the same name,
> // but when we deleted the source it upset them all and
> they forgot it.
> List<DataSetHandle> dataSets =
> reportDesignHandle.getAllDataSets();
> for (DataSetHandle dSetHandle : dataSets){
> if (dSetHandle instanceof OdaDataSetHandle){
> dSetHandle.setDataSource("Data Source");
> }
> }
>
> // Create the task ready for running and rendering the
> report now
> IRunAndRenderTask task =
> engine.createRunAndRenderTask(reportDesign);
>
> task.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY ,
> RunBirt.class.getClassLoader());
>
> RenderOption options = new RenderOption();
> options.setOption(IPDFRenderOption.PDF_HYPHENATION, true);
>
> //run the task
> options.setOutputFileName(outputFilePath);
>
> //set the output format
> //but postscript does not follow
> //the same as the others so have to change this.
> if (mimeConstantSelected.equalsIgnoreCase("ps")){
> options.setOutputFormat("postscript");
> } else {
> options.setOutputFormat(mimeConstantSelected);
> }
>
> //set the render options
> task.setRenderOption(options);
>
> //run the task
> task.run();
>
> //if errors in task
> if (task.getErrors().size() > 0) {
> MessageDialog.openError(null, "BIRT",
> task.getErrors().toString());
> }
>
>
> //tidy
> task.close();
> engine.destroy();
>
> } catch(Exception e){
> //tidy up
> engine.destroy();
> //throw error
> throw new Exception(e.getMessage());
> }
>
>
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.29911 seconds