Announcement Announcement Module
Collapse
No announcement yet.
Performance issues using LocalValidatorFactoryBean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Performance issues using LocalValidatorFactoryBean

    We have been using LocalValidatorFactoryBean to validate over 1 million objects. After performance profiling and looking at multiple stack dumps, it seems like Spring is creating a new instance of validator every time. This is killing our performance. I have used another implementation of JSR 303 and a new instance of each validator is not created per validation.

    Is there a way to disable this functionality of LocalValidatorFactoryBean? We don't need to persist any data and prefer to use validators as a singleton. It seems like the autowiring of each class is slow and not worth doing it every time.

    Any help would be appreciated.

  • #2
    Hello

    We have been using LocalValidatorFactoryBean to validate over 1 million objects
    OK, 1M of objects in real time

    it seems like Spring is creating a new instance of validator every time
    I think could be the same JSR 303 by itself to validate each instance, anyway ...

    I have used another implementation of JSR 303 and a new instance of each validator is not created per validation
    How you got such conclusion? Could you share the name of the other implementation?

    Is there a way to disable this functionality of LocalValidatorFactoryBean? We don't need to persist any data and prefer to use validators as a singleton. It seems like the autowiring of each class is slow and not worth doing it every time.
    Have you tried to work with the Spring's Validator interface? You should implement this interface and validate there your objects.

    Comment


    • #3
      Hello,

      The other implementation I have used was Apache's implementation. I came to this conclusion by doing two things. First, I ran a profiler with jVisualVM while validating these objects. Looking at the stack trace, I saw that auto-wiring and reflection methods were taking a really long time. I put sys outs in the constructor and indeed I saw that every single time I validate an object, a new validator is created.

      Using Apache's implementation seems to not have this same problem. I don't think it is part of JSR 303 to recreate instances. Using Spring's Validator interface is another option. I had forgotten about that. That is an option. We have already created 100+ annotations though to validate these objects.

      What would be good to know if recreating validators is part of the JSR303 specification? I am trying Apache again to validate.

      Comment


      • #4
        Hello Manuel,

        Here are my finding

        Code:
        Validation.buildDefaultValidatorFactory().getValidator()
        creates one and only one validator.

        Code:
        <bean id="jsr303Validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
                <property name="providerClass" value="org.apache.bval.jsr303.ApacheValidationProvider"/>
            </bean>
        Create one and only one validator.

        Code:
        <bean id="jsr303Validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
        Create n validators for n items!

        Comment

        Working...
        X