-7

Give me some idea/suggest/solution to retrieve data faster and page rendering speed.Technology using Spring MVC - Hibernate - JSP - AngularJS v1.6 - SQL Server Database.Data is retrieved from SQL Server, Mapped to Hibernate Object, While rendering in the User interface getting delayed. Into the project : I am retrieving the Product List(with Product Name, Category,Subcategory, rating, product Image as base64 format and some more details with calculation).

The objective of this post is Rendering data in User Interface is very slow.Is there any way to fine tune the performance of the Web Application.

Sample Code of DAO Layer- Product retrive-Hibernate :

Session session = sessionFactory.openSession(); // Open Session Factory connection
    Transaction tx = null; // Transaction
        try {
            tx = session.beginTransaction(); // Transaction Begin
            productMaster = sessionFactory.getCurrentSession()
                    .createSQLQuery(
                            "select field1,field2 from Table")
                    .addScalar("field1", StandardBasicTypes.STRING)
                    .addScalar("field2", StandardBasicTypes.BIG_INTEGER).list();
            for (Object[] o : productMaster) {
                map.put(o[0].toString(), Long.parseLong(o[1].toString()));
            }
            session.getTransaction().commit(); // Transaction Commit once its successful
            session.flush(); // Execute all pending statement in DB
            session.clear();// Clearing the session object
        } catch (HibernateException e) {
            if (tx != null) {
                tx.rollback();// Unsuccessfull transaction - rollback
            }
            e.printStackTrace();
        } finally {
            session.close(); // Closing the connection
        }
Renu
  • 11
  • 4

1 Answers1

1

Without more detail, I can only offer general advice, but here goes:

Start by profiling the application to see where the bottlenecks actually are. See this question for a list of profiling tools.

The golden rule is to measure first, then optimise only what needs optimising!

Once you know where improvements need to be made, general approaches you might try are:

  • Improving the efficiency of algorithms/calculations in Java.
  • Caching results.
  • Improving efficiency of database queries. Consider:
    • How many queries are required to handle client responses?
    • Whether the queries can be refactored to be more efficient.
    • Whether adding database level indexes etc might improve query performance.

From the technologies you're using, it sounds as though you're developing some kind of an interactive web app. Consider whether it's practical to load and display the data progressively (e.g. while the user is viewing the first data item, load the second data item in the background).

It might be counter intuitive, but consider whether your application can be implemented as plain old HTML pages without masses of client-side Javascript frameworks. In many cases, you'll find this results in much reduced page load times...

  • Thank you so much. I get idea with your answer. Yes, you are right. It is an interactive Web app. Rendering data in UI is very slow. – Renu Nov 22 '17 at 12:21
  • So the key question is - "which part of the application is slowing things down?" You could try using something like `curl` or a Python script (check out [Requests](http://docs.python-requests.org/en/latest/)) to test your server-side code to try and isolate the problem... – Jarvis Cochrane Nov 22 '17 at 13:34
  • I observed that rendering in the UI is getting delayed. – Renu Nov 23 '17 at 06:24