Jump to content
Software FX Community

ChartFX open file limit on the server


Charlie

Recommended Posts

 We are using ChartFX 7 for Java to make charts that are refreshing every second.

An example provided by SoftwareFX for refreshing the chart made out of a query to a db is shown in the code that follows.

We came accross the following problem, inside the chartfx70/temp directory there are the PNG and the CHS files
that are created for each chart, while updating the chart the chartfx server creates new PNG & CHS files and never releases the resources.

With 2 charts per page and 1 second refresh rates and 15 users we have a total of 108000 files/hour.

After a few hours we end up with a huge amount of open files that in windows slows down the application and in linux we have problems with the open files limit of the kernel (see lsof, ulimit).

One answer was to write a script that deletes the files, but even after deleting the files the file handles in the kernel are still all taken and no new files
can be opened.

How should we instruct the chart server to release the resources after the update is executed ?

 Code for charts that update provided by SoftwareFX Suport:

<%@page import="com.softwarefx.chartfx.server.*"%>
<%@page import="com.softwarefx.chartfx.server.dataproviders.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>Passing Data: JDBC</title>
  </head>   
  <script LANGUAGE = "JavaScript">
  var ascendent = true;
  var timerID = null
  var delay = 5000
 
  function InitializeTimer()
  {
  StartTheTimer()
  }
 
  function StartTheTimer()
  {
  var param = "";
  if (ascendent)
  param = "asc";
  else
  param = "desc";
 
  SFX_processing = false;
  SFX_SendUserCallback('chart1', param, false);
 
  ascendent = !ascendent;
  timerID = self.setTimeout("StartTheTimer()", delay)
  }
  function SFX_UpdateControls(id,callbackReturn) {  
  if (callbackReturn != "")
  alert(callbackReturn);              
  }  
 
  </SCRIPT>
 
 
  <body>
  <input type="submit" name="Button1" value="Start" id="Button1" style="font-family: Arial;
font-size: 9pt; width: 56px;" onclick="InitializeTimer()"/>
 
  <%!
  public class UserCallBackEventHandler implements com.softwarefx.chartfx.server.UserCallbackListener {

  public void userCallbackEventHandler(UserCallbackEvent e) {
  ChartServer chart1 = (ChartServer) e.getSource();

  chart1.getDataSourceSettings().getFields().clear();

  java.sql.ResultSet rs = null;
  java.sql.Connection conn = null;
  String query = "SELECT * FROM SampleFinancial ORDER BY Field1 " + e.getParam();
  try {
  Class.forName("org.hsqldb.jdbcDriver");
  String database = "jdbc:hsqldb:file:" +  getServletContext().getRealPath("/") + "/data/sampledb/sampledb";
  conn = java.sql.DriverManager.getConnection(database, "SA", "");
  java.sql.Statement stmt = conn.createStatement();
  rs = stmt.executeQuery(query);
  } catch (Exception ex) {
  }
  JDBCDataProvider provider = new JDBCDataProvider(rs);
  chart1.getDataSourceSettings().getFields().add(new FieldMap("Field1", FieldUsage.LABEL));
  chart1.getDataSourceSettings().getFields().add(new FieldMap("Field2", FieldUsage.VALUE));
  chart1.getDataSourceSettings().getFields().add(new FieldMap("Field3", FieldUsage.VALUE));
  chart1.getDataSourceSettings().setDataSource(provider);
  try {
  conn.close();
  } catch (Exception ex) {
  }
   
  chart1.recalculateScale();
  }
  }

  %>
  <%
  ChartServer chart1 = new ChartServer(pageContext, request, response);
  chart1.setID("chart1");
  chart1.setUseCallbacksForEvents(true);
  chart1.addUserCallbackListener(new UserCallBackEventHandler());

  chart1.setWidth(600);
  chart1.setHeight(400);

  java.sql.ResultSet rs = null;
  java.sql.Connection conn = null;
  String query = "";

  try {
  Class.forName("org.hsqldb.jdbcDriver");
  String database = "jdbc:hsqldb:file:" + application.getRealPath("/") + "/data/sampledb/sampledb";
  conn = java.sql.DriverManager.getConnection(database, "SA", "");
  java.sql.Statement stmt = conn.createStatement();
  query = "SELECT * FROM SampleFinancial";
  rs = stmt.executeQuery(query);
  } catch (Exception e) {
  out.println(e.getMessage());
  }

  JDBCDataProvider provider = new JDBCDataProvider(rs);
  chart1.getDataSourceSettings().getFields().add(new FieldMap("Field1", FieldUsage.LABEL));
  chart1.getDataSourceSettings().getFields().add(new FieldMap("Field2", FieldUsage.VALUE));
  chart1.getDataSourceSettings().getFields().add(new FieldMap("Field3", FieldUsage.VALUE));
  chart1.getDataSourceSettings().setDataSource(provider);

  conn.close();

  chart1.getAxisX().getLabelsFormat().setFormat(AxisFormat.DATE);

  SeriesAttributes series0 = chart1.getSeries().get(0);
  series0.setGallery(Gallery.LINES);
  series0.getLine().setWidth((short) 2);
  series0.setMarkerShape(MarkerShape.NONE);
  series0.setAxisY(chart1.getAxisY());

  SeriesAttributes series1 = chart1.getSeries().get(1);
  series1.setGallery(Gallery.AREA);
  series1.getBorder().setVisible(true);
  series1.setAxisY(chart1.getAxisY2());

  chart1.getAxisY().getGrids().getMajor().setVisible(true);
  Axis axis = chart1.getAxisY2();
  axis.setMax(200000000);
  axis.setMin(0);
  axis.setVisible(false);
  chart1.getPlotAreaMargin().setRight(30);

  chart1.recalculateScale();

  chart1.getSeries().get(0).setText("Price");
  chart1.getSeries().get(1).setText("Volume");

  chart1.renderControl();
  %>    
  </body>
</html>
 

 

Link to comment
Share on other sites

  • 9 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...