How to reduce JSF application CPU consumption

From a while ago, my application started to have a very large CPU consumption. I installed JProfiler, and from what I understood from it, there is a problem with Hibernate's C3P0. I'm using hibernate 4.3, JSF2.2. 10 + primefaces 5.2, I use ehcache as well.

Below are some results that I printed.

picture consumption mchange

Threads .date

thread tree

hibernate config

Author: Marlucio Pires, 2018-08-28

1 answers

Looking at the graphs presented, I believe you misinterpreted the problem.

I did not see CPU consumption as the problem, not least because this information is not shown. The amount of % you are seeing is not CPU, but it is time spent running that method. The cause can be various things (including CPU).

In your specific case, C3P0 seems to be taking a while to get a connection to the database. The connection pool serves to streamline this is because C3P0 keeps some connections always open and when the application asks for a connection, it already has one ready to use.

However, if this step is taking time, it is possible that the current pool is too small (in its current configuration, it is like 5) and it may need to open new connections to the database. Opening a new connection to the database is something heavier, which would explain your problem.

Another explanation is you have reached the maximum number of connections , which you currently set to 20. When this occurs, the system needs to wait to use an open connection, which would also explain the delay.

The above two cases can be monitored on the server or directly in the database, keeping track of the amount of open connections.

To improve, you can increase the minimum or maximum pool of connections, depending on your problem. Try a number greater than 5 for the minimum, for example. The exact number I can not say which can be as it depends a lot on your application and server.

If you notice that this problem is more serious at specific times (such as at dawn) also check that there is no heavy routine being run in the database during the time. Perhaps this can affect the opening time of a new connection.

 1
Author: Dherik, 2018-09-11 20:46:46