0

Good morning, I'm using Scout Java version framework, with Oracle Java 17 e Tomcat 9.0.70 on Debian 11, when populating tables, TablePage, with many rows, 10,000-50,000 or more, from Postgresql database, cpu usage by Java, exceeds 100% and execution is slow.

I've made many attempts to optimize both Java and Tomcat with little success.

With ScoutJS, do I solve the problem? Or at least get a performance boost?

Any suggestions are welcome.

Thanks for the attention.

  • Are you actually loading 10k - 50k rows from the database into some table to display? No wonder that would be slow, and probably hard to use. Look up pagination. If you are asking whether databases can have that may rows, then yes, they easily can, and you'd need to add database name and version as well as table structure details to the question. – Robert Feb 06 '23 at 16:56
  • Thanks for the comment, unfortunately Scout Java's Table Page, does not support pagination. – Giorgio Piangatelli Feb 07 '23 at 08:42

1 Answers1

0

The SqlService helper classes use reflection a lot. This is why they can be very inefficient in these cases. I gained a ~70% time improvement by changing from

        SQL.selectInto(sqlString, new NVPair("page", pageData));

to

        Object[][] result = SQL.select(sqlString);
        for (Object[] line : result) {
            PersonTableRowData row = new PersonTableRowData();
            if (line[0]!=null) row.setId((Long)line[0]);
            if (line[1]!=null) row.setName((String)line[1]);
            if (line[2]!=null) row.setPhone((String)line[2]);
            // ....

            pageData.addRow(row);
        }

Of course you loose flexibility here, like when changing the model you also have to your code here.

kadom
  • 16
  • 1