[
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
[EMAIL PROTECTED]:~$ 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
[EMAIL PROTECTED]:~$ 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