Results 1 to 4 of 4

Thread: Performance issues using LocalValidatorFactoryBean

  1. #1

    Default 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. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    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.
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  3. #3

    Default

    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.

  4. #4

    Default

    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!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •