HTTPCLIENT-895: Log object lookups by short lived components impair performance

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@885900 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2009-12-01 20:01:44 +00:00
parent 900c9c0966
commit 9f580578d9
4 changed files with 21 additions and 11 deletions

View File

@ -15,6 +15,9 @@ functionality improvements and new features.
encoding is not enabled per default in order to avoid conflicts with encoding is not enabled per default in order to avoid conflicts with
already existing custom content encoding solutions. already existing custom content encoding solutions.
* 5 to 10% performance increase due to elimination of unnecessary Log object
lookups by short-lived components.
Please note all methods and classes added in this release and marked as Please note all methods and classes added in this release and marked as
4.1 are API unstable and can change in the future 4.1 ALPHA releases. 4.1 are API unstable and can change in the future 4.1 ALPHA releases.
@ -69,9 +72,16 @@ This is a bug fix release that addresses a number of issues discovered since
the previous stable release. None of the fixed bugs is considered critical. the previous stable release. None of the fixed bugs is considered critical.
Most notably this release eliminates eliminates dependency on JCIP annotations. Most notably this release eliminates eliminates dependency on JCIP annotations.
This release is also expected to improve performance by 5 to 10% due to
elimination of unnecessary Log object lookups by short-lived components.
Changelog Changelog
------------------- -------------------
* [HTTPCLIENT-895] Eliminated Log lookups in short lived objects impairing
performance.
Contributed by Oleg Kalnichevski <olegk at apache.org>
* [HTTPCLIENT-885] URLEncodedUtils now correctly parses form-url-encoded * [HTTPCLIENT-885] URLEncodedUtils now correctly parses form-url-encoded
entities that specify a charset. entities that specify a charset.
Contributed by Oleg Kalnichevski <olegk at apache.org> Contributed by Oleg Kalnichevski <olegk at apache.org>

View File

@ -738,6 +738,7 @@ public abstract class AbstractHttpClient implements HttpClient {
final UserTokenHandler stateHandler, final UserTokenHandler stateHandler,
final HttpParams params) { final HttpParams params) {
return new DefaultRequestDirector( return new DefaultRequestDirector(
log,
requestExec, requestExec,
conman, conman,
reustrat, reustrat,

View File

@ -29,8 +29,6 @@ package org.apache.http.impl.client;
import org.apache.http.annotation.NotThreadSafe; import org.apache.http.annotation.NotThreadSafe;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.params.HttpParams; import org.apache.http.params.HttpParams;
import org.apache.http.params.AbstractHttpParams; import org.apache.http.params.AbstractHttpParams;
@ -73,8 +71,6 @@ import org.apache.http.params.AbstractHttpParams;
@NotThreadSafe @NotThreadSafe
public class ClientParamsStack extends AbstractHttpParams { public class ClientParamsStack extends AbstractHttpParams {
private final Log log = LogFactory.getLog(getClass());
/** The application parameter collection, or <code>null</code>. */ /** The application parameter collection, or <code>null</code>. */
protected final HttpParams applicationParams; protected final HttpParams applicationParams;
@ -211,10 +207,6 @@ public class ClientParamsStack extends AbstractHttpParams {
if ((result == null) && (applicationParams != null)) { if ((result == null) && (applicationParams != null)) {
result = applicationParams.getParameter(name); result = applicationParams.getParameter(name);
} }
if (this.log.isDebugEnabled() && result != null) {
this.log.debug("'" + name + "': " + result);
}
return result; return result;
} }

View File

@ -135,7 +135,7 @@ import org.apache.http.protocol.HttpRequestExecutor;
@NotThreadSafe // e.g. managedConn @NotThreadSafe // e.g. managedConn
public class DefaultRequestDirector implements RequestDirector { public class DefaultRequestDirector implements RequestDirector {
private final Log log = LogFactory.getLog(getClass()); private final Log log;
/** The connection manager. */ /** The connection manager. */
protected final ClientConnectionManager connManager; protected final ClientConnectionManager connManager;
@ -204,7 +204,8 @@ public class DefaultRequestDirector implements RequestDirector {
final AuthenticationHandler proxyAuthHandler, final AuthenticationHandler proxyAuthHandler,
final UserTokenHandler userTokenHandler, final UserTokenHandler userTokenHandler,
final HttpParams params) { final HttpParams params) {
this(requestExec, conman, reustrat, kastrat, rouplan, httpProcessor, retryHandler, this(LogFactory.getLog(DefaultRequestDirector.class),
requestExec, conman, reustrat, kastrat, rouplan, httpProcessor, retryHandler,
new DefaultRedirectStrategyAdaptor(redirectHandler), new DefaultRedirectStrategyAdaptor(redirectHandler),
targetAuthHandler, proxyAuthHandler, userTokenHandler, params); targetAuthHandler, proxyAuthHandler, userTokenHandler, params);
} }
@ -214,6 +215,7 @@ public class DefaultRequestDirector implements RequestDirector {
* @since 4.1 * @since 4.1
*/ */
public DefaultRequestDirector( public DefaultRequestDirector(
final Log log,
final HttpRequestExecutor requestExec, final HttpRequestExecutor requestExec,
final ClientConnectionManager conman, final ClientConnectionManager conman,
final ConnectionReuseStrategy reustrat, final ConnectionReuseStrategy reustrat,
@ -227,6 +229,10 @@ public class DefaultRequestDirector implements RequestDirector {
final UserTokenHandler userTokenHandler, final UserTokenHandler userTokenHandler,
final HttpParams params) { final HttpParams params) {
if (log == null) {
throw new IllegalArgumentException
("Log may not be null.");
}
if (requestExec == null) { if (requestExec == null) {
throw new IllegalArgumentException throw new IllegalArgumentException
("Request executor may not be null."); ("Request executor may not be null.");
@ -275,6 +281,7 @@ public class DefaultRequestDirector implements RequestDirector {
throw new IllegalArgumentException throw new IllegalArgumentException
("HTTP parameters may not be null"); ("HTTP parameters may not be null");
} }
this.log = log;
this.requestExec = requestExec; this.requestExec = requestExec;
this.connManager = conman; this.connManager = conman;
this.reuseStrategy = reustrat; this.reuseStrategy = reustrat;