0

I have an application that run fast on my computer but slow on a VPS for this JPA call

List<Catalogue> cats = catRepository.findAll() 

This lasts 9 seconds (2.5s on my computer), I would like to know what takes so long : sql query or jpa? Is there a way to distinguish these two execution durations?

Thanks in advance.

user1260928
  • 3,269
  • 9
  • 59
  • 105
  • How many rows in the table? If it's a lot you're just seeing a network throughput bottleneck between the server running the Java and the database. – Jim Garrison Feb 11 '15 at 10:06
  • 7000 records, with foreign keys. The problem comes from the VPS, I have logged the JPA call duration and it is 9s. My problem is that I don't know if these 9 seconds are taken mostly by JPA process (it could be then a matter of cpu anr/or ram) or by the generated query itself. – user1260928 Feb 11 '15 at 10:10
  • Again, if your Java is not running on the same machine as the database, the JPA call would take much longer to fetch the rows as they have to be transmitted over the wire. – Jim Garrison Feb 11 '15 at 10:12

2 Answers2

1

For MySql: enable slow query log and check if there are some problems there (set the limit to e.g 3 seconds). If the problem is MySql, you will see there the queries with problems.

I doubt the problem is JPA, but what it could be: there are too much data taken, like all relationships. In order to do that, enable the logging of the executed queries and see what is fetched from DB. Every JPA implementation (like Hibernate or EclipseLink) have different ways of doing that, so check the respective documentation, eg. check this answer.

Community
  • 1
  • 1
V G
  • 18,822
  • 6
  • 51
  • 89
1

There are tools for profiling JPA performance, but as far as I know they are all vendor specific.

If you use Hibernate, take a look at this thread: how to measure hibernate performance?

For EclipseLink, check this out: http://www.eclipse.org/eclipselink/documentation/2.5/solutions/performance002.htm

These tools should give you the insight on how much time is spent on preparing the query, executing it, processing the results, etc.

Community
  • 1
  • 1
Predrag Maric
  • 23,938
  • 5
  • 52
  • 68