0

I am working on GraphStream showing data from database. But it creates node and edges very slow. I am using this very basic example.

Here is my code:

public class GraphExplore {
    static Connection conn2;
    static String result, result2;
    static JFrame frame;
    static JPanel panel;
    static int totalRows, i;

    public static void main(String args[]) throws SQLException {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    showData();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    private static void showData() throws SQLException {

        frame = new JFrame("GRAPH TESTING");

        Graph graph = new SingleGraph("tutorial 1");
        graph.setAutoCreate(true);
        graph.setStrict(false);
        graph.display();

        try {
            Class.forName("org.h2.Driver");
            conn2 = DriverManager.getConnection("jdbc:h2:file:G:/hs_data/h2_db/test", "sa", "sa");

        } catch (Exception e) {
            e.printStackTrace();
        }
        Statement stmt2 = conn2.createStatement();
        ResultSet rs = stmt2.executeQuery("SELECT count(*) FROM cdr");
        while (rs.next()) {
            totalRows = rs.getInt(1);
        }
        ResultSet rs2 = stmt2.executeQuery("SELECT ANUMBER,BNUMBER FROM CDR LIMIT 20");
        while (rs2.next()) {
            result = rs2.getString("ANUMBER");
            result2 = rs2.getString("BNUMBER");
            graph.addNode(result);
            graph.addNode(result2);
            for (i = 0; i < totalRows; i++)
                graph.addEdge("string" + i, result, result2);
        }

        for (Node node : graph) {
            node.addAttribute("ui.label", node.getId());
        }
        // graph.addAttribute("ui.stylesheet", "graph { fill-color: red; }");text-mode:
        // hidden;
        graph.addAttribute("ui.stylesheet", "node {size: 12px;fill-color: #ff0000;z-index: 0;}");
        graph.addAttribute("ui.stylesheet", "edge { shape:line ; fill-color: #222;}");
        conn2.close();
    }

}

For now, I am just using 20 rows and it takes 3-4 seconds. But I need to show more records(may be more than 1 million) at once. Can anyone tell me how can I increased the speed of rendering ?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Noob Player
  • 279
  • 6
  • 25

1 Answers1

0

Just a wild guess here. Have you tried timing specifically the time the JDBC is taking to return the results from the query? I'd start here. If you figure out the query comes back quickly, it isn't a problem of the database. If it is, you may consider using indices for returning results faster.

If the query is not the problem, you may look into the graph functionality. My guess would lead me to believe the rendering is slow because the graph is set to display and then nodes and edges are added to it, so it renders in real time. It could be possible to preload the nodes and edges before you start rendering the graph, reducing the number of draw calls.

jdhurricanes
  • 142
  • 9