2

I have serious problem with (I guess hibernate validator). I''m using spring boot 2.0 and the problem exists even i spring boot 1.4.x and the correspondent version comes from:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>

I have simple domain validation -

ExhibitorListt.class
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id")
private Integer id;


@Column(name="exhibitor_name")
@NotBlank(message="The name of exhibitor cannot be empty!")
private String exhibitorName;


@Column(name="exhibitor_price")
@NotNull(message="Price must be a number")
private Double exhibitorPrice;


@Column(name="catalogue_number")
@NotNull(message="Catalogue number can not be empty!")
private Integer catalogueNumber;

@Column(name="oracle_number")
@NotBlank(message="Oracle number can not be empty")
private String oracleNumber;

And simple Spring MVC controller

@Secured({ "ROLE_ADMIN" })
@RequestMapping(value = "/new", method = RequestMethod.POST)
public String newExhibitor(Model model, @Valid ExhibitorList newExhibitor, BindingResult result, RedirectAttributes attr) {

    if (result.hasErrors()) {
        attr.addFlashAttribute("org.springframework.validation.BindingResult.newExhibitor", result);
        attr.addFlashAttribute("newExhibitor", newExhibitor);
        return "redirect:/exhibitor/new";
    }

    exhibitorListRepository.save(newExhibitor);
    return "redirect:/exhibitor/new";
}

When I try to create new entity, the request takes 10 - 15 sec. I attache profiler to diagnostic the problem. It seems that it comes from hibernate-validation. I cannot reproduce the bug because it is not occurs every time, but from time to time... I tried many things but nothing helps ....

enter image description here

JSON from the profiler with call tree. http://80.241.211.242/sampleCallTree%20(1).json

Any suggestions are OK.

ROZZ
  • 1,334
  • 3
  • 20
  • 36
  • Can you check which exact version of Hibernate Validator you have ? I assume it'll be some 5.4. In later versions of 6.0 there are some improvements around message interpolation and looking at your particular case where you have messages and no need to do any interpolation it wouldn't even try to load resource bundle. So I'd recommend to upgrade to latest 6.0.Also note that the time is actually consumed by getting the resource bundle and not the HV itself. So maybe worth looking into that ? – mark_o Mar 07 '18 at 10:13
  • I'm using hibernate-validator 6.0.7.Final – ROZZ Mar 07 '18 at 11:55

1 Answers1

0

As you can see in your profiling all the time is spent in the class loader loading a resource.

So your issue is not about Hibernate Validator specifically but it appears to be when Hibernate Validator tries to load the resource bundle (to find the localized messages) using the class loader.

It's indeed very strange as it should be fast and I don't see any reason why the class loader could take such an amount of time, apart from I/O issues.

Could you maybe try to build a minimal Spring Boot reproducer?

By the way, @mark_o is right: upgrading to the latest Hibernate Validator 6.0.7.Final will help you as, in the particular case when you define the message manually, we don't load the resource bundle anymore.

That being said, I would advise you to get to the root of this issue as you expose yourself to a lot of problems if loading a single resource from your class loader takes ~15 seconds.

Guillaume Smet
  • 9,921
  • 22
  • 29
  • I'm using org.hibernate.validator hibernate-validator 6.0.7.Final – ROZZ Mar 07 '18 at 11:54
  • I don't know why it is happening from time to time and not always. When it is working normally, it takes 30ms for example to return the response. – ROZZ Mar 07 '18 at 12:21
  • Yeah, to be honest, I don't think it's an issue with your Java code but more with the performance of the machine it runs on. It looks like you have some I/O issues. That being said, the call stack you have in your capture is not from Hibernate Validator 6.0.7.Final, the line numbers are off. Do you hardcode all your messages in the annotations? Because if so, with HV 6.0.7.Final, it shouldn't load the bundle at all. And even if you haven't defined a message, it should be loaded only once and then cached. Any chance you could assemble a simple reproducer I can check? – Guillaume Smet Mar 07 '18 at 19:03
  • ,, I added you in linkedin. I'll be very happy if you have some minutes for me :) – ROZZ Mar 08 '18 at 06:48
  • 1
    Hi, I am having the same situation, the hibernate validator I am using is 6.0.23 and spring boot 1.5.10 but the wierd thing is that locally it does not happen, when I deploy it in openshift, it happens. The loading of the resources cannot be because it happens when the request has not validation errors, so it is not needed to load any resources(I debug it locally and does not load any bundles if the request is valid). – fernando1979 Jul 13 '22 at 07:06
  • I found the answer here: https://stackoverflow.com/questions/59242577/why-my-springboot-with-embbeded-tomcat-too-slow-when-process-first-request – fernando1979 Jul 21 '22 at 11:33