You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Thomas Boniface <th...@stickyads.tv> on 2016/02/11 12:07:22 UTC

Async servlet timeout behaviour

Hi,

I'm using async servlet with a timeout configured to 300ms but I can
observe in live environnement some big differences with the actual applied
timeout  700ms or more for instance.

I was wondering how are triggered onTimeout events to AsyncListeners, is
there a limited number of thread handling this ? Could this be explained by
too many onTimeout occuring concurrently on a busy server ?

I also wonder what can be done or not while in the onTimeout thread, can I
still do some asynchronous operation (retrieving content from http request)
and is writing to the reponse from this thread, as long as I ensured this
done in a thread safe way, ok ?

Thanks,
Thomas

Re: Async servlet timeout behaviour

Posted by Thomas Boniface <th...@stickyads.tv>.
2016-02-11 12:31 GMT+01:00 André Warnier (tomcat) <aw...@ice-sa.com>:

> On 11.02.2016 12:07, Thomas Boniface wrote:
>
>> Hi,
>>
>> I'm using async servlet with a timeout configured to 300ms
>>
>
> naive question : is that not awfully short, if this relates to some
> over-the-Internet communication ?
>
That's a matter of context I guess, in a real time bidding context for
video advertising we expect to have a non noticable delay before being able
to reply to a request.

>
> but I can
>
>> observe in live environnement some big differences with the actual applied
>> timeout  700ms or more for instance.
>>
>> I was wondering how are triggered onTimeout events to AsyncListeners, is
>> there a limited number of thread handling this ? Could this be explained
>> by
>> too many onTimeout occuring concurrently on a busy server ?
>>
>> I also wonder what can be done or not while in the onTimeout thread, can I
>> still do some asynchronous operation (retrieving content from http
>> request)
>> and is writing to the reponse from this thread, as long as I ensured this
>> done in a thread safe way, ok ?
>>
>> Thanks,
>> Thomas
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Async servlet timeout behaviour

Posted by "André Warnier (tomcat)" <aw...@ice-sa.com>.
On 11.02.2016 12:07, Thomas Boniface wrote:
> Hi,
>
> I'm using async servlet with a timeout configured to 300ms

naive question : is that not awfully short, if this relates to some over-the-Internet 
communication ?

but I can
> observe in live environnement some big differences with the actual applied
> timeout  700ms or more for instance.
>
> I was wondering how are triggered onTimeout events to AsyncListeners, is
> there a limited number of thread handling this ? Could this be explained by
> too many onTimeout occuring concurrently on a busy server ?
>
> I also wonder what can be done or not while in the onTimeout thread, can I
> still do some asynchronous operation (retrieving content from http request)
> and is writing to the reponse from this thread, as long as I ensured this
> done in a thread safe way, ok ?
>
> Thanks,
> Thomas
>


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


Re: Async servlet timeout behaviour

Posted by Mark Thomas <ma...@apache.org>.
On 11/02/2016 11:44, Thomas Boniface wrote:
> 2016-02-11 12:16 GMT+01:00 Mark Thomas <ma...@apache.org>:
>> On 11/02/2016 11:07, Thomas Boniface wrote:

<snip/>

>>> I also wonder what can be done or not while in the onTimeout thread, can
>> I
>>> still do some asynchronous operation (retrieving content from http
>> request)
>>> and is writing to the reponse from this thread, as long as I ensured this
>>> done in a thread safe way, ok ?
>>
>> This is all in the Servlet spec.
>>
> I'll study the spec, I spent a lot of time looking for some documentation
> without thinking of reading the specs themselves, my bad.
> 
>>
>> In summary:
>> - You can perform any operation that is valid for a request in async mode.
>>
> This will have no impact on other request onTimeout triggering no matter
> what I do within the onTimeout ?

Correct. The timeout thread dispatches the processing of the timeout to
a separate thread for each AsyncContext that is timing out.

>> - You MUST call complete() or dispatch() before exiting onTimeout().
>>
> If the onTimeout occurs but another thread created by the same request is
> already writing the response I assume this thread will call complete() and
> the onTimeout thread must not do anything ?

No. The onTimeout thread MUST call complete() or dispatch(). If another
application thread is still performing processing then onTimeout() needs
to cancel that processing. Applications are responsible for making sure
all of this happens in a thread-safe manner.

If onTimeout() doesn't call complete(), Tomcat will followed by a 500
response.

If the application thread continues to processing then all sorts of
nasty things will happen because Tomcat will recycle the request and
response and at some point they will be re-used.

Mark

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


Re: Async servlet timeout behaviour

Posted by Thomas Boniface <th...@stickyads.tv>.
2016-02-11 12:16 GMT+01:00 Mark Thomas <ma...@apache.org>:

> On 11/02/2016 11:07, Thomas Boniface wrote:
> > Hi,
> >
> > I'm using async servlet with a timeout configured to 300ms but I can
> > observe in live environnement some big differences with the actual
> applied
> > timeout  700ms or more for instance.
> >
> > I was wondering how are triggered onTimeout events to AsyncListeners, is
> > there a limited number of thread handling this ? Could this be explained
> by
> > too many onTimeout occuring concurrently on a busy server ?
>
> Timeouts are only checked once a second.
>
That's explains this use case indeed.

>
> > I also wonder what can be done or not while in the onTimeout thread, can
> I
> > still do some asynchronous operation (retrieving content from http
> request)
> > and is writing to the reponse from this thread, as long as I ensured this
> > done in a thread safe way, ok ?
>
> This is all in the Servlet spec.
>
I'll study the spec, I spent a lot of time looking for some documentation
without thinking of reading the specs themselves, my bad.

>
> In summary:
> - You can perform any operation that is valid for a request in async mode.
>
This will have no impact on other request onTimeout triggering no matter
what I do within the onTimeout ?

> - You MUST call complete() or dispatch() before exiting onTimeout().
>
If the onTimeout occurs but another thread created by the same request is
already writing the response I assume this thread will call complete() and
the onTimeout thread must not do anything ?

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

Re: Async servlet timeout behaviour

Posted by Mark Thomas <ma...@apache.org>.
On 11/02/2016 11:07, Thomas Boniface wrote:
> Hi,
> 
> I'm using async servlet with a timeout configured to 300ms but I can
> observe in live environnement some big differences with the actual applied
> timeout  700ms or more for instance.
> 
> I was wondering how are triggered onTimeout events to AsyncListeners, is
> there a limited number of thread handling this ? Could this be explained by
> too many onTimeout occuring concurrently on a busy server ?

Timeouts are only checked once a second.

> I also wonder what can be done or not while in the onTimeout thread, can I
> still do some asynchronous operation (retrieving content from http request)
> and is writing to the reponse from this thread, as long as I ensured this
> done in a thread safe way, ok ?

This is all in the Servlet spec.

In summary:
- You can perform any operation that is valid for a request in async mode.
- You MUST call complete() or dispatch() before exiting onTimeout().

Mark


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