You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Behrang Saeedzadeh <be...@gmail.com> on 2019/12/01 02:17:34 UTC

Async file upload server has 33% less throughput compared to the sync version

Source code with Gatling tests here (WIP):
https://github.com/turingg/file-server

I wanted to compare the performance/throughput of an async file upload
servlet to a sync version. To do that, I intentionally configured Tomcat to:

* Use at most 2 HTTP connector threads
* Accept up to 1000 connections
* With a queue length of 0

<Connector port="8080"
protocol="HTTP/1.1"
asyncTimeout="30000"
connectionTimeout="30000"
acceptCount="0"
maxConnections="1000"
maxThreads="2"
minSpareThreads="2"
processorCache="1"
redirectPort="8443" />

However despite that, my async servlet (
https://github.com/turingg/file-server/blob/master/src/main/java/xyz/behrang/fileserver/b/AsyncUploadServlet.java)
has 33% less throughput compared to the sync version ((
https://github.com/turingg/file-server/blob/master/src/main/java/xyz/behrang/fileserver/a/SyncUploadServlet.java
):

# Async

---- Global Information
--------------------------------------------------------
> request count                                       5000 (OK=5000   KO=0
    )
> min response time                                    218 (OK=218    KO=-
    )
> max response time                                   2234 (OK=2234   KO=-
    )
> mean response time                                   674 (OK=674    KO=-
    )
> std deviation                                        486 (OK=486    KO=-
    )
> response time 50th percentile                        464 (OK=464    KO=-
    )
> response time 75th percentile                        773 (OK=772    KO=-
    )
> response time 95th percentile                       1890 (OK=1891   KO=-
    )
> response time 99th percentile                       2142 (OK=2142   KO=-
    )
*> mean requests/sec                                555.556 (OK=555.556
KO=-     )*
---- Response Time Distribution
------------------------------------------------
> t < 800 ms                                          3780 ( 76%)
> 800 ms < t < 1200 ms                                 525 ( 11%)
> t > 1200 ms                                          695 ( 14%)
> failed                                                 0 (  0%)
================================================================================

# Sync

================================================================================
---- Global Information
--------------------------------------------------------
> request count                                       5000 (OK=5000   KO=0
    )
> min response time                                      1 (OK=1      KO=-
    )
> max response time                                   1617 (OK=1617   KO=-
    )
> mean response time                                   207 (OK=207    KO=-
    )
> std deviation                                        333 (OK=333    KO=-
    )
> response time 50th percentile                         36 (OK=36     KO=-
    )
> response time 75th percentile                        150 (OK=150    KO=-
    )
> response time 95th percentile                        992 (OK=992    KO=-
    )
> response time 99th percentile                       1312 (OK=1312   KO=-
    )
*> mean requests/sec                                833.333 (OK=833.333
KO=-     )*
---- Response Time Distribution
------------------------------------------------
> t < 800 ms                                          4458 ( 89%)
> 800 ms < t < 1200 ms                                 479 ( 10%)
> t > 1200 ms                                           63 (  1%)
> failed                                                 0 (  0%)
================================================================================

Any ideas what am I missing here?

Thanks in advance,
Behrang

Re: Async file upload server has 33% less throughput compared to the sync version

Posted by Mark Thomas <ma...@apache.org>.
On 04/12/2019 02:23, Behrang Saeedzadeh wrote:
> I am not expecting it to take less time, but to provide better throughput.

Despite what you appear to think, you have written two synchronous,
blocking I/O upload servlets. Not one synchronous and one
non-synchronous. With synchronous I/O less time == more throughput.

> With 1000 concurrent users, the sync version was still performing better
> (mean req/second).

Entirely as expected.

An asynchronous approach is not magic pixie dust that automatically
improves performance. In some scenarios it will make performance
(throughput and time per request) worse.

Neither is writing an asynchronous upload servlet as simple as taking
all the code from your synchronous doPost() method and surrounding it with:
asyncContext.start(() -> {
    <original doPost() method code here>
});

All that does is start a separate thread to do the synchronous, blocking
I/O you had in the original method. i.e. more server side work to
achieve exactly the same result.

For an asynchronous file upload servlet to provide improved throughput:

1. It needs to use non-blocking I/O. Your doesn't.

2. The clients need to be sending data sufficiently slowly that a thread
reading the upload with blocking I/O spends a reasonable amount of time
blocking, waiting for more data to arrive. Your tests don't do that.

Mark

> 
> 
> Best regards,
> Behrang Saeedzadeh
> (Sent from my cellphone.)
> 
> On Mon, 2 Dec. 2019, 8:44 am Mark Thomas, <ma...@apache.org> wrote:
> 
>> On 01/12/2019 02:17, Behrang Saeedzadeh wrote:
>>
>> <snip/>
>>
>>> Any ideas what am I missing here?
>>
>> Async provides scalability, not raw performance.
>>
>> You haven't written a async file upload servlet. That would require
>> non-blocking I/O and look more like this:
>>
>> https://github.com/apache/tomcat/blob/master/webapps/examples/WEB-INF/classes/nonblocking/ByteCounter.java
>>
>> Step back from your code for a second. The async version does exactly
>> the same thing as the sync version apart from it does a bunch of *extra*
>> stuff (creating the Runnable and dispatching it to a different thread).
>> Why would you expect the code that does extra stuff, to take less time
>> when it does more?
>>
>> Mark
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
> 


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


Re: Async file upload server has 33% less throughput compared to the sync version

Posted by Behrang Saeedzadeh <be...@gmail.com>.
I am not expecting it to take less time, but to provide better throughput.
With 1000 concurrent users, the sync version was still performing better
(mean req/second).


Best regards,
Behrang Saeedzadeh
(Sent from my cellphone.)

On Mon, 2 Dec. 2019, 8:44 am Mark Thomas, <ma...@apache.org> wrote:

> On 01/12/2019 02:17, Behrang Saeedzadeh wrote:
>
> <snip/>
>
> > Any ideas what am I missing here?
>
> Async provides scalability, not raw performance.
>
> You haven't written a async file upload servlet. That would require
> non-blocking I/O and look more like this:
>
> https://github.com/apache/tomcat/blob/master/webapps/examples/WEB-INF/classes/nonblocking/ByteCounter.java
>
> Step back from your code for a second. The async version does exactly
> the same thing as the sync version apart from it does a bunch of *extra*
> stuff (creating the Runnable and dispatching it to a different thread).
> Why would you expect the code that does extra stuff, to take less time
> when it does more?
>
> Mark
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Async file upload server has 33% less throughput compared to the sync version

Posted by Mark Thomas <ma...@apache.org>.
On 01/12/2019 02:17, Behrang Saeedzadeh wrote:

<snip/>

> Any ideas what am I missing here?

Async provides scalability, not raw performance.

You haven't written a async file upload servlet. That would require
non-blocking I/O and look more like this:
https://github.com/apache/tomcat/blob/master/webapps/examples/WEB-INF/classes/nonblocking/ByteCounter.java

Step back from your code for a second. The async version does exactly
the same thing as the sync version apart from it does a bunch of *extra*
stuff (creating the Runnable and dispatching it to a different thread).
Why would you expect the code that does extra stuff, to take less time
when it does more?

Mark

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