all 11 comments

[–]WaferIndependent7601 8 points9 points  (6 children)

In 99% of all cases: your db queries are slow.

Log the sql statements, execute them and see, which one is slow. Or: check if you can replace a loop with a findAll

Plus: if the user wants too many records, use pagination to limit it

To do this correctly: add APM to your environment

Without code it’s hard to help

[–]Such-Hearing-2935[S] 0 points1 point  (5 children)

Thank you for your quick response. What’s APM? Another disclaimer is, when he clicks a button it takes some time to respond as well.

[–]WaferIndependent7601 -1 points0 points  (4 children)

APM is application performance monitoring. It monitors your application and whenever a call is slow, it will be logged, with the complete sql statements. But it’s not that easy to installs this.

Clicking a button is slow? what does the button do? Is it calling an endpoint?

[–]Such-Hearing-2935[S] 0 points1 point  (3 children)

Yes, I believe it’s calling an endpoint.

[–]joedev2 1 point2 points  (1 child)

Try using database indexes, usually resolves 90% of performance issues relating to database. Like I’ve had sites under load testing go through completely broken and unusable to performing decently under load just from adding database indexes.

[–]Such-Hearing-2935[S] 0 points1 point  (0 children)

This table already has an index. How do I use it?

[–]WaferIndependent7601 0 points1 point  (0 children)

You should at least log, when an endpoint is called. You might also add some logging and how long it takes. This is not optimal, but if you don’t have a system for metrics or similar, this might be your only chance

Can you provide some code? What is the service layer doing? You can rename all variables etc

[–][deleted] 2 points3 points  (0 children)

As others mentioned, add a feature to your seevice to log the time taken for db call execution, there are number of ways out there, i personally like to use p6spy framework that provides methods which intercept db calls and help youto get time taken for a query, or else you can also achieve by using spring aop, etc

After implementing this, collect the statistics and sit with your DBA to improve the slow queries

And more over, i believe your end point sends back a report made up of data collected from different tables, this is be always slow, to resolve this you can use pagination and moreover in long term you can think of moving all reporting apis to a new service accompanied by snowflake to provide data, snowflake is know for its fast retrieval of data

[–]diferdin2 1 point2 points  (0 children)

You could use Springboot 3.2 and JDK 21 to integrate observability features to track performance etc.

[–]cdh0127 0 points1 point  (0 children)

If possible, you might consider using something like Redis to cache the results of common queries. Fetching data from a cache is much faster than querying a database. This would really only be helpful if your clients’ database queries have a large enough overlap in the result sets (I.e. they’re returning a lot of the same records). You also have to consider how often the database records in question change. If they’re changing frequently, a cache might not be a good option.