Annotation based configuration – performance

Splash Forums PrettyFaces Users Annotation based configuration – performance

This topic contains 4 replies, has 2 voices, and was last updated by  Christian Kaltepoth 5 years, 6 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #18252

    Petter Helset
    Participant

    Hello, I’m experiencing some performance-issues when using “com.ocpsoft.pretty.SCAN_LIB_DIRECTORY” and “com.ocpsoft.pretty.BASE_PACKAGES”.

    The project I’m working on consists of multiple modules/projects (eg. in separated jars).

    The main module works as a container for the rest of the modules; it scans the jars (classpath) in WEB-INF/lib for spring-beans, faces-pages etc.

    This module is the actual war-file in the project – the other modules is just included jars.

    Simplified example:

    – project-hub (war)

    – user-services-web-api (jar)

    – news-services-web-api (jar)

    The hub contains web.xml, spring-config, faces-config, pretty-config (empty), etc.

    The web-api modules contains spring controllers, modules (components), faces-pages (xhtml), and so on.

    The hub scans for controllers, modules, etc.

    The user-controller may look like this:

    @Controller

    @URLMappings(mappings = {

    @URLMapping(id = LIST, pattern = "/secure/users/", viewId = "/faces/secure/user/list.xhtml"),

    @URLMapping(id = VIEW, pattern = "/secure/user/#{" + ID + "}/", viewId = "/faces/secure/user/view.xhtml")

    })

    public class UserController {

    public static final String LIST = "user_list";

    public static final String VIEW = "user_view";

    public static final String ID = "id";

    /* autowiring etc. */

    @URLAction(mappingId = VIEW, onPostback = false)

    public void view() {

    final HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();

    final Long userId = request.getParameter(ID);

    final User user = service.findUser(userId);

    userModel.setUser(user);

    }

    /* ... */

    }

    The user-model may look like this:

    @Component

    @Scope(value = "view", proxyMode = ScopedProxyMode.TARGET_CLASS)

    public class UserModel implements Serializable {

    /* ... */

    private User user;

    /* plain getters and setters */

    }

    The web.xml contains:

    <context-param>

    <param-name>com.ocpsoft.pretty.BASE_PACKAGES</param-name>

    <param-value>my.packages.web</param-value>

    </context-param>

    <context-param>

    <param-name>com.ocpsoft.pretty.SCAN_LIB_DIRECTORY</param-name>

    <param-value>true</param-value>

    </context-param>

    The problem:

    It seems that EVERY time there is a request to the servlet, the annotation-scanner scans my packages and libs. This is a time-consuming process (the larger the lib folder is, the more time-consuming).

    Why isn’t the annotated mappings scanned ONCE, and then cached?

    (btw. this approach with @Controller and @Component w/@Scope is not the “JSF-way”, altho our preferred way – the classes annotated with @Controller is global-scoped for all requests)

    PrettyFaces 3.3.3

    JSF 2.1.6

    SpringFramework 3.1.0.RELEASE (core, webmvc and security)

    Apache Tomcat 7.0.26

    #22300

    Hey phelset,

    PrettyFaces reloads it’s configuration on a regular basis to allow developers to update the configuration without restarting the server. But this is only done in project stage “development”. So this shouldn’t have any effect on production performance.

    But if I remember correctly you can disable this behavior by setting the following servlet context parameter in your web.xml:

    <context-param>
    <param-name>com.ocpsoft.pretty.DEVELOPMENT</param-name>
    <param-value>false</param-value>
    </context-param>

    Does this solve your performance problem?

    Christian

    #22301

    Petter Helset
    Participant

    Solved this by implementing a custom ConfigurationProvider and disabling both “com.ocpsoft.pretty.SCAN_LIB_DIRECTORY” and “com.ocpsoft.pretty.BASE_PACKAGES”.

    @Override

    public PrettyConfig loadConfiguration(ServletContext servletContext)

    {

    final ListableBeanFactory listableBeanFactory = WebApplicationContextUtils.getWebApplicationContext(servletContext);

    final Map<String, Object> controllers = listableBeanFactory.getBeansWithAnnotation(Controller.class);

    final LazyBeanNameFinder beanNameFinder = new LazyBeanNameFinder(servletContext);

    final PrettyAnnotationHandler annotationHandler = new PrettyAnnotationHandler(beanNameFinder);

    for (Object o : controllers.values())

    {

    annotationHandler.processClass(o.getClass());

    }

    final PrettyConfigBuilder builder = new PrettyConfigBuilder();

    annotationHandler.build(builder);

    return builder.build();

    }

    This ConfigurationProvider finds all beans annotated with @Controller and processes PrettyFaces annotations with PrettyAnnotationHandler.

    #22302

    Petter Helset
    Participant

    Christian Kaltepoth, thanks – disabling development mode seems to speed it up :-)

    (also not calling ConfigurationProvider on every request)

    #22303

    Nice to hear that it’s working for you now! :)

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

Comments are closed.