0

Sorry for my english.

Using Spring 4 for the first time, I began to doubt whether it really helps or is just disturbing. When the session expires, this reconnect between 36 and 60 seconds.

Using: Spring-boot with Hibernate4 + JPA2 + HikariCP (pool) + Hibernate.spatial

I put an asterisk in this line with the bottleneck.

2014-07-08 17:59:14 DEBUG o.s.s.w.u.m.AntPathRequestMatcher:145 - Checking match of request : '/rest/restaurant/c1f15300-8bfc-496b-b90c-cf57596c8319/detail'; against '/rest/restaurant'
2014-07-08 17:59:14 DEBUG o.s.s.w.u.m.AntPathRequestMatcher:145 - Checking match of request : '/rest/restaurant/c1f15300-8bfc-496b-b90c-cf57596c8319/detail'; against '/rest/restaurant/**'
2014-07-08 17:59:14 DEBUG o.s.s.w.FilterChainProxy:180 - /rest/restaurant/C1F15300-8BFC-496B-B90C-CF57596C8319/detail has an empty filter list
2014-07-08 17:59:14 DEBUG o.s.w.s.DispatcherServlet:838 - DispatcherServlet with name 'dispatcherServlet' processing GET request for [/almocaqui/rest/restaurant/C1F15300-8BFC-496B-B90C-CF57596C8319/detail]
2014-07-08 17:59:14 DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping:246 - Looking up handler method for path /rest/restaurant/C1F15300-8BFC-496B-B90C-CF57596C8319/detail
2014-07-08 17:59:14 DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping:251 - Returning handler method [public com.snowmanlabs.almocaqui.domain.external.ExternalBasicRestaurant com.snowmanlabs.almocaqui.rest.controller.RestaurantRestController.getDetail(java.lang.String)]
2014-07-08 17:59:14 DEBUG o.s.b.f.s.DefaultListableBeanFactory:249 - Returning cached instance of singleton bean 'restaurantRestController'
2014-07-08 17:59:14 DEBUG o.s.w.s.DispatcherServlet:925 - Last-Modified value for [/almocaqui/rest/restaurant/C1F15300-8BFC-496B-B90C-CF57596C8319/detail] is: -1
2014-07-08 17:59:14 DEBUG o.s.o.j.s.OpenEntityManagerInViewInterceptor:87 - Opening JPA EntityManager in OpenEntityManagerInViewInterceptor
2014-07-08 17:59:14 DEBUG o.s.b.f.s.DefaultListableBeanFactory:249 - Returning cached instance of singleton bean 'transactionManager'
2014-07-08 17:59:14 DEBUG o.s.o.j.JpaTransactionManager:334 - Found thread-bound EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@1007b020] for JPA transaction
***2014-07-08 17:59:14 DEBUG o.s.o.j.JpaTransactionManager:367 - Creating new transaction with name [com.snowmanlabs.almocaqui.service.implement.RestaurantServiceImpl.getRestaurant]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly; ''
2014-07-08 17:59:48 DEBUG o.s.o.j.JpaTransactionManager:403 - Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@356f95be]
2014-07-08 17:59:49 DEBUG o.s.o.j.JpaTransactionManager:755 - Initiating transaction commit
2014-07-08 17:59:49 DEBUG o.s.o.j.JpaTransactionManager:510 - Committing JPA transaction on EntityManager [org.hibernate.jpa.internal.EntityManagerImpl@1007b020]
2014-07-08 17:59:49 DEBUG o.s.o.j.JpaTransactionManager:603 - Not closing pre-bound JPA EntityManager after transaction
2014-07-08 17:59:50 DEBUG o.s.w.s.m.m.a.RequestResponseBodyMethodProcessor:145 - Written [com.snowmanlabs.almocaqui.domain.external.ExternalBasicRestaurant@479caa5b] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@4a37a117]
2014-07-08 17:59:50 DEBUG o.s.w.s.DispatcherServlet:1012 - Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2014-07-08 17:59:50 DEBUG o.s.o.j.s.OpenEntityManagerInViewInterceptor:112 - Closing JPA EntityManager in OpenEntityManagerInViewInterceptor
2014-07-08 17:59:50 DEBUG o.s.o.j.EntityManagerFactoryUtils:435 - Closing JPA EntityManager
2014-07-08 17:59:50 DEBUG o.s.w.s.DispatcherServlet:991 - Successfully completed request

PS: This problem in AWS, makes the site get off the air (exceeds the maximum time Internal hold)


Summary of my files:

*RestaurantRestController.java

@Controller
@RequestMapping(value = "/rest/restaurant")
public class RestaurantRestController {

    private final RestaurantService service;

    @Inject
    public RestaurantRestController(final RestaurantService service) {
        this.service = service;
    }
    
    
    @RequestMapping(value = "/{uuid}/detail", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public ExternalBasicRestaurant getDetail(@PathVariable("uuid") String uuid) {
        Restaurant restaurant = service.getRestaurant(uuid);

        ExternalBasicRestaurant external = createExternalBasicRestaurant(restaurant);
          
        return external;
    }
    @ExceptionHandler
    @ResponseStatus(HttpStatus.CONFLICT)
    public String handleUserAlreadyExistsException(UserAlreadyExistsException e) {
        return e.getMessage();
    }
}

*RestaurantServiceImpl.java

@Service
@Validated
public class RestaurantServiceImpl implements RestaurantService {

    private final RestaurantRepository repository;
    
    @Inject
    public RestaurantServiceImpl(final RestaurantRepository repository) {
        this.repository = repository;
    }
    
    @Override
    @Transactional(readOnly = true)
    public Restaurant getRestaurant(String uuid){
        Restaurant restaurant = repository.findOneByUUID(uuid);

        return restaurant;
    }
}

*RestaurantRepository.java

@Repository
public interface RestaurantRepository extends JpaRepository<Restaurant, Integer> {
}

*application.properties

# Spring
spring.profiles.active=dev

# Server
server.port=8080
server.sessionTimeout=30

# MVC
spring.view.prefix=/WEB-INF/jsp/
spring.view.suffix=.jsp

java.runtime.version=1.7

#DataSource
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.url=jdbc:sqlserver://x.database.windows.net:1433;database=almocaqui;encrypt=true;hostNameInCertificate=*.database.windows.net;loginTimeout=30;
spring.datasource.username=x
spring.datasource.password=x
spring.datasource.validationQuery=SELECT 1
spring.datasource.testOnBorrow=true
spring.datasource.poolPreparedStatements=true

# JPA
spring.jpa.database-platform=org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect
spring.jpa.generate-ddl=true
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=none
spring.jpa.hibernate.autocommit=false
spring.data.jpa.repositories.enabled=true

# HikariCP
hibernate.connection.provider_class=com.zaxxer.hikari.hibernate.HikariConnectionProvider
hibernate.hikari.minimumPoolSize=20
hibernate.hikari.maximumPoolSize=100
hibernate.hikari.idleTimeout=30

# Tomcat
tomcat.accessLogEnabled=false
tomcat.protocolHeader=x-forwarded-proto
tomcat.remoteIpHeader=x-forwarded-for
tomcat.backgroundProcessorDelay=10
server.tomcat.uri-encoding=UTF-8
server.session-timeout=10

*Local final: localhost:8080/rest/restaurant/C1F15300-8BFC-496B-B90C-CF57596C8319/detail

Community
  • 1
  • 1
luisdemarchi
  • 1,402
  • 19
  • 29

2 Answers2

0

At a minimum, it seems you are using an old version of HikariCP. Several of the properties referenced are no longer supported. I recommend upgrading HikariCP to 1.4.0. Change your HikariCP settings to these recommended settings:

hibernate.connection.provider_class=com.zaxxer.hikari.hibernate.HikariConnectionProvider
hibernate.hikari.minimumIdle=10
hibernate.hikari.maximumPoolSize=30
hibernate.hikari.idleTimeout=300000
hibernate.hikari.maxLifetime=600000
brettw
  • 10,664
  • 2
  • 42
  • 59
  • It really was an old version, changed to 1.4.0. However the problem persists. The stop continues in "Creating new transaction with name...", time long enough to fall the server. Check out ws [test in AWS](http://almocaquiweb-test.elasticbeanstalk.com/rest/restaurant/C1F15300-8BFC-496B-B90C-CF57596C8319/detail). – luisdemarchi Jul 09 '14 at 18:53
  • What's supposed to happen when I hit that test URL. It loads immediately for me (and reloads). This issue http://stackoverflow.com/questions/24445721/thread-lock-after-opening-new-entitymanager looks the same to me. – brettw Jul 10 '14 at 05:35
0

Apparently the problem was in codes that have not shared here. I found the answer in this article: http://zeroturnaround.com/rebellabs/how-to-use-jpa-correctly-to-avoid-complaints-of-a-slow-application/

Many lazy that the last object that was sent as a JSON response. Simply removed ALL lazy and it looks like it worked.

I'll restructure my code. Anything return here.


Edit

The problem was the other. Had the server app in AWS and database in Azure, the reconnection with the database that was slow, however the JPA does not show it.

Stayed in all AWS and got "show the ball" (as the Brazilians say, of course that once took 7x1 is not that much .. lol).

Community
  • 1
  • 1
luisdemarchi
  • 1,402
  • 19
  • 29