You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Pamir Erdem <pa...@gmail.com> on 2009/11/10 19:17:38 UTC

org.apachewicket.protocol.http.WebRequestCycleProcessor

>From wicket source code WebRequestCycleProcessor has a lock on session.
(Look at the source code below).
>From a profiler we can easily observe that %57 of the time is spent on this
function especially on lock region.
Is there any way to speed it up  this source code ?


 /**
  * @see
org.apache.wicket.request.IRequestCycleProcessor#resolve(org.apache.wicket.RequestCycle,
  *      org.apache.wicket.request.RequestParameters)
  */
 public IRequestTarget resolve(final RequestCycle requestCycle,
   final RequestParameters requestParameters)
 {
  IRequestCodingStrategy requestCodingStrategy = requestCycle.getProcessor()
    .getRequestCodingStrategy();

  final String path = requestParameters.getPath();
  IRequestTarget target = null;

  // See whether this request points to a bookmarkable page
  if (requestParameters.getBookmarkablePageClass() != null)
  {
   target = resolveBookmarkablePage(requestCycle, requestParameters);
  }
  // See whether this request points to a rendered page
  else if (requestParameters.getComponentPath() != null)
  {
   // marks whether or not we will be processing this request
   boolean processRequest = true;
   synchronized (requestCycle.getSession())
   {
    // we need to check if this request has been flagged as
    // process-only-if-path-is-active and if so make sure this
    // condition is met
    if (requestParameters.isOnlyProcessIfPathActive())
    {
     // this request has indeed been flagged as
     // process-only-if-path-is-active

     Session session = Session.get();
     IPageMap pageMap =
session.pageMapForName(requestParameters.getPageMapName(),
       false);
     if (pageMap == null)
     {
      // requested pagemap no longer exists - ignore this
      // request
      processRequest = false;
     }
     else if (pageMap instanceof AccessStackPageMap)
     {
      AccessStackPageMap accessStackPageMap = (AccessStackPageMap)pageMap;
      if (accessStackPageMap.getAccessStack().size() > 0)
      {
       final Access access = (Access)accessStackPageMap.getAccessStack()
         .peek();

       final int pageId = Integer
         .parseInt(Strings.firstPathComponent(requestParameters
           .getComponentPath(), Component.PATH_SEPARATOR));

       if (pageId != access.getId())
       {
        // the page is no longer the active page
        // - ignore this request
        processRequest = false;
       }
       else
       {
        final int version = requestParameters.getVersionNumber();
        if (version != Page.LATEST_VERSION &&
          version != access.getVersion())
        {
         // version is no longer the active version -
         // ignore this request
         processRequest = false;
        }
       }
      }
     }
     else
     {
      // TODO also this should work..
     }
    }
   }
   if (processRequest)
   {
    try
    {
     target = resolveRenderedPage(requestCycle, requestParameters);
    }
    catch (IgnoreAjaxRequestException e)
    {
     target = EmptyAjaxRequestTarget.getInstance();
    }
   }
   else
   {
    throw new PageExpiredException("Request cannot be processed");
   }
  }
  // See whether this request points to a shared resource
  else if (requestParameters.getResourceKey() != null)
  {
   target = resolveSharedResource(requestCycle, requestParameters);
  }
  // See whether this request points to the home page
  else if (Strings.isEmpty(path) || ("/".equals(path)))
  {
   target = resolveHomePageTarget(requestCycle, requestParameters);
  }

  // NOTE we are doing the mount check as the last item, so that it will
  // only be executed when everything else fails. This enables URLs like
  // /foo/bar/?wicket:bookmarkablePage=my.Page to be resolved, where
  // is either a valid mount or a non-valid mount. I (Eelco) am not
  // absolutely sure this is a great way to go, but it seems to have been
  // established as the default way of doing things. If we ever want to
  // tighten the algorithm up, it should be combined by going back to
  // unmounted paths so that requests with Wicket parameters like
  // 'bookmarkablePage' are always created and resolved in the same
  // fashion. There is a test for this in UrlMountingTest.
  if (target == null)
  {
   // still null? check for a mount
   target = requestCodingStrategy.targetForRequest(requestParameters);

   if (target == null && requestParameters.getComponentPath() != null)
   {
    // If the target is still null and there was a component path
    // then the Page could not be located in the session
    throw new PageExpiredException(
      "Cannot find the rendered page in session [pagemap=" +
        requestParameters.getPageMapName() + ",componentPath=" +
        requestParameters.getComponentPath() + ",versionNumber=" +
        requestParameters.getVersionNumber() + "]");
   }
  }
  else
  {
   // a target was found, but not by looking up a mount. check whether
   // this is allowed
   if (Application.get().getSecuritySettings().getEnforceMounts() &&
     requestCodingStrategy.pathForTarget(target) != null)
   {
    String msg = "Direct access not allowed for mounted targets";
    // the target was mounted, but we got here via another path
    // : deny the request
    log.error(msg + " [request=" + requestCycle.getRequest() + ",target=" +
target +
      ",session=" + Session.get() + "]");
    throw new
AbortWithWebErrorCodeException(HttpServletResponse.SC_FORBIDDEN, msg);
   }
  }

  // (WICKET-1356) in case no target was found, return null here.
RequestCycle will deal with it
  // possible letting wicket filter to pass the request down the filter
chain
  /*
  if (target == null)
  {
   // if we get here, we have no recognized Wicket target, and thus
   // regard this as a external (non-wicket) resource request on
   // this server
   return resolveExternalResource(requestCycle);
  }
  */

  return target;
 }


-- 
Pamir Erdem

Re: org.apachewicket.protocol.http.WebRequestCycleProcessor

Posted by Igor Vaynberg <ig...@gmail.com>.
search this list, google it. this has been answered on this list multiple times.

-igor

On Tue, Nov 10, 2009 at 3:22 PM, Pamir Erdem <pa...@gmail.com> wrote:
> Could you please send me a link that  how i can achieve this over wicket ?
>
> On Wed, Nov 11, 2009 at 1:18 AM, Igor Vaynberg <ig...@gmail.com>wrote:
>
>> well, its either we lock on the page, or you have to make sure all
>> your code is threadsafe.
>>
>> yes, this can be a problem for a lot of concurrent ajax requests, you
>> just have to make sure your responses are fast. eg if you have a
>> time-consuming operation do it in a background thread and make ajax
>> calls poll instead of block.
>>
>> -igor
>>
>> On Tue, Nov 10, 2009 at 2:09 PM, Pamir Erdem <pa...@gmail.com>
>> wrote:
>> > Hi
>> >
>> > There are parts in web which make ajax calls. In this situtation on
>> request
>> > blocks the piece of code till it returns a value. Do you recommend
>> anything
>> > about ajax calls in a web page?
>> >
>> > Thanks
>> > Pamir
>> > On Tue, Nov 10, 2009 at 9:28 PM, Igor Vaynberg <igor.vaynberg@gmail.com
>> >wrote:
>> >
>> >> can you submit a quickstart that reproduces this?
>> >>
>> >> the lock on session only blocks concurrent requests from the browser,
>> >> which is usually not a big deal because most users operate one window
>> >> at a time.
>> >>
>> >> also we do not get the same results in our wicket-threadtest project.
>> >>
>> >> -igor
>> >>
>> >> On Tue, Nov 10, 2009 at 10:17 AM, Pamir Erdem <pa...@gmail.com>
>> >> wrote:
>> >> > From wicket source code WebRequestCycleProcessor has a lock on
>> session.
>> >> > (Look at the source code below).
>> >> > From a profiler we can easily observe that %57 of the time is spent on
>> >> this
>> >> > function especially on lock region.
>> >> > Is there any way to speed it up  this source code ?
>> >> >
>> >> >
>> >> >  /**
>> >> >  * @see
>> >> >
>> >>
>> org.apache.wicket.request.IRequestCycleProcessor#resolve(org.apache.wicket.RequestCycle,
>> >> >  *      org.apache.wicket.request.RequestParameters)
>> >> >  */
>> >> >  public IRequestTarget resolve(final RequestCycle requestCycle,
>> >> >   final RequestParameters requestParameters)
>> >> >  {
>> >> >  IRequestCodingStrategy requestCodingStrategy =
>> >> requestCycle.getProcessor()
>> >> >    .getRequestCodingStrategy();
>> >> >
>> >> >  final String path = requestParameters.getPath();
>> >> >  IRequestTarget target = null;
>> >> >
>> >> >  // See whether this request points to a bookmarkable page
>> >> >  if (requestParameters.getBookmarkablePageClass() != null)
>> >> >  {
>> >> >   target = resolveBookmarkablePage(requestCycle, requestParameters);
>> >> >  }
>> >> >  // See whether this request points to a rendered page
>> >> >  else if (requestParameters.getComponentPath() != null)
>> >> >  {
>> >> >   // marks whether or not we will be processing this request
>> >> >   boolean processRequest = true;
>> >> >   synchronized (requestCycle.getSession())
>> >> >   {
>> >> >    // we need to check if this request has been flagged as
>> >> >    // process-only-if-path-is-active and if so make sure this
>> >> >    // condition is met
>> >> >    if (requestParameters.isOnlyProcessIfPathActive())
>> >> >    {
>> >> >     // this request has indeed been flagged as
>> >> >     // process-only-if-path-is-active
>> >> >
>> >> >     Session session = Session.get();
>> >> >     IPageMap pageMap =
>> >> > session.pageMapForName(requestParameters.getPageMapName(),
>> >> >       false);
>> >> >     if (pageMap == null)
>> >> >     {
>> >> >      // requested pagemap no longer exists - ignore this
>> >> >      // request
>> >> >      processRequest = false;
>> >> >     }
>> >> >     else if (pageMap instanceof AccessStackPageMap)
>> >> >     {
>> >> >      AccessStackPageMap accessStackPageMap =
>> (AccessStackPageMap)pageMap;
>> >> >      if (accessStackPageMap.getAccessStack().size() > 0)
>> >> >      {
>> >> >       final Access access =
>> (Access)accessStackPageMap.getAccessStack()
>> >> >         .peek();
>> >> >
>> >> >       final int pageId = Integer
>> >> >         .parseInt(Strings.firstPathComponent(requestParameters
>> >> >           .getComponentPath(), Component.PATH_SEPARATOR));
>> >> >
>> >> >       if (pageId != access.getId())
>> >> >       {
>> >> >        // the page is no longer the active page
>> >> >        // - ignore this request
>> >> >        processRequest = false;
>> >> >       }
>> >> >       else
>> >> >       {
>> >> >        final int version = requestParameters.getVersionNumber();
>> >> >        if (version != Page.LATEST_VERSION &&
>> >> >          version != access.getVersion())
>> >> >        {
>> >> >         // version is no longer the active version -
>> >> >         // ignore this request
>> >> >         processRequest = false;
>> >> >        }
>> >> >       }
>> >> >      }
>> >> >     }
>> >> >     else
>> >> >     {
>> >> >      // TODO also this should work..
>> >> >     }
>> >> >    }
>> >> >   }
>> >> >   if (processRequest)
>> >> >   {
>> >> >    try
>> >> >    {
>> >> >     target = resolveRenderedPage(requestCycle, requestParameters);
>> >> >    }
>> >> >    catch (IgnoreAjaxRequestException e)
>> >> >    {
>> >> >     target = EmptyAjaxRequestTarget.getInstance();
>> >> >    }
>> >> >   }
>> >> >   else
>> >> >   {
>> >> >    throw new PageExpiredException("Request cannot be processed");
>> >> >   }
>> >> >  }
>> >> >  // See whether this request points to a shared resource
>> >> >  else if (requestParameters.getResourceKey() != null)
>> >> >  {
>> >> >   target = resolveSharedResource(requestCycle, requestParameters);
>> >> >  }
>> >> >  // See whether this request points to the home page
>> >> >  else if (Strings.isEmpty(path) || ("/".equals(path)))
>> >> >  {
>> >> >   target = resolveHomePageTarget(requestCycle, requestParameters);
>> >> >  }
>> >> >
>> >> >  // NOTE we are doing the mount check as the last item, so that it
>> will
>> >> >  // only be executed when everything else fails. This enables URLs
>> like
>> >> >  // /foo/bar/?wicket:bookmarkablePage=my.Page to be resolved, where
>> >> >  // is either a valid mount or a non-valid mount. I (Eelco) am not
>> >> >  // absolutely sure this is a great way to go, but it seems to have
>> been
>> >> >  // established as the default way of doing things. If we ever want to
>> >> >  // tighten the algorithm up, it should be combined by going back to
>> >> >  // unmounted paths so that requests with Wicket parameters like
>> >> >  // 'bookmarkablePage' are always created and resolved in the same
>> >> >  // fashion. There is a test for this in UrlMountingTest.
>> >> >  if (target == null)
>> >> >  {
>> >> >   // still null? check for a mount
>> >> >   target = requestCodingStrategy.targetForRequest(requestParameters);
>> >> >
>> >> >   if (target == null && requestParameters.getComponentPath() != null)
>> >> >   {
>> >> >    // If the target is still null and there was a component path
>> >> >    // then the Page could not be located in the session
>> >> >    throw new PageExpiredException(
>> >> >      "Cannot find the rendered page in session [pagemap=" +
>> >> >        requestParameters.getPageMapName() + ",componentPath=" +
>> >> >        requestParameters.getComponentPath() + ",versionNumber=" +
>> >> >        requestParameters.getVersionNumber() + "]");
>> >> >   }
>> >> >  }
>> >> >  else
>> >> >  {
>> >> >   // a target was found, but not by looking up a mount. check whether
>> >> >   // this is allowed
>> >> >   if (Application.get().getSecuritySettings().getEnforceMounts() &&
>> >> >     requestCodingStrategy.pathForTarget(target) != null)
>> >> >   {
>> >> >    String msg = "Direct access not allowed for mounted targets";
>> >> >    // the target was mounted, but we got here via another path
>> >> >    // : deny the request
>> >> >    log.error(msg + " [request=" + requestCycle.getRequest() +
>> ",target="
>> >> +
>> >> > target +
>> >> >      ",session=" + Session.get() + "]");
>> >> >    throw new
>> >> > AbortWithWebErrorCodeException(HttpServletResponse.SC_FORBIDDEN, msg);
>> >> >   }
>> >> >  }
>> >> >
>> >> >  // (WICKET-1356) in case no target was found, return null here.
>> >> > RequestCycle will deal with it
>> >> >  // possible letting wicket filter to pass the request down the filter
>> >> > chain
>> >> >  /*
>> >> >  if (target == null)
>> >> >  {
>> >> >   // if we get here, we have no recognized Wicket target, and thus
>> >> >   // regard this as a external (non-wicket) resource request on
>> >> >   // this server
>> >> >   return resolveExternalResource(requestCycle);
>> >> >  }
>> >> >  */
>> >> >
>> >> >  return target;
>> >> >  }
>> >> >
>> >> >
>> >> > --
>> >> > Pamir Erdem
>> >> >
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> >> For additional commands, e-mail: users-help@wicket.apache.org
>> >>
>> >>
>> >
>> >
>> > --
>> > Pamir Erdem
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>
> --
> Pamir Erdem
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: org.apachewicket.protocol.http.WebRequestCycleProcessor

Posted by Pamir Erdem <pa...@gmail.com>.
Could you please send me a link that  how i can achieve this over wicket ?

On Wed, Nov 11, 2009 at 1:18 AM, Igor Vaynberg <ig...@gmail.com>wrote:

> well, its either we lock on the page, or you have to make sure all
> your code is threadsafe.
>
> yes, this can be a problem for a lot of concurrent ajax requests, you
> just have to make sure your responses are fast. eg if you have a
> time-consuming operation do it in a background thread and make ajax
> calls poll instead of block.
>
> -igor
>
> On Tue, Nov 10, 2009 at 2:09 PM, Pamir Erdem <pa...@gmail.com>
> wrote:
> > Hi
> >
> > There are parts in web which make ajax calls. In this situtation on
> request
> > blocks the piece of code till it returns a value. Do you recommend
> anything
> > about ajax calls in a web page?
> >
> > Thanks
> > Pamir
> > On Tue, Nov 10, 2009 at 9:28 PM, Igor Vaynberg <igor.vaynberg@gmail.com
> >wrote:
> >
> >> can you submit a quickstart that reproduces this?
> >>
> >> the lock on session only blocks concurrent requests from the browser,
> >> which is usually not a big deal because most users operate one window
> >> at a time.
> >>
> >> also we do not get the same results in our wicket-threadtest project.
> >>
> >> -igor
> >>
> >> On Tue, Nov 10, 2009 at 10:17 AM, Pamir Erdem <pa...@gmail.com>
> >> wrote:
> >> > From wicket source code WebRequestCycleProcessor has a lock on
> session.
> >> > (Look at the source code below).
> >> > From a profiler we can easily observe that %57 of the time is spent on
> >> this
> >> > function especially on lock region.
> >> > Is there any way to speed it up  this source code ?
> >> >
> >> >
> >> >  /**
> >> >  * @see
> >> >
> >>
> org.apache.wicket.request.IRequestCycleProcessor#resolve(org.apache.wicket.RequestCycle,
> >> >  *      org.apache.wicket.request.RequestParameters)
> >> >  */
> >> >  public IRequestTarget resolve(final RequestCycle requestCycle,
> >> >   final RequestParameters requestParameters)
> >> >  {
> >> >  IRequestCodingStrategy requestCodingStrategy =
> >> requestCycle.getProcessor()
> >> >    .getRequestCodingStrategy();
> >> >
> >> >  final String path = requestParameters.getPath();
> >> >  IRequestTarget target = null;
> >> >
> >> >  // See whether this request points to a bookmarkable page
> >> >  if (requestParameters.getBookmarkablePageClass() != null)
> >> >  {
> >> >   target = resolveBookmarkablePage(requestCycle, requestParameters);
> >> >  }
> >> >  // See whether this request points to a rendered page
> >> >  else if (requestParameters.getComponentPath() != null)
> >> >  {
> >> >   // marks whether or not we will be processing this request
> >> >   boolean processRequest = true;
> >> >   synchronized (requestCycle.getSession())
> >> >   {
> >> >    // we need to check if this request has been flagged as
> >> >    // process-only-if-path-is-active and if so make sure this
> >> >    // condition is met
> >> >    if (requestParameters.isOnlyProcessIfPathActive())
> >> >    {
> >> >     // this request has indeed been flagged as
> >> >     // process-only-if-path-is-active
> >> >
> >> >     Session session = Session.get();
> >> >     IPageMap pageMap =
> >> > session.pageMapForName(requestParameters.getPageMapName(),
> >> >       false);
> >> >     if (pageMap == null)
> >> >     {
> >> >      // requested pagemap no longer exists - ignore this
> >> >      // request
> >> >      processRequest = false;
> >> >     }
> >> >     else if (pageMap instanceof AccessStackPageMap)
> >> >     {
> >> >      AccessStackPageMap accessStackPageMap =
> (AccessStackPageMap)pageMap;
> >> >      if (accessStackPageMap.getAccessStack().size() > 0)
> >> >      {
> >> >       final Access access =
> (Access)accessStackPageMap.getAccessStack()
> >> >         .peek();
> >> >
> >> >       final int pageId = Integer
> >> >         .parseInt(Strings.firstPathComponent(requestParameters
> >> >           .getComponentPath(), Component.PATH_SEPARATOR));
> >> >
> >> >       if (pageId != access.getId())
> >> >       {
> >> >        // the page is no longer the active page
> >> >        // - ignore this request
> >> >        processRequest = false;
> >> >       }
> >> >       else
> >> >       {
> >> >        final int version = requestParameters.getVersionNumber();
> >> >        if (version != Page.LATEST_VERSION &&
> >> >          version != access.getVersion())
> >> >        {
> >> >         // version is no longer the active version -
> >> >         // ignore this request
> >> >         processRequest = false;
> >> >        }
> >> >       }
> >> >      }
> >> >     }
> >> >     else
> >> >     {
> >> >      // TODO also this should work..
> >> >     }
> >> >    }
> >> >   }
> >> >   if (processRequest)
> >> >   {
> >> >    try
> >> >    {
> >> >     target = resolveRenderedPage(requestCycle, requestParameters);
> >> >    }
> >> >    catch (IgnoreAjaxRequestException e)
> >> >    {
> >> >     target = EmptyAjaxRequestTarget.getInstance();
> >> >    }
> >> >   }
> >> >   else
> >> >   {
> >> >    throw new PageExpiredException("Request cannot be processed");
> >> >   }
> >> >  }
> >> >  // See whether this request points to a shared resource
> >> >  else if (requestParameters.getResourceKey() != null)
> >> >  {
> >> >   target = resolveSharedResource(requestCycle, requestParameters);
> >> >  }
> >> >  // See whether this request points to the home page
> >> >  else if (Strings.isEmpty(path) || ("/".equals(path)))
> >> >  {
> >> >   target = resolveHomePageTarget(requestCycle, requestParameters);
> >> >  }
> >> >
> >> >  // NOTE we are doing the mount check as the last item, so that it
> will
> >> >  // only be executed when everything else fails. This enables URLs
> like
> >> >  // /foo/bar/?wicket:bookmarkablePage=my.Page to be resolved, where
> >> >  // is either a valid mount or a non-valid mount. I (Eelco) am not
> >> >  // absolutely sure this is a great way to go, but it seems to have
> been
> >> >  // established as the default way of doing things. If we ever want to
> >> >  // tighten the algorithm up, it should be combined by going back to
> >> >  // unmounted paths so that requests with Wicket parameters like
> >> >  // 'bookmarkablePage' are always created and resolved in the same
> >> >  // fashion. There is a test for this in UrlMountingTest.
> >> >  if (target == null)
> >> >  {
> >> >   // still null? check for a mount
> >> >   target = requestCodingStrategy.targetForRequest(requestParameters);
> >> >
> >> >   if (target == null && requestParameters.getComponentPath() != null)
> >> >   {
> >> >    // If the target is still null and there was a component path
> >> >    // then the Page could not be located in the session
> >> >    throw new PageExpiredException(
> >> >      "Cannot find the rendered page in session [pagemap=" +
> >> >        requestParameters.getPageMapName() + ",componentPath=" +
> >> >        requestParameters.getComponentPath() + ",versionNumber=" +
> >> >        requestParameters.getVersionNumber() + "]");
> >> >   }
> >> >  }
> >> >  else
> >> >  {
> >> >   // a target was found, but not by looking up a mount. check whether
> >> >   // this is allowed
> >> >   if (Application.get().getSecuritySettings().getEnforceMounts() &&
> >> >     requestCodingStrategy.pathForTarget(target) != null)
> >> >   {
> >> >    String msg = "Direct access not allowed for mounted targets";
> >> >    // the target was mounted, but we got here via another path
> >> >    // : deny the request
> >> >    log.error(msg + " [request=" + requestCycle.getRequest() +
> ",target="
> >> +
> >> > target +
> >> >      ",session=" + Session.get() + "]");
> >> >    throw new
> >> > AbortWithWebErrorCodeException(HttpServletResponse.SC_FORBIDDEN, msg);
> >> >   }
> >> >  }
> >> >
> >> >  // (WICKET-1356) in case no target was found, return null here.
> >> > RequestCycle will deal with it
> >> >  // possible letting wicket filter to pass the request down the filter
> >> > chain
> >> >  /*
> >> >  if (target == null)
> >> >  {
> >> >   // if we get here, we have no recognized Wicket target, and thus
> >> >   // regard this as a external (non-wicket) resource request on
> >> >   // this server
> >> >   return resolveExternalResource(requestCycle);
> >> >  }
> >> >  */
> >> >
> >> >  return target;
> >> >  }
> >> >
> >> >
> >> > --
> >> > Pamir Erdem
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >>
> >>
> >
> >
> > --
> > Pamir Erdem
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Pamir Erdem

Re: org.apachewicket.protocol.http.WebRequestCycleProcessor

Posted by Igor Vaynberg <ig...@gmail.com>.
well, its either we lock on the page, or you have to make sure all
your code is threadsafe.

yes, this can be a problem for a lot of concurrent ajax requests, you
just have to make sure your responses are fast. eg if you have a
time-consuming operation do it in a background thread and make ajax
calls poll instead of block.

-igor

On Tue, Nov 10, 2009 at 2:09 PM, Pamir Erdem <pa...@gmail.com> wrote:
> Hi
>
> There are parts in web which make ajax calls. In this situtation on request
> blocks the piece of code till it returns a value. Do you recommend anything
> about ajax calls in a web page?
>
> Thanks
> Pamir
> On Tue, Nov 10, 2009 at 9:28 PM, Igor Vaynberg <ig...@gmail.com>wrote:
>
>> can you submit a quickstart that reproduces this?
>>
>> the lock on session only blocks concurrent requests from the browser,
>> which is usually not a big deal because most users operate one window
>> at a time.
>>
>> also we do not get the same results in our wicket-threadtest project.
>>
>> -igor
>>
>> On Tue, Nov 10, 2009 at 10:17 AM, Pamir Erdem <pa...@gmail.com>
>> wrote:
>> > From wicket source code WebRequestCycleProcessor has a lock on session.
>> > (Look at the source code below).
>> > From a profiler we can easily observe that %57 of the time is spent on
>> this
>> > function especially on lock region.
>> > Is there any way to speed it up  this source code ?
>> >
>> >
>> >  /**
>> >  * @see
>> >
>> org.apache.wicket.request.IRequestCycleProcessor#resolve(org.apache.wicket.RequestCycle,
>> >  *      org.apache.wicket.request.RequestParameters)
>> >  */
>> >  public IRequestTarget resolve(final RequestCycle requestCycle,
>> >   final RequestParameters requestParameters)
>> >  {
>> >  IRequestCodingStrategy requestCodingStrategy =
>> requestCycle.getProcessor()
>> >    .getRequestCodingStrategy();
>> >
>> >  final String path = requestParameters.getPath();
>> >  IRequestTarget target = null;
>> >
>> >  // See whether this request points to a bookmarkable page
>> >  if (requestParameters.getBookmarkablePageClass() != null)
>> >  {
>> >   target = resolveBookmarkablePage(requestCycle, requestParameters);
>> >  }
>> >  // See whether this request points to a rendered page
>> >  else if (requestParameters.getComponentPath() != null)
>> >  {
>> >   // marks whether or not we will be processing this request
>> >   boolean processRequest = true;
>> >   synchronized (requestCycle.getSession())
>> >   {
>> >    // we need to check if this request has been flagged as
>> >    // process-only-if-path-is-active and if so make sure this
>> >    // condition is met
>> >    if (requestParameters.isOnlyProcessIfPathActive())
>> >    {
>> >     // this request has indeed been flagged as
>> >     // process-only-if-path-is-active
>> >
>> >     Session session = Session.get();
>> >     IPageMap pageMap =
>> > session.pageMapForName(requestParameters.getPageMapName(),
>> >       false);
>> >     if (pageMap == null)
>> >     {
>> >      // requested pagemap no longer exists - ignore this
>> >      // request
>> >      processRequest = false;
>> >     }
>> >     else if (pageMap instanceof AccessStackPageMap)
>> >     {
>> >      AccessStackPageMap accessStackPageMap = (AccessStackPageMap)pageMap;
>> >      if (accessStackPageMap.getAccessStack().size() > 0)
>> >      {
>> >       final Access access = (Access)accessStackPageMap.getAccessStack()
>> >         .peek();
>> >
>> >       final int pageId = Integer
>> >         .parseInt(Strings.firstPathComponent(requestParameters
>> >           .getComponentPath(), Component.PATH_SEPARATOR));
>> >
>> >       if (pageId != access.getId())
>> >       {
>> >        // the page is no longer the active page
>> >        // - ignore this request
>> >        processRequest = false;
>> >       }
>> >       else
>> >       {
>> >        final int version = requestParameters.getVersionNumber();
>> >        if (version != Page.LATEST_VERSION &&
>> >          version != access.getVersion())
>> >        {
>> >         // version is no longer the active version -
>> >         // ignore this request
>> >         processRequest = false;
>> >        }
>> >       }
>> >      }
>> >     }
>> >     else
>> >     {
>> >      // TODO also this should work..
>> >     }
>> >    }
>> >   }
>> >   if (processRequest)
>> >   {
>> >    try
>> >    {
>> >     target = resolveRenderedPage(requestCycle, requestParameters);
>> >    }
>> >    catch (IgnoreAjaxRequestException e)
>> >    {
>> >     target = EmptyAjaxRequestTarget.getInstance();
>> >    }
>> >   }
>> >   else
>> >   {
>> >    throw new PageExpiredException("Request cannot be processed");
>> >   }
>> >  }
>> >  // See whether this request points to a shared resource
>> >  else if (requestParameters.getResourceKey() != null)
>> >  {
>> >   target = resolveSharedResource(requestCycle, requestParameters);
>> >  }
>> >  // See whether this request points to the home page
>> >  else if (Strings.isEmpty(path) || ("/".equals(path)))
>> >  {
>> >   target = resolveHomePageTarget(requestCycle, requestParameters);
>> >  }
>> >
>> >  // NOTE we are doing the mount check as the last item, so that it will
>> >  // only be executed when everything else fails. This enables URLs like
>> >  // /foo/bar/?wicket:bookmarkablePage=my.Page to be resolved, where
>> >  // is either a valid mount or a non-valid mount. I (Eelco) am not
>> >  // absolutely sure this is a great way to go, but it seems to have been
>> >  // established as the default way of doing things. If we ever want to
>> >  // tighten the algorithm up, it should be combined by going back to
>> >  // unmounted paths so that requests with Wicket parameters like
>> >  // 'bookmarkablePage' are always created and resolved in the same
>> >  // fashion. There is a test for this in UrlMountingTest.
>> >  if (target == null)
>> >  {
>> >   // still null? check for a mount
>> >   target = requestCodingStrategy.targetForRequest(requestParameters);
>> >
>> >   if (target == null && requestParameters.getComponentPath() != null)
>> >   {
>> >    // If the target is still null and there was a component path
>> >    // then the Page could not be located in the session
>> >    throw new PageExpiredException(
>> >      "Cannot find the rendered page in session [pagemap=" +
>> >        requestParameters.getPageMapName() + ",componentPath=" +
>> >        requestParameters.getComponentPath() + ",versionNumber=" +
>> >        requestParameters.getVersionNumber() + "]");
>> >   }
>> >  }
>> >  else
>> >  {
>> >   // a target was found, but not by looking up a mount. check whether
>> >   // this is allowed
>> >   if (Application.get().getSecuritySettings().getEnforceMounts() &&
>> >     requestCodingStrategy.pathForTarget(target) != null)
>> >   {
>> >    String msg = "Direct access not allowed for mounted targets";
>> >    // the target was mounted, but we got here via another path
>> >    // : deny the request
>> >    log.error(msg + " [request=" + requestCycle.getRequest() + ",target="
>> +
>> > target +
>> >      ",session=" + Session.get() + "]");
>> >    throw new
>> > AbortWithWebErrorCodeException(HttpServletResponse.SC_FORBIDDEN, msg);
>> >   }
>> >  }
>> >
>> >  // (WICKET-1356) in case no target was found, return null here.
>> > RequestCycle will deal with it
>> >  // possible letting wicket filter to pass the request down the filter
>> > chain
>> >  /*
>> >  if (target == null)
>> >  {
>> >   // if we get here, we have no recognized Wicket target, and thus
>> >   // regard this as a external (non-wicket) resource request on
>> >   // this server
>> >   return resolveExternalResource(requestCycle);
>> >  }
>> >  */
>> >
>> >  return target;
>> >  }
>> >
>> >
>> > --
>> > Pamir Erdem
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>
> --
> Pamir Erdem
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: org.apachewicket.protocol.http.WebRequestCycleProcessor

Posted by Pamir Erdem <pa...@gmail.com>.
Hi

There are parts in web which make ajax calls. In this situtation on request
blocks the piece of code till it returns a value. Do you recommend anything
about ajax calls in a web page?

Thanks
Pamir
On Tue, Nov 10, 2009 at 9:28 PM, Igor Vaynberg <ig...@gmail.com>wrote:

> can you submit a quickstart that reproduces this?
>
> the lock on session only blocks concurrent requests from the browser,
> which is usually not a big deal because most users operate one window
> at a time.
>
> also we do not get the same results in our wicket-threadtest project.
>
> -igor
>
> On Tue, Nov 10, 2009 at 10:17 AM, Pamir Erdem <pa...@gmail.com>
> wrote:
> > From wicket source code WebRequestCycleProcessor has a lock on session.
> > (Look at the source code below).
> > From a profiler we can easily observe that %57 of the time is spent on
> this
> > function especially on lock region.
> > Is there any way to speed it up  this source code ?
> >
> >
> >  /**
> >  * @see
> >
> org.apache.wicket.request.IRequestCycleProcessor#resolve(org.apache.wicket.RequestCycle,
> >  *      org.apache.wicket.request.RequestParameters)
> >  */
> >  public IRequestTarget resolve(final RequestCycle requestCycle,
> >   final RequestParameters requestParameters)
> >  {
> >  IRequestCodingStrategy requestCodingStrategy =
> requestCycle.getProcessor()
> >    .getRequestCodingStrategy();
> >
> >  final String path = requestParameters.getPath();
> >  IRequestTarget target = null;
> >
> >  // See whether this request points to a bookmarkable page
> >  if (requestParameters.getBookmarkablePageClass() != null)
> >  {
> >   target = resolveBookmarkablePage(requestCycle, requestParameters);
> >  }
> >  // See whether this request points to a rendered page
> >  else if (requestParameters.getComponentPath() != null)
> >  {
> >   // marks whether or not we will be processing this request
> >   boolean processRequest = true;
> >   synchronized (requestCycle.getSession())
> >   {
> >    // we need to check if this request has been flagged as
> >    // process-only-if-path-is-active and if so make sure this
> >    // condition is met
> >    if (requestParameters.isOnlyProcessIfPathActive())
> >    {
> >     // this request has indeed been flagged as
> >     // process-only-if-path-is-active
> >
> >     Session session = Session.get();
> >     IPageMap pageMap =
> > session.pageMapForName(requestParameters.getPageMapName(),
> >       false);
> >     if (pageMap == null)
> >     {
> >      // requested pagemap no longer exists - ignore this
> >      // request
> >      processRequest = false;
> >     }
> >     else if (pageMap instanceof AccessStackPageMap)
> >     {
> >      AccessStackPageMap accessStackPageMap = (AccessStackPageMap)pageMap;
> >      if (accessStackPageMap.getAccessStack().size() > 0)
> >      {
> >       final Access access = (Access)accessStackPageMap.getAccessStack()
> >         .peek();
> >
> >       final int pageId = Integer
> >         .parseInt(Strings.firstPathComponent(requestParameters
> >           .getComponentPath(), Component.PATH_SEPARATOR));
> >
> >       if (pageId != access.getId())
> >       {
> >        // the page is no longer the active page
> >        // - ignore this request
> >        processRequest = false;
> >       }
> >       else
> >       {
> >        final int version = requestParameters.getVersionNumber();
> >        if (version != Page.LATEST_VERSION &&
> >          version != access.getVersion())
> >        {
> >         // version is no longer the active version -
> >         // ignore this request
> >         processRequest = false;
> >        }
> >       }
> >      }
> >     }
> >     else
> >     {
> >      // TODO also this should work..
> >     }
> >    }
> >   }
> >   if (processRequest)
> >   {
> >    try
> >    {
> >     target = resolveRenderedPage(requestCycle, requestParameters);
> >    }
> >    catch (IgnoreAjaxRequestException e)
> >    {
> >     target = EmptyAjaxRequestTarget.getInstance();
> >    }
> >   }
> >   else
> >   {
> >    throw new PageExpiredException("Request cannot be processed");
> >   }
> >  }
> >  // See whether this request points to a shared resource
> >  else if (requestParameters.getResourceKey() != null)
> >  {
> >   target = resolveSharedResource(requestCycle, requestParameters);
> >  }
> >  // See whether this request points to the home page
> >  else if (Strings.isEmpty(path) || ("/".equals(path)))
> >  {
> >   target = resolveHomePageTarget(requestCycle, requestParameters);
> >  }
> >
> >  // NOTE we are doing the mount check as the last item, so that it will
> >  // only be executed when everything else fails. This enables URLs like
> >  // /foo/bar/?wicket:bookmarkablePage=my.Page to be resolved, where
> >  // is either a valid mount or a non-valid mount. I (Eelco) am not
> >  // absolutely sure this is a great way to go, but it seems to have been
> >  // established as the default way of doing things. If we ever want to
> >  // tighten the algorithm up, it should be combined by going back to
> >  // unmounted paths so that requests with Wicket parameters like
> >  // 'bookmarkablePage' are always created and resolved in the same
> >  // fashion. There is a test for this in UrlMountingTest.
> >  if (target == null)
> >  {
> >   // still null? check for a mount
> >   target = requestCodingStrategy.targetForRequest(requestParameters);
> >
> >   if (target == null && requestParameters.getComponentPath() != null)
> >   {
> >    // If the target is still null and there was a component path
> >    // then the Page could not be located in the session
> >    throw new PageExpiredException(
> >      "Cannot find the rendered page in session [pagemap=" +
> >        requestParameters.getPageMapName() + ",componentPath=" +
> >        requestParameters.getComponentPath() + ",versionNumber=" +
> >        requestParameters.getVersionNumber() + "]");
> >   }
> >  }
> >  else
> >  {
> >   // a target was found, but not by looking up a mount. check whether
> >   // this is allowed
> >   if (Application.get().getSecuritySettings().getEnforceMounts() &&
> >     requestCodingStrategy.pathForTarget(target) != null)
> >   {
> >    String msg = "Direct access not allowed for mounted targets";
> >    // the target was mounted, but we got here via another path
> >    // : deny the request
> >    log.error(msg + " [request=" + requestCycle.getRequest() + ",target="
> +
> > target +
> >      ",session=" + Session.get() + "]");
> >    throw new
> > AbortWithWebErrorCodeException(HttpServletResponse.SC_FORBIDDEN, msg);
> >   }
> >  }
> >
> >  // (WICKET-1356) in case no target was found, return null here.
> > RequestCycle will deal with it
> >  // possible letting wicket filter to pass the request down the filter
> > chain
> >  /*
> >  if (target == null)
> >  {
> >   // if we get here, we have no recognized Wicket target, and thus
> >   // regard this as a external (non-wicket) resource request on
> >   // this server
> >   return resolveExternalResource(requestCycle);
> >  }
> >  */
> >
> >  return target;
> >  }
> >
> >
> > --
> > Pamir Erdem
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Pamir Erdem

Re: org.apachewicket.protocol.http.WebRequestCycleProcessor

Posted by Igor Vaynberg <ig...@gmail.com>.
can you submit a quickstart that reproduces this?

the lock on session only blocks concurrent requests from the browser,
which is usually not a big deal because most users operate one window
at a time.

also we do not get the same results in our wicket-threadtest project.

-igor

On Tue, Nov 10, 2009 at 10:17 AM, Pamir Erdem <pa...@gmail.com> wrote:
> From wicket source code WebRequestCycleProcessor has a lock on session.
> (Look at the source code below).
> From a profiler we can easily observe that %57 of the time is spent on this
> function especially on lock region.
> Is there any way to speed it up  this source code ?
>
>
>  /**
>  * @see
> org.apache.wicket.request.IRequestCycleProcessor#resolve(org.apache.wicket.RequestCycle,
>  *      org.apache.wicket.request.RequestParameters)
>  */
>  public IRequestTarget resolve(final RequestCycle requestCycle,
>   final RequestParameters requestParameters)
>  {
>  IRequestCodingStrategy requestCodingStrategy = requestCycle.getProcessor()
>    .getRequestCodingStrategy();
>
>  final String path = requestParameters.getPath();
>  IRequestTarget target = null;
>
>  // See whether this request points to a bookmarkable page
>  if (requestParameters.getBookmarkablePageClass() != null)
>  {
>   target = resolveBookmarkablePage(requestCycle, requestParameters);
>  }
>  // See whether this request points to a rendered page
>  else if (requestParameters.getComponentPath() != null)
>  {
>   // marks whether or not we will be processing this request
>   boolean processRequest = true;
>   synchronized (requestCycle.getSession())
>   {
>    // we need to check if this request has been flagged as
>    // process-only-if-path-is-active and if so make sure this
>    // condition is met
>    if (requestParameters.isOnlyProcessIfPathActive())
>    {
>     // this request has indeed been flagged as
>     // process-only-if-path-is-active
>
>     Session session = Session.get();
>     IPageMap pageMap =
> session.pageMapForName(requestParameters.getPageMapName(),
>       false);
>     if (pageMap == null)
>     {
>      // requested pagemap no longer exists - ignore this
>      // request
>      processRequest = false;
>     }
>     else if (pageMap instanceof AccessStackPageMap)
>     {
>      AccessStackPageMap accessStackPageMap = (AccessStackPageMap)pageMap;
>      if (accessStackPageMap.getAccessStack().size() > 0)
>      {
>       final Access access = (Access)accessStackPageMap.getAccessStack()
>         .peek();
>
>       final int pageId = Integer
>         .parseInt(Strings.firstPathComponent(requestParameters
>           .getComponentPath(), Component.PATH_SEPARATOR));
>
>       if (pageId != access.getId())
>       {
>        // the page is no longer the active page
>        // - ignore this request
>        processRequest = false;
>       }
>       else
>       {
>        final int version = requestParameters.getVersionNumber();
>        if (version != Page.LATEST_VERSION &&
>          version != access.getVersion())
>        {
>         // version is no longer the active version -
>         // ignore this request
>         processRequest = false;
>        }
>       }
>      }
>     }
>     else
>     {
>      // TODO also this should work..
>     }
>    }
>   }
>   if (processRequest)
>   {
>    try
>    {
>     target = resolveRenderedPage(requestCycle, requestParameters);
>    }
>    catch (IgnoreAjaxRequestException e)
>    {
>     target = EmptyAjaxRequestTarget.getInstance();
>    }
>   }
>   else
>   {
>    throw new PageExpiredException("Request cannot be processed");
>   }
>  }
>  // See whether this request points to a shared resource
>  else if (requestParameters.getResourceKey() != null)
>  {
>   target = resolveSharedResource(requestCycle, requestParameters);
>  }
>  // See whether this request points to the home page
>  else if (Strings.isEmpty(path) || ("/".equals(path)))
>  {
>   target = resolveHomePageTarget(requestCycle, requestParameters);
>  }
>
>  // NOTE we are doing the mount check as the last item, so that it will
>  // only be executed when everything else fails. This enables URLs like
>  // /foo/bar/?wicket:bookmarkablePage=my.Page to be resolved, where
>  // is either a valid mount or a non-valid mount. I (Eelco) am not
>  // absolutely sure this is a great way to go, but it seems to have been
>  // established as the default way of doing things. If we ever want to
>  // tighten the algorithm up, it should be combined by going back to
>  // unmounted paths so that requests with Wicket parameters like
>  // 'bookmarkablePage' are always created and resolved in the same
>  // fashion. There is a test for this in UrlMountingTest.
>  if (target == null)
>  {
>   // still null? check for a mount
>   target = requestCodingStrategy.targetForRequest(requestParameters);
>
>   if (target == null && requestParameters.getComponentPath() != null)
>   {
>    // If the target is still null and there was a component path
>    // then the Page could not be located in the session
>    throw new PageExpiredException(
>      "Cannot find the rendered page in session [pagemap=" +
>        requestParameters.getPageMapName() + ",componentPath=" +
>        requestParameters.getComponentPath() + ",versionNumber=" +
>        requestParameters.getVersionNumber() + "]");
>   }
>  }
>  else
>  {
>   // a target was found, but not by looking up a mount. check whether
>   // this is allowed
>   if (Application.get().getSecuritySettings().getEnforceMounts() &&
>     requestCodingStrategy.pathForTarget(target) != null)
>   {
>    String msg = "Direct access not allowed for mounted targets";
>    // the target was mounted, but we got here via another path
>    // : deny the request
>    log.error(msg + " [request=" + requestCycle.getRequest() + ",target=" +
> target +
>      ",session=" + Session.get() + "]");
>    throw new
> AbortWithWebErrorCodeException(HttpServletResponse.SC_FORBIDDEN, msg);
>   }
>  }
>
>  // (WICKET-1356) in case no target was found, return null here.
> RequestCycle will deal with it
>  // possible letting wicket filter to pass the request down the filter
> chain
>  /*
>  if (target == null)
>  {
>   // if we get here, we have no recognized Wicket target, and thus
>   // regard this as a external (non-wicket) resource request on
>   // this server
>   return resolveExternalResource(requestCycle);
>  }
>  */
>
>  return target;
>  }
>
>
> --
> Pamir Erdem
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org