Merge branch 'master' of ssh://git.eclipse.org/gitroot/jetty/org.eclipse.jetty.project

This commit is contained in:
Simone Bordet 2011-11-17 12:40:56 +01:00
commit 324f2049f3
8 changed files with 304 additions and 20 deletions

View File

@ -31,6 +31,7 @@ import org.eclipse.jetty.server.handler.RequestLogHandler;
import org.eclipse.jetty.server.handler.StatisticsHandler;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.server.ssl.SslSelectChannelConnector;
import org.eclipse.jetty.server.ssl.SslSocketConnector;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
@ -55,7 +56,7 @@ public class LikeJettyXml
// Setup Threadpool
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setMaxThreads(100);
threadPool.setMaxThreads(500);
server.setThreadPool(threadPool);
// Setup Connectors
@ -63,7 +64,7 @@ public class LikeJettyXml
connector.setPort(8080);
connector.setMaxIdleTime(30000);
connector.setConfidentialPort(8443);
connector.setStatsOn(true);
connector.setStatsOn(false);
server.setConnectors(new Connector[]
{ connector });
@ -86,11 +87,17 @@ public class LikeJettyXml
"SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA",
"SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA"
});
ssl_connector.setStatsOn(true);
ssl_connector.setStatsOn(false);
server.addConnector(ssl_connector);
ssl_connector.open();
SslSocketConnector ssl2_connector = new SslSocketConnector(cf);
ssl2_connector.setPort(8444);
ssl2_connector.setStatsOn(false);
server.addConnector(ssl2_connector);
ssl2_connector.open();
/*
Ajp13SocketConnector ajp = new Ajp13SocketConnector();

View File

@ -1,6 +1,8 @@
package org.eclipse.jetty.client;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
@ -33,11 +35,26 @@ public class Curl
client.start();
boolean async=true;
boolean dump= false;
boolean verbose= false;
final CountDownLatch latch = new CountDownLatch(args.length);
int urls=0;
for (String arg : args)
{
if (!arg.startsWith("-"))
urls++;
}
final CountDownLatch latch = new CountDownLatch(urls);
for (String arg : args)
{
if ("--verbose".equals(arg))
{
verbose=true;
continue;
}
if ("--sync".equals(arg))
{
async=false;
@ -63,6 +80,7 @@ public class Curl
}
final boolean d = dump;
final boolean v = verbose;
HttpExchange ex = new HttpExchange()
{
AtomicBoolean counted=new AtomicBoolean(false);
@ -105,7 +123,8 @@ public class Curl
super.onResponseContent(content);
if (d)
System.out.print(content.toString());
System.err.println("got "+content.length());
if (v)
System.err.println("got "+content.length());
}
/* ------------------------------------------------------------ */
@ -116,7 +135,8 @@ public class Curl
protected void onResponseHeader(Buffer name, Buffer value) throws IOException
{
super.onResponseHeader(name,value);
System.err.println(name+": "+value);
if (v)
System.err.println(name+": "+value);
}
/* ------------------------------------------------------------ */
@ -127,7 +147,8 @@ public class Curl
protected void onResponseHeaderComplete() throws IOException
{
super.onResponseHeaderComplete();
System.err.println();
if (v)
System.err.println();
}
/* ------------------------------------------------------------ */
@ -138,7 +159,8 @@ public class Curl
protected void onResponseStatus(Buffer version, int status, Buffer reason) throws IOException
{
super.onResponseStatus(version,status,reason);
System.err.println(version+" "+status+" "+reason);
if (v)
System.err.println(version+" "+status+" "+reason);
}
};

View File

@ -0,0 +1,211 @@
package org.eclipse.jetty.client;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.jetty.http.HttpMethods;
import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
/* ------------------------------------------------------------ */
/**
*/
public class Siege
{
private static final class ConcurrentExchange extends HttpExchange
{
private final long _start=System.currentTimeMillis();
private final HttpClient _client;
private final CountDownLatch _latch;
volatile int _status;
volatile int _count;
volatile long _bytes;
final List<String> _uris;
final int _repeats;
int _u;
int _r;
AtomicBoolean counted=new AtomicBoolean(false);
public ConcurrentExchange(HttpClient client,CountDownLatch latch, List<String> uris, int repeats)
{
_client = client;
_latch = latch;
_uris = uris;
_repeats = repeats;
}
@Override
protected void onConnectionFailed(Throwable ex)
{
if (!counted.getAndSet(true))
_latch.countDown();
super.onConnectionFailed(ex);
}
@Override
protected void onException(Throwable ex)
{
if (!counted.getAndSet(true))
_latch.countDown();
super.onException(ex);
}
@Override
protected void onExpire()
{
if (!counted.getAndSet(true))
_latch.countDown();
super.onExpire();
}
@Override
protected void onResponseComplete() throws IOException
{
if (_status==200)
_count++;
if (!next() && !counted.getAndSet(true))
{
_latch.countDown();
long duration=System.currentTimeMillis()-_start;
System.err.printf("Got %d/%d with %dB in %dms %d%n",_count,_uris.size()*_repeats,_bytes,duration,_latch.getCount());
}
}
/* ------------------------------------------------------------ */
@Override
protected void onResponseContent(Buffer content) throws IOException
{
_bytes+=content.length();
super.onResponseContent(content);
}
/* ------------------------------------------------------------ */
/**
* @see org.eclipse.jetty.client.HttpExchange#onResponseHeader(org.eclipse.jetty.io.Buffer, org.eclipse.jetty.io.Buffer)
*/
@Override
protected void onResponseHeader(Buffer name, Buffer value) throws IOException
{
super.onResponseHeader(name,value);
if ("Set-Cookie".equalsIgnoreCase(name.toString()))
{
String v=value.toString();
int c = v.indexOf(';');
if (c>=0)
v=v.substring(0,c);
addRequestHeader("Cookie",v);
}
}
/* ------------------------------------------------------------ */
/**
* @see org.eclipse.jetty.client.HttpExchange#onResponseHeaderComplete()
*/
@Override
protected void onResponseHeaderComplete() throws IOException
{
super.onResponseHeaderComplete();
}
/* ------------------------------------------------------------ */
/**
* @see org.eclipse.jetty.client.HttpExchange#onResponseStatus(org.eclipse.jetty.io.Buffer, int, org.eclipse.jetty.io.Buffer)
*/
@Override
protected void onResponseStatus(Buffer version, int status, Buffer reason) throws IOException
{
_status=status;
super.onResponseStatus(version,status,reason);
}
public boolean next()
{
if (_u>=_uris.size())
{
_u=0;
_r++;
if (_r>=_repeats)
return false;
}
String uri=_uris.get(_u++);
reset();
setMethod(HttpMethods.GET);
setURL(uri);
try
{
_client.send(this);
}
catch(IOException e)
{
e.printStackTrace();
return false;
}
return true;
}
}
public static void main(String[] args)
throws Exception
{
if (args.length==0)
args=new String[]
{ "-c", "2", "-r", "2", "http://localhost:8080/dump", "http://localhost:8080/d.txt"};
int concurrent=1;
int repeats=1;
final List<String> uris = new ArrayList<String>();
for (int i=0; i<args.length; i++)
{
String arg=args[i];
if ("-c".equals(arg))
{
concurrent=Integer.parseInt(args[++i]);
continue;
}
if ("-r".equals(arg))
{
repeats=Integer.parseInt(args[++i]);
continue;
}
uris.add(arg);
}
QueuedThreadPool pool = new QueuedThreadPool();
pool.setMaxThreads(500);
pool.setDaemon(true);
HttpClient client = new HttpClient();
client.setThreadPool(pool);
client.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
client.setIdleTimeout(30000);
client.setConnectTimeout(30000);
client.setMaxConnectionsPerAddress(concurrent*2);
client.start();
final CountDownLatch latch = new CountDownLatch(concurrent);
for (int i=0;i<concurrent;i++)
{
ConcurrentExchange ex = new ConcurrentExchange(client,latch,uris,repeats);
if (!ex.next())
latch.countDown();
}
latch.await();
client.stop();
pool.stop();
}
}

View File

@ -792,7 +792,7 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
o=_outbound;
u=_unwrapBuf;
}
return "SSL:"+_endp+" "+_engine.getHandshakeStatus()+" i/u/o="+(i==null?0:i.length())+"/"+(u==null?0:u.length())+"/"+(o==null?0:o.length()+(_oshut?" oshut":""));
return "SSL:"+_endp+" "+_engine.getHandshakeStatus()+" i/u/o="+(i==null?0:i.length())+"/"+(u==null?0:u.length())+"/"+(o==null?0:o.length()+(_ishut?" ishut":"")+(_oshut?" oshut":""));
}
}

View File

@ -111,14 +111,19 @@ public class AsyncHttpConnection extends AbstractHttpConnection implements Async
reset();
// TODO Is this required?
// TODO Is this still required?
if (!_generator.isPersistent() && !_endp.isOutputShutdown())
{
LOG.warn("Safety net oshut!!!");
LOG.warn("Safety net oshut!!! IF YOU SEE THIS, PLEASE RAISE BUGZILLA");
_endp.shutdownOutput();
}
}
else if (_request.getAsyncContinuation().isAsyncStarted())
{
// The request is suspended, so even though progress has been made, break the while loop
LOG.debug("suspended {}",this);
break;
}
}
}
}

View File

@ -102,6 +102,7 @@ public class BlockingHttpConnection extends AbstractHttpConnection
// Reset the parser/generator
progress=true;
reset();
_endp.flush();
// look for a switched connection instance?
if (_response.getStatus()==HttpStatus.SWITCHING_PROTOCOLS_101)
@ -114,7 +115,7 @@ public class BlockingHttpConnection extends AbstractHttpConnection
// TODO Is this required?
if (!_generator.isPersistent() && !_endp.isOutputShutdown())
{
System.err.println("Safety net oshut!!!");
LOG.warn("Safety net oshut!!! Please open a bugzilla");
_endp.shutdownOutput();
}
}

View File

@ -31,16 +31,16 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class AsyncContextTest
public class LocalAsyncContextTest
{
protected Server _server = new Server();
protected SuspendHandler _handler = new SuspendHandler();
protected LocalConnector _connector;
protected Connector _connector;
@Before
public void init() throws Exception
{
_connector = new LocalConnector();
_connector = initConnector();
_server.setConnectors(new Connector[]{ _connector });
SessionHandler session = new SessionHandler();
@ -49,6 +49,11 @@ public class AsyncContextTest
_server.setHandler(session);
_server.start();
}
protected Connector initConnector()
{
return new LocalConnector();
}
@After
public void destroy() throws Exception
@ -129,14 +134,21 @@ public class AsyncContextTest
private synchronized String process(String content) throws Exception
{
String request = "GET / HTTP/1.1\r\n" + "Host: localhost\r\n";
String request = "GET / HTTP/1.1\r\n" +
"Host: localhost\r\n"+
"Connection: close\r\n";
if (content==null)
request+="\r\n";
else
request+="Content-Length: "+content.length()+"\r\n" + "\r\n" + content;
request+="Content-Length: "+content.length()+"\r\n" +"\r\n" + content;
return _connector.getResponses(request);
return getResponse(request);
}
protected String getResponse(String request) throws Exception
{
return ((LocalConnector)_connector).getResponses(request);
}
private static class SuspendHandler extends HandlerWrapper

View File

@ -0,0 +1,26 @@
package org.eclipse.jetty.server;
import java.net.Socket;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.util.IO;
public class SelectChannelAsyncContextTest extends LocalAsyncContextTest
{
@Override
protected Connector initConnector()
{
return new SelectChannelConnector();
}
@Override
protected String getResponse(String request) throws Exception
{
SelectChannelConnector connector = (SelectChannelConnector)_connector;
Socket socket = new Socket((String)null,connector.getLocalPort());
socket.getOutputStream().write(request.getBytes("UTF-8"));
return IO.toString(socket.getInputStream());
}
}