You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "Oleg Kalnichevski (JIRA)" <ji...@apache.org> on 2006/07/31 14:49:16 UTC

[jira] Created: (DIRMINA-232) Performance of StreamIoHandler degrades dramatically when the IoSession is kept alive between HTTP requests

Performance of StreamIoHandler degrades dramatically when the IoSession is kept alive between HTTP requests
-----------------------------------------------------------------------------------------------------------

                 Key: DIRMINA-232
                 URL: http://issues.apache.org/jira/browse/DIRMINA-232
             Project: Directory MINA
          Issue Type: Bug
    Affects Versions: 0.9.5
         Environment: Ubuntu Linux 6.06
            Reporter: Oleg Kalnichevski


I have been observing a strange issue with MINA's StreamIoHandler while benchmarking the performance of the HTTP server based on HttpCore and MINA. The throughput of the StreamIoHandler tends to degrade dramatically when the IoSession is kept alive between HTTP requests. The problem is perfectly reproducible with a slightly modified version of HttpProtocolHandler that ships with MINA (no external code is involved).

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Re: [jira] Commented: (DIRMINA-232) Performance of StreamIoHandler degrades dramatically when the IoSession is kept alive between HTTP requests

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2006-08-01 at 19:44 +0200, Emmanuel Lecharny wrote:
> Guys, seems to me that the Naggle Algorithm hit again :)
> 
> When you reach around 25 req/s, whith an average of 40 ms per request means
> you didn't disabled it. Try to change that :
> 
> SocketAcceptorConfig acceptorCfg = new SocketAcceptorConfig();
> ...
> ((SocketSessionConfig)(acceptorCfg.getSessionConfig())).setTcpNoDelay( true
> );
> 
> I think it can change the performance *a lot* :)
> 
> (or something similar. On linux, you can type : sudo /sbin/sysctl -w
> net.ipv4.tcp_abc=0)
> 
> Emmanuel
> 

Yes, indeed. That did the trick. Thanks a bunch.

Oleg

> On 8/1/06, Niklas Therning (JIRA) <ji...@apache.org> wrote:
> >
> >     [
> > http://issues.apache.org/jira/browse/DIRMINA-232?page=comments#action_12424943]
> >
> > Niklas Therning commented on DIRMINA-232:
> > -----------------------------------------
> >
> > Hehe, just figured that out. Thanks! I see performance in line with what
> > you get:
> >
> > niklas@niklas:~$ ab2 -k -n 100 http://localhost:8080/index.html
> > This is ApacheBench, Version 2.0.41-dev <$Revision: 1.141 $> apache-2.0
> > Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd,
> > http://www.zeustech.net/
> > Copyright (c) 1998-2002 The Apache Software Foundation,
> > http://www.apache.org/
> >
> > Benchmarking localhost (be patient).....done
> >
> >
> > Server Software:        MINA
> > Server Hostname:        localhost
> > Server Port:            8080
> >
> > Document Path:          /index.html
> > Document Length:        10000 bytes
> >
> > Concurrency Level:      1
> > Time taken for tests:   3.994865 seconds
> > Complete requests:      100
> > Failed requests:        0
> > Write errors:           0
> > Keep-Alive requests:    100
> > Total transferred:      1011400 bytes
> > HTML transferred:       1000000 bytes
> > Requests per second:    25.03 [#/sec] (mean)
> > Time per request:       39.949 [ms] (mean)
> > Time per request:       39.949 [ms] (mean, across all concurrent requests)
> > Transfer rate:          247.07 [Kbytes/sec] received
> >
> > Connection Times (ms)
> >               min  mean[+/-sd] median   max
> > Connect:        0    0   0.0      0       0
> > Processing:     4   39   4.7     39      69
> > Waiting:        0    0   3.1      0      30
> > Total:          4   39   4.7     39      69
> >
> > Percentage of the requests served within a certain time (ms)
> >   50%     39
> >   66%     40
> >   75%     40
> >   80%     40
> >   90%     40
> >   95%     40
> >   98%     40
> >   99%     69
> > 100%     69 (longest request)
> >
> > So, still not anywhere near the 8571.66 Kbytes/sec you get with native
> > HttpCore. I will try to do some profiling and see if I can see what happens.
> >
> >
> > > Performance of StreamIoHandler degrades dramatically when the IoSession
> > is kept alive between HTTP requests
> > >
> > -----------------------------------------------------------------------------------------------------------
> > >
> > >                 Key: DIRMINA-232
> > >                 URL: http://issues.apache.org/jira/browse/DIRMINA-232
> > >             Project: Directory MINA
> > >          Issue Type: Bug
> > >    Affects Versions: 0.9.5
> > >         Environment: Ubuntu Linux 6.06
> > >            Reporter: Oleg Kalnichevski
> > >
> > > I have been observing a strange issue with MINA's StreamIoHandler while
> > benchmarking the performance of the HTTP server based on HttpCore and MINA.
> > The throughput of the StreamIoHandler tends to degrade dramatically when the
> > IoSession is kept alive between HTTP requests. The problem is perfectly
> > reproducible with a slightly modified version of HttpProtocolHandler that
> > ships with MINA (no external code is involved).
> >
> > --
> > This message is automatically generated by JIRA.
> > -
> > If you think it was sent incorrectly contact one of the administrators:
> > http://issues.apache.org/jira/secure/Administrators.jspa
> > -
> > For more information on JIRA, see: http://www.atlassian.com/software/jira
> >
> >
> >
> 
> 


Re: [jira] Commented: (DIRMINA-232) Performance of StreamIoHandler degrades dramatically when the IoSession is kept alive between HTTP requests

Posted by Emmanuel Lecharny <el...@gmail.com>.
Guys, seems to me that the Naggle Algorithm hit again :)

When you reach around 25 req/s, whith an average of 40 ms per request means
you didn't disabled it. Try to change that :

SocketAcceptorConfig acceptorCfg = new SocketAcceptorConfig();
...
((SocketSessionConfig)(acceptorCfg.getSessionConfig())).setTcpNoDelay( true
);

I think it can change the performance *a lot* :)

(or something similar. On linux, you can type : sudo /sbin/sysctl -w
net.ipv4.tcp_abc=0)

Emmanuel

On 8/1/06, Niklas Therning (JIRA) <ji...@apache.org> wrote:
>
>     [
> http://issues.apache.org/jira/browse/DIRMINA-232?page=comments#action_12424943]
>
> Niklas Therning commented on DIRMINA-232:
> -----------------------------------------
>
> Hehe, just figured that out. Thanks! I see performance in line with what
> you get:
>
> niklas@niklas:~$ ab2 -k -n 100 http://localhost:8080/index.html
> This is ApacheBench, Version 2.0.41-dev <$Revision: 1.141 $> apache-2.0
> Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd,
> http://www.zeustech.net/
> Copyright (c) 1998-2002 The Apache Software Foundation,
> http://www.apache.org/
>
> Benchmarking localhost (be patient).....done
>
>
> Server Software:        MINA
> Server Hostname:        localhost
> Server Port:            8080
>
> Document Path:          /index.html
> Document Length:        10000 bytes
>
> Concurrency Level:      1
> Time taken for tests:   3.994865 seconds
> Complete requests:      100
> Failed requests:        0
> Write errors:           0
> Keep-Alive requests:    100
> Total transferred:      1011400 bytes
> HTML transferred:       1000000 bytes
> Requests per second:    25.03 [#/sec] (mean)
> Time per request:       39.949 [ms] (mean)
> Time per request:       39.949 [ms] (mean, across all concurrent requests)
> Transfer rate:          247.07 [Kbytes/sec] received
>
> Connection Times (ms)
>               min  mean[+/-sd] median   max
> Connect:        0    0   0.0      0       0
> Processing:     4   39   4.7     39      69
> Waiting:        0    0   3.1      0      30
> Total:          4   39   4.7     39      69
>
> Percentage of the requests served within a certain time (ms)
>   50%     39
>   66%     40
>   75%     40
>   80%     40
>   90%     40
>   95%     40
>   98%     40
>   99%     69
> 100%     69 (longest request)
>
> So, still not anywhere near the 8571.66 Kbytes/sec you get with native
> HttpCore. I will try to do some profiling and see if I can see what happens.
>
>
> > Performance of StreamIoHandler degrades dramatically when the IoSession
> is kept alive between HTTP requests
> >
> -----------------------------------------------------------------------------------------------------------
> >
> >                 Key: DIRMINA-232
> >                 URL: http://issues.apache.org/jira/browse/DIRMINA-232
> >             Project: Directory MINA
> >          Issue Type: Bug
> >    Affects Versions: 0.9.5
> >         Environment: Ubuntu Linux 6.06
> >            Reporter: Oleg Kalnichevski
> >
> > I have been observing a strange issue with MINA's StreamIoHandler while
> benchmarking the performance of the HTTP server based on HttpCore and MINA.
> The throughput of the StreamIoHandler tends to degrade dramatically when the
> IoSession is kept alive between HTTP requests. The problem is perfectly
> reproducible with a slightly modified version of HttpProtocolHandler that
> ships with MINA (no external code is involved).
>
> --
> This message is automatically generated by JIRA.
> -
> If you think it was sent incorrectly contact one of the administrators:
> http://issues.apache.org/jira/secure/Administrators.jspa
> -
> For more information on JIRA, see: http://www.atlassian.com/software/jira
>
>
>


-- 
Cordialement,
Emmanuel Lécharny

[jira] Resolved: (DIRMINA-232) Performance of StreamIoHandler degrades dramatically when the IoSession is kept alive between HTTP requests

Posted by "Niklas Therning (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/DIRMINA-232?page=all ]

Niklas Therning resolved DIRMINA-232.
-------------------------------------

    Resolution: Invalid

This is due to tcpNoDelay not being true by default. Oleg, please close this issue.

> Performance of StreamIoHandler degrades dramatically when the IoSession is kept alive between HTTP requests
> -----------------------------------------------------------------------------------------------------------
>
>                 Key: DIRMINA-232
>                 URL: http://issues.apache.org/jira/browse/DIRMINA-232
>             Project: Directory MINA
>          Issue Type: Bug
>    Affects Versions: 0.9.5
>         Environment: Ubuntu Linux 6.06
>            Reporter: Oleg Kalnichevski
>
> I have been observing a strange issue with MINA's StreamIoHandler while benchmarking the performance of the HTTP server based on HttpCore and MINA. The throughput of the StreamIoHandler tends to degrade dramatically when the IoSession is kept alive between HTTP requests. The problem is perfectly reproducible with a slightly modified version of HttpProtocolHandler that ships with MINA (no external code is involved).

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (DIRMINA-232) Performance of StreamIoHandler degrades dramatically when the IoSession is kept alive between HTTP requests

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/DIRMINA-232?page=comments#action_12424952 ] 
            
Oleg Kalnichevski commented on DIRMINA-232:
-------------------------------------------

Please close this one as invalid. I was not aware of that fact that setTcpNoDelay was not set to true per default. My bad.

Oleg

> Performance of StreamIoHandler degrades dramatically when the IoSession is kept alive between HTTP requests
> -----------------------------------------------------------------------------------------------------------
>
>                 Key: DIRMINA-232
>                 URL: http://issues.apache.org/jira/browse/DIRMINA-232
>             Project: Directory MINA
>          Issue Type: Bug
>    Affects Versions: 0.9.5
>         Environment: Ubuntu Linux 6.06
>            Reporter: Oleg Kalnichevski
>
> I have been observing a strange issue with MINA's StreamIoHandler while benchmarking the performance of the HTTP server based on HttpCore and MINA. The throughput of the StreamIoHandler tends to degrade dramatically when the IoSession is kept alive between HTTP requests. The problem is perfectly reproducible with a slightly modified version of HttpProtocolHandler that ships with MINA (no external code is involved).

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (DIRMINA-232) Performance of StreamIoHandler degrades dramatically when the IoSession is kept alive between HTTP requests

Posted by "Niklas Therning (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/DIRMINA-232?page=comments#action_12424943 ] 
            
Niklas Therning commented on DIRMINA-232:
-----------------------------------------

Hehe, just figured that out. Thanks! I see performance in line with what you get:

niklas@niklas:~$ ab2 -k -n 100 http://localhost:8080/index.html
This is ApacheBench, Version 2.0.41-dev <$Revision: 1.141 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient).....done


Server Software:        MINA
Server Hostname:        localhost
Server Port:            8080

Document Path:          /index.html
Document Length:        10000 bytes

Concurrency Level:      1
Time taken for tests:   3.994865 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Keep-Alive requests:    100
Total transferred:      1011400 bytes
HTML transferred:       1000000 bytes
Requests per second:    25.03 [#/sec] (mean)
Time per request:       39.949 [ms] (mean)
Time per request:       39.949 [ms] (mean, across all concurrent requests)
Transfer rate:          247.07 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     4   39   4.7     39      69
Waiting:        0    0   3.1      0      30
Total:          4   39   4.7     39      69

Percentage of the requests served within a certain time (ms)
  50%     39
  66%     40
  75%     40
  80%     40
  90%     40
  95%     40
  98%     40
  99%     69
 100%     69 (longest request)

So, still not anywhere near the 8571.66 Kbytes/sec you get with native HttpCore. I will try to do some profiling and see if I can see what happens.


> Performance of StreamIoHandler degrades dramatically when the IoSession is kept alive between HTTP requests
> -----------------------------------------------------------------------------------------------------------
>
>                 Key: DIRMINA-232
>                 URL: http://issues.apache.org/jira/browse/DIRMINA-232
>             Project: Directory MINA
>          Issue Type: Bug
>    Affects Versions: 0.9.5
>         Environment: Ubuntu Linux 6.06
>            Reporter: Oleg Kalnichevski
>
> I have been observing a strange issue with MINA's StreamIoHandler while benchmarking the performance of the HTTP server based on HttpCore and MINA. The throughput of the StreamIoHandler tends to degrade dramatically when the IoSession is kept alive between HTTP requests. The problem is perfectly reproducible with a slightly modified version of HttpProtocolHandler that ships with MINA (no external code is involved).

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (DIRMINA-232) Performance of StreamIoHandler degrades dramatically when the IoSession is kept alive between HTTP requests

Posted by "Niklas Therning (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/DIRMINA-232?page=comments#action_12424953 ] 
            
Niklas Therning commented on DIRMINA-232:
-----------------------------------------

Emmanuel suggested that the poor performance might be due to nagle which I indeed think is the case. Here's the result with nagle disabled:

niklas@niklas:~$ ab2 -k -n 100 http://localhost:8080/index.html
This is ApacheBench, Version 2.0.41-dev <$Revision: 1.141 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient).....done


Server Software:        MINA
Server Hostname:        localhost
Server Port:            8080

Document Path:          /index.html
Document Length:        10000 bytes

Concurrency Level:      1
Time taken for tests:   0.107275 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Keep-Alive requests:    100
Total transferred:      1011400 bytes
HTML transferred:       1000000 bytes
Requests per second:    932.18 [#/sec] (mean)
Time per request:       1.073 [ms] (mean)
Time per request:       1.073 [ms] (mean, across all concurrent requests)
Transfer rate:          9200.65 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     0    0   3.3      0      32
Waiting:        0    0   3.3      0      32
Total:          0    0   3.3      0      32

Percentage of the requests served within a certain time (ms)
  50%      0
  66%      0
  75%      0
  80%      0
  90%      0
  95%      1
  98%      6
  99%     32
 100%     32 (longest request)

Add the following to Main.java before the bind call to disable nagle:

( ( SocketSessionConfig ) ( config.getSessionConfig() ) ).setTcpNoDelay( true ); 

Thanks Emmanuel for pointing this out!

What do you think Oleg, can we close this issue?

> Performance of StreamIoHandler degrades dramatically when the IoSession is kept alive between HTTP requests
> -----------------------------------------------------------------------------------------------------------
>
>                 Key: DIRMINA-232
>                 URL: http://issues.apache.org/jira/browse/DIRMINA-232
>             Project: Directory MINA
>          Issue Type: Bug
>    Affects Versions: 0.9.5
>         Environment: Ubuntu Linux 6.06
>            Reporter: Oleg Kalnichevski
>
> I have been observing a strange issue with MINA's StreamIoHandler while benchmarking the performance of the HTTP server based on HttpCore and MINA. The throughput of the StreamIoHandler tends to degrade dramatically when the IoSession is kept alive between HTTP requests. The problem is perfectly reproducible with a slightly modified version of HttpProtocolHandler that ships with MINA (no external code is involved).

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Closed: (DIRMINA-232) Performance of StreamIoHandler degrades dramatically when the IoSession is kept alive between HTTP requests

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/DIRMINA-232?page=all ]

Oleg Kalnichevski closed DIRMINA-232.
-------------------------------------


> Performance of StreamIoHandler degrades dramatically when the IoSession is kept alive between HTTP requests
> -----------------------------------------------------------------------------------------------------------
>
>                 Key: DIRMINA-232
>                 URL: http://issues.apache.org/jira/browse/DIRMINA-232
>             Project: Directory MINA
>          Issue Type: Bug
>    Affects Versions: 0.9.5
>         Environment: Ubuntu Linux 6.06
>            Reporter: Oleg Kalnichevski
>
> I have been observing a strange issue with MINA's StreamIoHandler while benchmarking the performance of the HTTP server based on HttpCore and MINA. The throughput of the StreamIoHandler tends to degrade dramatically when the IoSession is kept alive between HTTP requests. The problem is perfectly reproducible with a slightly modified version of HttpProtocolHandler that ships with MINA (no external code is involved).

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (DIRMINA-232) Performance of StreamIoHandler degrades dramatically when the IoSession is kept alive between HTTP requests

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/DIRMINA-232?page=comments#action_12424939 ] 
            
Oleg Kalnichevski commented on DIRMINA-232:
-------------------------------------------

Niklas,
Most likely you need to apply this patch first

http://issues.apache.org/jira/browse/DIRMINA-229

Oleg

> Performance of StreamIoHandler degrades dramatically when the IoSession is kept alive between HTTP requests
> -----------------------------------------------------------------------------------------------------------
>
>                 Key: DIRMINA-232
>                 URL: http://issues.apache.org/jira/browse/DIRMINA-232
>             Project: Directory MINA
>          Issue Type: Bug
>    Affects Versions: 0.9.5
>         Environment: Ubuntu Linux 6.06
>            Reporter: Oleg Kalnichevski
>
> I have been observing a strange issue with MINA's StreamIoHandler while benchmarking the performance of the HTTP server based on HttpCore and MINA. The throughput of the StreamIoHandler tends to degrade dramatically when the IoSession is kept alive between HTTP requests. The problem is perfectly reproducible with a slightly modified version of HttpProtocolHandler that ships with MINA (no external code is involved).

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (DIRMINA-232) Performance of StreamIoHandler degrades dramatically when the IoSession is kept alive between HTTP requests

Posted by "Niklas Therning (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/DIRMINA-232?page=comments#action_12424919 ] 
            
Niklas Therning commented on DIRMINA-232:
-----------------------------------------

I tried to run ab2 with the modified version of HttpProtocolHandler you posted above and I can't even get ab2 to finish:

niklas@niklas:~$ ab2 -k -n 100 http://localhost:8080/index.html
This is ApacheBench, Version 2.0.41-dev <$Revision: 1.141 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)...
Test aborted after 10 failures


Total of 5 requests completed

As you can see I'm using the exact same version of ab2 as you (I'm on Ubuntu 6.06 too).

When telnetting to port 8080 it seems like I sometimes get partial responses and responses missing the headers. Are you using the svn version (that's what I'm using) of MINA or 0.9.4? Have you made any changes to Main.java for the httpserver example?

> Performance of StreamIoHandler degrades dramatically when the IoSession is kept alive between HTTP requests
> -----------------------------------------------------------------------------------------------------------
>
>                 Key: DIRMINA-232
>                 URL: http://issues.apache.org/jira/browse/DIRMINA-232
>             Project: Directory MINA
>          Issue Type: Bug
>    Affects Versions: 0.9.5
>         Environment: Ubuntu Linux 6.06
>            Reporter: Oleg Kalnichevski
>
> I have been observing a strange issue with MINA's StreamIoHandler while benchmarking the performance of the HTTP server based on HttpCore and MINA. The throughput of the StreamIoHandler tends to degrade dramatically when the IoSession is kept alive between HTTP requests. The problem is perfectly reproducible with a slightly modified version of HttpProtocolHandler that ships with MINA (no external code is involved).

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (DIRMINA-232) Performance of StreamIoHandler degrades dramatically when the IoSession is kept alive between HTTP requests

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/DIRMINA-232?page=comments#action_12424526 ] 
            
Oleg Kalnichevski commented on DIRMINA-232:
-------------------------------------------

public class HttpProtocolHandler extends StreamIoHandler
{
    protected void processStreamIo( IoSession session, InputStream in,
                                    OutputStream out )
    {
        // You *MUST* execute stream I/O logic in a separate thread.
        new Worker( in, out ).start();
    }
    
    private static class Worker extends Thread
    {
        private final InputStream in;
        private final OutputStream out;
        
        public Worker( InputStream in, OutputStream out )
        {
            setDaemon( true );
            this.in = in;
            this.out = out;
        }
        
        public void run()
        {
            BufferedReader in = new BufferedReader(
                    new InputStreamReader( this.in ) );
            PrintWriter out = new PrintWriter(
                    new BufferedWriter( new OutputStreamWriter( this.out ) ) );
            
            try
            {
                while (true) {
                    in.readLine().split( " " );
                    Map headers = new TreeMap();
                    
                    // Read header
                    String line;
                    while ( ( line = in.readLine() ) != null && !line.equals( "" ) )
                    {
                        String[] tokens = line.split(": ");
                        headers.put( tokens[0], tokens[1] );
                    }
                    
                    // Write header
                    out.println( "HTTP/1.0 200 OK" );
                    out.println( "Content-Type: text/plain" );
                    out.println( "Server: MINA Example" );
                    out.println( "Content-Length: 10000" );
                    out.println( "Connection: Keep-Alive" );
                    out.println();
                    
                    char[] tmp = new char[1000];
                    for (int i = 0; i < 10; i++) {
                        out.write(tmp);
                    }
                    out.flush();
                }
                
            }
            catch( Exception e )
            {
                e.printStackTrace();
            }
            finally
            {
                out.flush();
                out.close();
                try
                {
                    in.close();
                }
                catch( IOException e )
                {
                }
            }
        }
    }
}

These are the benchmark results

oleg@dld810:~$ ab2 -k -n 100  http://localhost:8080/index.html
This is ApacheBench, Version 2.0.41-dev <$Revision: 1.141 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient).....done


Server Software:        MINA
Server Hostname:        localhost
Server Port:            8080

Document Path:          /index.html
Document Length:        10000 bytes

Concurrency Level:      1
Time taken for tests:   6.558238 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Keep-Alive requests:    100
Total transferred:      1010800 bytes
HTML transferred:       1000000 bytes
Requests per second:    15.25 [#/sec] (mean)
Time per request:       65.582 [ms] (mean)
Time per request:       65.582 [ms] (mean, across all concurrent requests)
Transfer rate:          150.50 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:    38   65  24.1     53     111
Waiting:        0    1   8.3      1      83
Total:         38   65  24.1     53     111

Transfer rate of 150.50 [Kbytes/sec] is enormously low. For instance, the native HttpCore I/O layer easily achieves that of 8571.66 Kbytes/sec

oleg@dld810:~$ ab2 -k -n 100  http://localhost:8080/index.html
This is ApacheBench, Version 2.0.41-dev <$Revision: 1.141 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient).....done


Server Software:        Jakarta-HttpComponents/1.1
Server Hostname:        localhost
Server Port:            8080

Document Path:          /index.html
Document Length:        12928 bytes

Concurrency Level:      1
Time taken for tests:   0.149096 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Keep-Alive requests:    100
Total transferred:      1309200 bytes
HTML transferred:       1292800 bytes
Requests per second:    670.71 [#/sec] (mean)
Time per request:       1.491 [ms] (mean)
Time per request:       1.491 [ms] (mean, across all concurrent requests)
Transfer rate:          8571.66 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     0    1   9.5      0      95
Waiting:        0    1   9.4      0      94
Total:          0    1   9.5      0      95

It is quite imaginable I am doing something silly, but as the problem appears reproducible using MINA's own sample code, this may not be the case. 

I will be trying to pinpoint the problem myself, but I would appreciate some pointers or a helping hand from some one more knowledgeable about MINA's inner working.

Oleg


> Performance of StreamIoHandler degrades dramatically when the IoSession is kept alive between HTTP requests
> -----------------------------------------------------------------------------------------------------------
>
>                 Key: DIRMINA-232
>                 URL: http://issues.apache.org/jira/browse/DIRMINA-232
>             Project: Directory MINA
>          Issue Type: Bug
>    Affects Versions: 0.9.5
>         Environment: Ubuntu Linux 6.06
>            Reporter: Oleg Kalnichevski
>
> I have been observing a strange issue with MINA's StreamIoHandler while benchmarking the performance of the HTTP server based on HttpCore and MINA. The throughput of the StreamIoHandler tends to degrade dramatically when the IoSession is kept alive between HTTP requests. The problem is perfectly reproducible with a slightly modified version of HttpProtocolHandler that ships with MINA (no external code is involved).

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira