Merge remote-tracking branch 'origin/jetty-8'

Conflicts:
	examples/embedded/src/main/java/org/eclipse/jetty/embedded/SpdyServer.java
	jetty-client/src/test/java/org/eclipse/jetty/client/HttpExchangeTest.java
	jetty-io/src/test/java/org/eclipse/jetty/io/ThreadLocalBuffersTest.java
	jetty-server/src/main/config/etc/jetty-requestlog.xml
	jetty-server/src/test/java/org/eclipse/jetty/server/AsyncStressTest.java
	jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestFixture.java
	jetty-server/src/test/java/org/eclipse/jetty/server/StressTest.java
	jetty-servlets/pom.xml
This commit is contained in:
Greg Wilkins 2013-03-18 11:09:13 +11:00
commit e8d76ef12c
12 changed files with 202 additions and 40 deletions

View File

@ -25,6 +25,7 @@ import org.eclipse.jetty.deploy.providers.WebAppProvider;
import org.eclipse.jetty.jmx.MBeanContainer;
import org.eclipse.jetty.security.HashLoginService;
import org.eclipse.jetty.server.ForwardedRequestCustomizer;
import org.eclipse.jetty.server.AsyncNCSARequestLog;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
@ -152,7 +153,8 @@ public class SpdyServer
login.setConfig(jetty_home + "/etc/realm.properties");
server.addBean(login);
NCSARequestLog requestLog = new NCSARequestLog(jetty_home + "/logs/jetty-yyyy_mm_dd.log");
NCSARequestLog requestLog = new AsyncNCSARequestLog();
requestLog.setFilename(jetty_home + "/logs/jetty-yyyy_mm_dd.log");
requestLog.setExtended(false);
requestLogHandler.setRequestLog(requestLog);

View File

@ -478,6 +478,7 @@ case "$ACTION" in
echo "OK `date`"
else
echo "FAILED `date`"
exit 1
fi
;;

View File

@ -14,6 +14,7 @@
<Arg>
<New id="RequestLog" class="org.eclipse.jetty.server.handler.RequestLogHandler">
<Set name="requestLog">
<!-- Use AsyncNCSARequestLog for improved request latency -->
<New id="RequestLogImpl" class="org.eclipse.jetty.server.NCSARequestLog">
<Set name="filename"><Property name="jetty.logs" default="./logs" />/yyyy_mm_dd.request.log</Set>
<Set name="filenameDateFormat">yyyy_MM_dd</Set>

View File

@ -0,0 +1,130 @@
//
// ========================================================================
// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.server;
import org.eclipse.jetty.util.BlockingArrayQueue;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import java.io.IOException;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
/* ------------------------------------------------------------ */
/**
* An asynchronously writing NCSA Request Log
*/
public class AsyncNCSARequestLog extends NCSARequestLog
{
private static final Logger LOG = Log.getLogger(AsyncNCSARequestLog.class);
private final BlockingQueue<String> _queue;
private transient WriterThread _thread;
private boolean _warnedFull;
public AsyncNCSARequestLog()
{
this(null,null);
}
public AsyncNCSARequestLog(BlockingQueue<String> queue)
{
this(null,queue);
}
public AsyncNCSARequestLog(String filename)
{
this(filename,null);
}
public AsyncNCSARequestLog(String filename,BlockingQueue<String> queue)
{
super(filename);
if (queue==null)
queue=new BlockingArrayQueue<String>(1024);
_queue=queue;
}
private class WriterThread extends Thread
{
WriterThread()
{
setName("AsyncNCSARequestLog@"+Integer.toString(AsyncNCSARequestLog.this.hashCode(),16));
}
@Override
public void run()
{
while (isRunning())
{
try
{
String log = _queue.poll(10,TimeUnit.SECONDS);
if (log!=null)
AsyncNCSARequestLog.super.write(log);
while(!_queue.isEmpty())
{
log=_queue.poll();
if (log!=null)
AsyncNCSARequestLog.super.write(log);
}
}
catch (IOException e)
{
LOG.warn(e);
}
catch (InterruptedException e)
{
LOG.ignore(e);
}
}
}
}
@Override
protected synchronized void doStart() throws Exception
{
super.doStart();
_thread = new WriterThread();
_thread.start();
}
@Override
protected void doStop() throws Exception
{
_thread.interrupt();
_thread.join();
super.doStop();
_thread=null;
}
@Override
protected void write(String log) throws IOException
{
if (!_queue.offer(log))
{
if (_warnedFull)
LOG.warn("Log Queue overflow");
_warnedFull=true;
}
}
}

View File

@ -55,6 +55,14 @@ import org.eclipse.jetty.util.log.Logger;
public class NCSARequestLog extends AbstractLifeCycle implements RequestLog
{
private static final Logger LOG = Log.getLogger(NCSARequestLog.class);
private static ThreadLocal<StringBuilder> _buffers = new ThreadLocal<StringBuilder>()
{
@Override
protected StringBuilder initialValue()
{
return new StringBuilder(256);
}
};
private String _filename;
private boolean _extended;
@ -468,7 +476,8 @@ public class NCSARequestLog extends AbstractLifeCycle implements RequestLog
if (_fileOut == null)
return;
StringBuilder buf= new StringBuilder(256);
StringBuilder buf= _buffers.get();
buf.setLength(0);
if (_logServer)
{
@ -584,22 +593,29 @@ public class NCSARequestLog extends AbstractLifeCycle implements RequestLog
}
buf.append(StringUtil.__LINE_SEPARATOR);
String log = buf.toString();
synchronized(this)
{
if (_writer==null)
return;
_writer.write(log);
_writer.flush();
}
write(log);
}
catch (IOException e)
{
LOG.warn(e);
}
}
/* ------------------------------------------------------------ */
protected void write(String log) throws IOException
{
synchronized(this)
{
if (_writer==null)
return;
_writer.write(log);
_writer.flush();
}
}
/* ------------------------------------------------------------ */
/**
* Writes extended request and response information to the output stream.
@ -669,7 +685,10 @@ public class NCSARequestLog extends AbstractLifeCycle implements RequestLog
else
_ignorePathMap = null;
_writer = new OutputStreamWriter(_out);
synchronized(this)
{
_writer = new OutputStreamWriter(_out);
}
super.doStart();
}

View File

@ -280,10 +280,12 @@ public class Server extends HandlerWrapper implements Attributes
@Override
protected void doStart() throws Exception
{
if (getStopAtShutdown()) {
ShutdownThread.register(this);
ShutdownMonitor.getInstance().start(); // initialize
if (getStopAtShutdown())
{
ShutdownThread.register(this);
}
ShutdownMonitor.getInstance().start(); // initialize
LOG.info("jetty-"+getVersion());
HttpGenerator.setServerVersion(getVersion());

View File

@ -75,7 +75,7 @@ public class ShutdownMonitor extends Thread
// Use values passed thru via /jetty-start/
this.port = Integer.parseInt(props.getProperty("STOP.PORT","-1"));
this.key = props.getProperty("STOP.KEY","eclipse");
this.key = props.getProperty("STOP.KEY",null);
this.exitVm = true;
}

View File

@ -18,7 +18,7 @@
package org.eclipse.jetty.server;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
import java.io.IOException;
import java.io.InputStream;
@ -39,6 +39,7 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.handler.HandlerWrapper;
import org.eclipse.jetty.toolchain.test.AdvancedRunner;
import org.eclipse.jetty.toolchain.test.annotation.Stress;
import org.eclipse.jetty.toolchain.test.PropertyFlag;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@ -95,7 +96,14 @@ public class AsyncStressTest
@Stress("High connection count")
public void testAsync() throws Throwable
{
doConnections(1600,240);
if (PropertyFlag.isEnabled("test.stress"))
{
doConnections(1600,240);
}
else
{
doConnections(80,80);
}
}
private void doConnections(int connections,final int loops) throws Throwable

View File

@ -35,6 +35,7 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.handler.HandlerWrapper;
import org.eclipse.jetty.toolchain.test.PropertyFlag;
import org.eclipse.jetty.util.IO;
import org.junit.After;
import org.junit.Before;
@ -42,7 +43,7 @@ import org.junit.Before;
public class HttpServerTestFixture
{ // Useful constants
protected static final long PAUSE=10L;
protected static final int LOOPS=50;
protected static final int LOOPS=PropertyFlag.isEnabled("test.stress")?250:50;
protected Server _server;
protected URI _serverURI;

View File

@ -37,6 +37,7 @@ import org.eclipse.jetty.server.handler.HandlerWrapper;
import org.eclipse.jetty.toolchain.test.AdvancedRunner;
import org.eclipse.jetty.toolchain.test.OS;
import org.eclipse.jetty.toolchain.test.annotation.Stress;
import org.eclipse.jetty.toolchain.test.PropertyFlag;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@ -130,35 +131,37 @@ public class StressTest
}
@Test
@Stress("Much threading")
public void testNonPersistent() throws Throwable
{
// TODO needs to be further investigated
assumeTrue(!OS.IS_OSX);
assumeTrue(!OS.IS_OSX || PropertyFlag.isEnabled("test.stress"));
doThreads(10,10,false);
Thread.sleep(1000);
doThreads(20,20,false);
Thread.sleep(1000);
doThreads(200,10,false);
Thread.sleep(1000);
doThreads(200,200,false);
if (PropertyFlag.isEnabled("test.stress"))
{
doThreads(20,20,false);
Thread.sleep(1000);
doThreads(200,10,false);
Thread.sleep(1000);
doThreads(200,200,false);
}
}
@Test
@Stress("Much threading")
public void testPersistent() throws Throwable
{
// TODO needs to be further investigated
assumeTrue(!OS.IS_OSX);
assumeTrue(!OS.IS_OSX || PropertyFlag.isEnabled("test.stress"));
doThreads(10,10,true);
Thread.sleep(1000);
doThreads(40,40,true);
Thread.sleep(1000);
doThreads(200,10,true);
Thread.sleep(1000);
doThreads(200,200,true);
if (PropertyFlag.isEnabled("test.stress"))
{
doThreads(40,40,true);
Thread.sleep(1000);
doThreads(200,10,true);
Thread.sleep(1000);
doThreads(200,200,true);
}
}
private void doThreads(int threadCount, final int loops, final boolean persistent) throws Throwable

View File

@ -53,31 +53,26 @@ public class FileNoticeLifeCycleListener implements LifeCycle.Listener
}
}
@Override
public void lifeCycleStarting(LifeCycle event)
{
writeState("STARTING",event);
}
@Override
public void lifeCycleStarted(LifeCycle event)
{
writeState("STARTED",event);
}
@Override
public void lifeCycleFailure(LifeCycle event, Throwable cause)
{
writeState("FAILED",event);
}
@Override
public void lifeCycleStopping(LifeCycle event)
{
writeState("STOPPING",event);
}
@Override
public void lifeCycleStopped(LifeCycle event)
{
writeState("STOPPED",event);

View File

@ -265,7 +265,7 @@
<plugin>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-version-maven-plugin</artifactId>
<version>1.0.9</version>
<version>1.0.10</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>