JETTY-1269 Improve log multithreadedness

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2257 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2010-09-08 01:36:20 +00:00
parent fa9a3fab2c
commit 2149d93443
2 changed files with 77 additions and 111 deletions

View File

@ -34,6 +34,7 @@ jetty-7.2-SNAPSHOT
+ JETTY-1250 Parallel start of HandlerCollection + JETTY-1250 Parallel start of HandlerCollection
+ JETTY-1256 annotation jars from Orbit + JETTY-1256 annotation jars from Orbit
+ JETTY-1261 errant listener usage in StandardDescriptorProcessor + JETTY-1261 errant listener usage in StandardDescriptorProcessor
+ JETTY-1269 Improve log multithreadedness
+ JETTY-1271 handled unavailable exception + JETTY-1271 handled unavailable exception
+ Fix jetty-plus.xml for new configuration names + Fix jetty-plus.xml for new configuration names
+ Added ignore to Logger interface + Added ignore to Logger interface

View File

@ -68,8 +68,6 @@ public class NCSARequestLog extends AbstractLifeCycle implements RequestLog
private transient DateCache _logDateCache; private transient DateCache _logDateCache;
private transient PathMap _ignorePathMap; private transient PathMap _ignorePathMap;
private transient Writer _writer; private transient Writer _writer;
private transient ArrayList _buffers;
private transient char[] _copy;
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** /**
@ -448,9 +446,6 @@ public class NCSARequestLog extends AbstractLifeCycle implements RequestLog
*/ */
public void log(Request request, Response response) public void log(Request request, Response response)
{ {
if (!isStarted())
return;
try try
{ {
if (_ignorePathMap != null && _ignorePathMap.getMatch(request.getRequestURI()) != null) if (_ignorePathMap != null && _ignorePathMap.getMatch(request.getRequestURI()) != null)
@ -459,14 +454,7 @@ public class NCSARequestLog extends AbstractLifeCycle implements RequestLog
if (_fileOut == null) if (_fileOut == null)
return; return;
Utf8StringBuilder u8buf; StringBuilder buf= new StringBuilder(256);
StringBuilder buf;
synchronized(_writer)
{
int size=_buffers.size();
u8buf = size==0?new Utf8StringBuilder(160):(Utf8StringBuilder)_buffers.remove(size-1);
buf = u8buf.getStringBuilder();
}
if (_logServer) if (_logServer)
{ {
@ -500,9 +488,7 @@ public class NCSARequestLog extends AbstractLifeCycle implements RequestLog
buf.append("] \""); buf.append("] \"");
buf.append(request.getMethod()); buf.append(request.getMethod());
buf.append(' '); buf.append(' ');
buf.append(request.getUri().toString());
request.getUri().writeTo(u8buf);
buf.append(' '); buf.append(' ');
buf.append(request.getProtocol()); buf.append(request.getProtocol());
buf.append("\" "); buf.append("\" ");
@ -541,78 +527,58 @@ public class NCSARequestLog extends AbstractLifeCycle implements RequestLog
else else
buf.append(" - "); buf.append(" - ");
if (!_extended && !_logCookies && !_logLatency)
{
synchronized(_writer)
{
buf.append(StringUtil.__LINE_SEPARATOR);
int l=buf.length();
if (l>_copy.length)
l=_copy.length;
buf.getChars(0,l,_copy,0);
_writer.write(_copy,0,l);
_writer.flush();
u8buf.reset();
_buffers.add(u8buf);
}
}
else
{
synchronized(_writer)
{
int l=buf.length();
if (l>_copy.length)
l=_copy.length;
buf.getChars(0,l,_copy,0);
_writer.write(_copy,0,l);
u8buf.reset();
_buffers.add(u8buf);
// TODO do outside synchronized scope
if (_extended) if (_extended)
logExtended(request, response, _writer); logExtended(request, response, buf);
// TODO do outside synchronized scope
if (_logCookies) if (_logCookies)
{ {
Cookie[] cookies = request.getCookies(); Cookie[] cookies = request.getCookies();
if (cookies == null || cookies.length == 0) if (cookies == null || cookies.length == 0)
_writer.write(" -"); buf.append(" -");
else else
{ {
_writer.write(" \""); buf.append(" \"");
for (int i = 0; i < cookies.length; i++) for (int i = 0; i < cookies.length; i++)
{ {
if (i != 0) if (i != 0)
_writer.write(';'); buf.append(';');
_writer.write(cookies[i].getName()); buf.append(cookies[i].getName());
_writer.write('='); buf.append('=');
_writer.write(cookies[i].getValue()); buf.append(cookies[i].getValue());
} }
_writer.write('\"'); buf.append('\"');
} }
} }
final long now = System.currentTimeMillis(); if (_logDispatch || _logLatency)
final long start = request.getTimeStamp(); {
final long dispatch = request.getDispatchTime(); long now = System.currentTimeMillis();
if (_logDispatch) if (_logDispatch)
{ {
_writer.write(' '); long d = request.getDispatchTime();
_writer.write(Long.toString(now - (dispatch==0 ? start:dispatch))); buf.append(' ');
buf.append(now - (d==0 ? request.getTimeStamp():d));
} }
if (_logLatency) if (_logLatency)
{ {
_writer.write(' '); buf.append(' ');
_writer.write(Long.toString(now - start)); buf.append(now - request.getTimeStamp());
}
} }
_writer.write(StringUtil.__LINE_SEPARATOR); buf.append(StringUtil.__LINE_SEPARATOR);
String log = buf.toString();
synchronized(this)
{
if (_writer==null)
return;
_writer.write(log);
_writer.flush(); _writer.flush();
} }
} }
}
catch (IOException e) catch (IOException e)
{ {
Log.warn(e); Log.warn(e);
@ -626,31 +592,31 @@ public class NCSARequestLog extends AbstractLifeCycle implements RequestLog
* *
* @param request request object * @param request request object
* @param response response object * @param response response object
* @param writer log file writer * @param b StringBuilder to write to
* @throws IOException * @throws IOException
*/ */
protected void logExtended(Request request, protected void logExtended(Request request,
Response response, Response response,
Writer writer) throws IOException StringBuilder b) throws IOException
{ {
String referer = request.getHeader(HttpHeaders.REFERER); String referer = request.getHeader(HttpHeaders.REFERER);
if (referer == null) if (referer == null)
writer.write("\"-\" "); b.append("\"-\" ");
else else
{ {
writer.write('"'); b.append('"');
writer.write(referer); b.append(referer);
writer.write("\" "); b.append("\" ");
} }
String agent = request.getHeader(HttpHeaders.USER_AGENT); String agent = request.getHeader(HttpHeaders.USER_AGENT);
if (agent == null) if (agent == null)
writer.write("\"-\" "); b.append("\"-\" ");
else else
{ {
writer.write('"'); b.append('"');
writer.write(agent); b.append(agent);
writer.write('"'); b.append('"');
} }
} }
@ -690,8 +656,6 @@ public class NCSARequestLog extends AbstractLifeCycle implements RequestLog
_ignorePathMap = null; _ignorePathMap = null;
_writer = new OutputStreamWriter(_out); _writer = new OutputStreamWriter(_out);
_buffers = new ArrayList();
_copy = new char[1024];
super.doStart(); super.doStart();
} }
@ -703,6 +667,8 @@ public class NCSARequestLog extends AbstractLifeCycle implements RequestLog
*/ */
@Override @Override
protected void doStop() throws Exception protected void doStop() throws Exception
{
synchronized (this)
{ {
super.doStop(); super.doStop();
try try
@ -729,7 +695,6 @@ public class NCSARequestLog extends AbstractLifeCycle implements RequestLog
_closeOut = false; _closeOut = false;
_logDateCache = null; _logDateCache = null;
_writer = null; _writer = null;
_buffers = null; }
_copy = null;
} }
} }