From 6781e3b79f4ff822aeb68d4d3a3dcd8b49ad86f9 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Wed, 12 Sep 2007 00:03:02 +0000
Subject: [PATCH] Make a couple of changes to help improve server performance:
---
opendj-sdk/opends/src/server/org/opends/server/protocols/ldap/LDAPStatistics.java | 509 ++++++--------------------------------------------------
1 files changed, 58 insertions(+), 451 deletions(-)
diff --git a/opendj-sdk/opends/src/server/org/opends/server/protocols/ldap/LDAPStatistics.java b/opendj-sdk/opends/src/server/org/opends/server/protocols/ldap/LDAPStatistics.java
index 360e339..ec0947c 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/protocols/ldap/LDAPStatistics.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/protocols/ldap/LDAPStatistics.java
@@ -25,27 +25,26 @@
* Portions Copyright 2006-2007 Sun Microsystems, Inc.
*/
package org.opends.server.protocols.ldap;
-import org.opends.messages.Message;
import java.util.ArrayList;
import java.util.LinkedHashSet;
-import java.util.concurrent.locks.ReentrantLock;
+import org.opends.messages.Message;
import org.opends.server.admin.std.server.MonitorProviderCfg;
import org.opends.server.api.MonitorProvider;
import org.opends.server.core.DirectoryServer;
import org.opends.server.config.ConfigException;
+import org.opends.server.loggers.debug.DebugTracer;
import org.opends.server.protocols.asn1.ASN1OctetString;
import org.opends.server.types.Attribute;
import org.opends.server.types.AttributeType;
import org.opends.server.types.AttributeValue;
import org.opends.server.types.DebugLogLevel;
-import static org.opends.server.loggers.debug.DebugLogger.*;
-import org.opends.server.loggers.debug.DebugTracer;
import static org.opends.messages.ProtocolMessages.*;
+import static org.opends.server.loggers.debug.DebugLogger.*;
import static org.opends.server.protocols.ldap.LDAPConstants.*;
@@ -120,11 +119,11 @@
// The locks used to provide threadsafe access to this class. In this case,
// read and write refer to the type of LDAP communication, not access to the
// protected data.
- private ReentrantLock abandonLock;
- private ReentrantLock connectLock;
- private ReentrantLock disconnectLock;
- private ReentrantLock readLock;
- private ReentrantLock writeLock;
+ private Object abandonLock;
+ private Object connectLock;
+ private Object disconnectLock;
+ private Object readLock;
+ private Object writeLock;
// The instance name for this monitor provider instance.
private String instanceName;
@@ -162,11 +161,11 @@
this.instanceName = instanceName;
this.parent = parent;
- abandonLock = new ReentrantLock();
- connectLock = new ReentrantLock();
- disconnectLock = new ReentrantLock();
- readLock = new ReentrantLock();
- writeLock = new ReentrantLock();
+ abandonLock = new Object();
+ connectLock = new Object();
+ disconnectLock = new Object();
+ readLock = new Object();
+ writeLock = new Object();
abandonRequests = 0;
addRequests = 0;
@@ -307,25 +306,15 @@
// Quickly grab the locks and store consistent copies of the information.
// Note that when grabbing multiple locks, it is essential that they are all
// acquired in the same order to prevent deadlocks.
- abandonLock.lock();
-
- try
+ synchronized (abandonLock)
{
- connectLock.lock();
-
- try
+ synchronized (connectLock)
{
- disconnectLock.lock();
-
- try
+ synchronized (disconnectLock)
{
- writeLock.lock();
-
- try
+ synchronized (writeLock)
{
- readLock.lock();
-
- try
+ synchronized (readLock)
{
tmpAbandonRequests = abandonRequests;
tmpAddRequests = addRequests;
@@ -357,74 +346,9 @@
tmpSearchResultsDone = searchResultsDone;
tmpUnbindRequests = unbindRequests;
}
- catch (Exception e)
- {
- if (debugEnabled())
- {
- TRACER.debugCaught(DebugLogLevel.ERROR, e);
- }
-
- return attrs;
- }
- finally
- {
- readLock.unlock();
- }
- }
- catch (Exception e)
- {
- if (debugEnabled())
- {
- TRACER.debugCaught(DebugLogLevel.ERROR, e);
- }
-
- return attrs;
- }
- finally
- {
- writeLock.unlock();
}
}
- catch (Exception e)
- {
- if (debugEnabled())
- {
- TRACER.debugCaught(DebugLogLevel.ERROR, e);
- }
-
- return attrs;
- }
- finally
- {
- disconnectLock.unlock();
- }
}
- catch (Exception e)
- {
- if (debugEnabled())
- {
- TRACER.debugCaught(DebugLogLevel.ERROR, e);
- }
-
- return attrs;
- }
- finally
- {
- connectLock.unlock();
- }
- }
- catch (Exception e)
- {
- if (debugEnabled())
- {
- TRACER.debugCaught(DebugLogLevel.ERROR, e);
- }
-
- return attrs;
- }
- finally
- {
- abandonLock.unlock();
}
@@ -496,25 +420,15 @@
// Quickly grab the locks and store consistent copies of the information.
// Note that when grabbing multiple locks, it is essential that they are all
// acquired in the same order to prevent deadlocks.
- abandonLock.lock();
-
- try
+ synchronized (abandonLock)
{
- connectLock.lock();
-
- try
+ synchronized (connectLock)
{
- disconnectLock.lock();
-
- try
+ synchronized (disconnectLock)
{
- writeLock.lock();
-
- try
+ synchronized (writeLock)
{
- readLock.lock();
-
- try
+ synchronized (readLock)
{
abandonRequests = 0;
addRequests = 0;
@@ -546,64 +460,9 @@
searchResultsDone = 0;
unbindRequests = 0;
}
- catch (Exception e)
- {
- if (debugEnabled())
- {
- TRACER.debugCaught(DebugLogLevel.ERROR, e);
- }
- }
- finally
- {
- readLock.unlock();
- }
- }
- catch (Exception e)
- {
- if (debugEnabled())
- {
- TRACER.debugCaught(DebugLogLevel.ERROR, e);
- }
- }
- finally
- {
- writeLock.unlock();
}
}
- catch (Exception e)
- {
- if (debugEnabled())
- {
- TRACER.debugCaught(DebugLogLevel.ERROR, e);
- }
- }
- finally
- {
- disconnectLock.unlock();
- }
}
- catch (Exception e)
- {
- if (debugEnabled())
- {
- TRACER.debugCaught(DebugLogLevel.ERROR, e);
- }
- }
- finally
- {
- connectLock.unlock();
- }
- }
- catch (Exception e)
- {
- if (debugEnabled())
- {
- TRACER.debugCaught(DebugLogLevel.ERROR, e);
- }
- }
- finally
- {
- abandonLock.unlock();
}
}
@@ -615,23 +474,10 @@
*/
public void updateConnect()
{
- connectLock.lock();
-
- try
+ synchronized (connectLock)
{
connectionsEstablished++;
}
- catch (Exception e)
- {
- if (debugEnabled())
- {
- TRACER.debugCaught(DebugLogLevel.ERROR, e);
- }
- }
- finally
- {
- connectLock.unlock();
- }
// Update the parent if there is one.
if (parent != null)
@@ -648,23 +494,10 @@
*/
public void updateDisconnect()
{
- disconnectLock.lock();
-
- try
+ synchronized (disconnectLock)
{
connectionsClosed++;
}
- catch (Exception e)
- {
- if (debugEnabled())
- {
- TRACER.debugCaught(DebugLogLevel.ERROR, e);
- }
- }
- finally
- {
- disconnectLock.unlock();
- }
// Update the parent if there is one.
if (parent != null)
@@ -683,23 +516,10 @@
*/
public void updateBytesRead(int bytesRead)
{
- readLock.lock();
-
- try
+ synchronized (readLock)
{
this.bytesRead += bytesRead;
}
- catch (Exception e)
- {
- if (debugEnabled())
- {
- TRACER.debugCaught(DebugLogLevel.ERROR, e);
- }
- }
- finally
- {
- readLock.unlock();
- }
// Update the parent if there is one.
if (parent != null)
@@ -718,9 +538,7 @@
*/
public void updateMessageRead(LDAPMessage message)
{
- readLock.lock();
-
- try
+ synchronized (readLock)
{
messagesRead++;
operationsInitiated++;
@@ -759,17 +577,6 @@
break;
}
}
- catch (Exception e)
- {
- if (debugEnabled())
- {
- TRACER.debugCaught(DebugLogLevel.ERROR, e);
- }
- }
- finally
- {
- readLock.unlock();
- }
// Update the parent if there is one.
if (parent != null)
@@ -789,9 +596,7 @@
*/
public void updateMessageWritten(LDAPMessage message, int bytesWritten)
{
- writeLock.lock();
-
- try
+ synchronized (writeLock)
{
this.bytesWritten += bytesWritten;
messagesWritten++;
@@ -844,17 +649,6 @@
break;
}
}
- catch (Exception e)
- {
- if (debugEnabled())
- {
- TRACER.debugCaught(DebugLogLevel.ERROR, e);
- }
- }
- finally
- {
- writeLock.unlock();
- }
// Update the parent if there is one.
if (parent != null)
@@ -871,23 +665,10 @@
*/
public void updateAbandonedOperation()
{
- abandonLock.lock();
-
- try
+ synchronized (abandonLock)
{
operationsAbandoned++;
}
- catch (Exception e)
- {
- if (debugEnabled())
- {
- TRACER.debugCaught(DebugLogLevel.ERROR, e);
- }
- }
- finally
- {
- abandonLock.unlock();
- }
// Update the parent if there is one.
if (parent != null)
@@ -941,16 +722,10 @@
*/
public long getConnectionsEstablished()
{
- connectLock.lock();
-
- try
+ synchronized (connectLock)
{
return connectionsEstablished;
}
- finally
- {
- connectLock.unlock();
- }
}
@@ -962,16 +737,10 @@
*/
public long getConnectionsClosed()
{
- disconnectLock.lock();
-
- try
+ synchronized (disconnectLock)
{
return connectionsClosed;
}
- finally
- {
- disconnectLock.unlock();
- }
}
@@ -983,16 +752,10 @@
*/
public long getBytesRead()
{
- readLock.lock();
-
- try
+ synchronized (readLock)
{
return bytesRead;
}
- finally
- {
- readLock.unlock();
- }
}
@@ -1004,16 +767,10 @@
*/
public long getBytesWritten()
{
- writeLock.lock();
-
- try
+ synchronized (writeLock)
{
return bytesWritten;
}
- finally
- {
- writeLock.unlock();
- }
}
@@ -1025,16 +782,10 @@
*/
public long getMessagesRead()
{
- readLock.lock();
-
- try
+ synchronized (readLock)
{
return messagesRead;
}
- finally
- {
- readLock.unlock();
- }
}
@@ -1046,16 +797,10 @@
*/
public long getMessagesWritten()
{
- writeLock.lock();
-
- try
+ synchronized (writeLock)
{
return messagesWritten;
}
- finally
- {
- writeLock.unlock();
- }
}
@@ -1067,16 +812,10 @@
*/
public long getOperationsInitiated()
{
- readLock.lock();
-
- try
+ synchronized (readLock)
{
return operationsInitiated;
}
- finally
- {
- readLock.unlock();
- }
}
@@ -1090,16 +829,10 @@
*/
public long getOperationsCompleted()
{
- writeLock.lock();
-
- try
+ synchronized (writeLock)
{
return operationsCompleted;
}
- finally
- {
- writeLock.unlock();
- }
}
@@ -1111,16 +844,10 @@
*/
public long getOperationsAbandoned()
{
- abandonLock.lock();
-
- try
+ synchronized (abandonLock)
{
return operationsAbandoned;
}
- finally
- {
- abandonLock.unlock();
- }
}
@@ -1132,16 +859,10 @@
*/
public long getAbandonRequests()
{
- readLock.lock();
-
- try
+ synchronized (readLock)
{
return abandonRequests;
}
- finally
- {
- readLock.unlock();
- }
}
@@ -1153,16 +874,10 @@
*/
public long getAddRequests()
{
- readLock.lock();
-
- try
+ synchronized (readLock)
{
return addRequests;
}
- finally
- {
- readLock.unlock();
- }
}
@@ -1174,16 +889,10 @@
*/
public long getAddResponses()
{
- writeLock.lock();
-
- try
+ synchronized (writeLock)
{
return addResponses;
}
- finally
- {
- writeLock.unlock();
- }
}
@@ -1195,16 +904,10 @@
*/
public long getBindRequests()
{
- readLock.lock();
-
- try
+ synchronized (readLock)
{
return bindRequests;
}
- finally
- {
- readLock.unlock();
- }
}
@@ -1216,16 +919,10 @@
*/
public long getBindResponses()
{
- writeLock.lock();
-
- try
+ synchronized (writeLock)
{
return bindResponses;
}
- finally
- {
- writeLock.unlock();
- }
}
@@ -1237,16 +934,10 @@
*/
public long getCompareRequests()
{
- readLock.lock();
-
- try
+ synchronized (readLock)
{
return compareRequests;
}
- finally
- {
- readLock.unlock();
- }
}
@@ -1258,16 +949,10 @@
*/
public long getCompareResponses()
{
- writeLock.lock();
-
- try
+ synchronized (writeLock)
{
return compareResponses;
}
- finally
- {
- writeLock.unlock();
- }
}
@@ -1279,16 +964,10 @@
*/
public long getDeleteRequests()
{
- readLock.lock();
-
- try
+ synchronized (readLock)
{
return deleteRequests;
}
- finally
- {
- readLock.unlock();
- }
}
@@ -1300,16 +979,10 @@
*/
public long getDeleteResponses()
{
- writeLock.lock();
-
- try
+ synchronized (writeLock)
{
return deleteResponses;
}
- finally
- {
- writeLock.unlock();
- }
}
@@ -1321,16 +994,10 @@
*/
public long getExtendedRequests()
{
- readLock.lock();
-
- try
+ synchronized (readLock)
{
return extendedRequests;
}
- finally
- {
- readLock.unlock();
- }
}
@@ -1342,16 +1009,10 @@
*/
public long getExtendedResponses()
{
- writeLock.lock();
-
- try
+ synchronized (writeLock)
{
return extendedResponses;
}
- finally
- {
- writeLock.unlock();
- }
}
@@ -1363,16 +1024,10 @@
*/
public long getModifyRequests()
{
- readLock.lock();
-
- try
+ synchronized (readLock)
{
return modifyRequests;
}
- finally
- {
- readLock.unlock();
- }
}
@@ -1384,16 +1039,10 @@
*/
public long getModifyResponses()
{
- writeLock.lock();
-
- try
+ synchronized (writeLock)
{
return modifyResponses;
}
- finally
- {
- writeLock.unlock();
- }
}
@@ -1405,16 +1054,10 @@
*/
public long getModifyDNRequests()
{
- readLock.lock();
-
- try
+ synchronized (readLock)
{
return modifyDNRequests;
}
- finally
- {
- readLock.unlock();
- }
}
@@ -1426,16 +1069,10 @@
*/
public long getModifyDNResponses()
{
- writeLock.lock();
-
- try
+ synchronized (writeLock)
{
return modifyDNResponses;
}
- finally
- {
- writeLock.unlock();
- }
}
@@ -1447,16 +1084,10 @@
*/
public long getSearchRequests()
{
- readLock.lock();
-
- try
+ synchronized (readLock)
{
return searchRequests;
}
- finally
- {
- readLock.unlock();
- }
}
@@ -1468,16 +1099,10 @@
*/
public long getSearchResultEntries()
{
- writeLock.lock();
-
- try
+ synchronized (writeLock)
{
return searchResultEntries;
}
- finally
- {
- writeLock.unlock();
- }
}
@@ -1489,16 +1114,10 @@
*/
public long getSearchResultReferences()
{
- writeLock.lock();
-
- try
+ synchronized (writeLock)
{
return searchResultReferences;
}
- finally
- {
- writeLock.unlock();
- }
}
@@ -1510,16 +1129,10 @@
*/
public long getSearchResultsDone()
{
- writeLock.lock();
-
- try
+ synchronized (writeLock)
{
return searchResultsDone;
}
- finally
- {
- writeLock.unlock();
- }
}
@@ -1531,16 +1144,10 @@
*/
public long getUnbindRequests()
{
- readLock.lock();
-
- try
+ synchronized (readLock)
{
return unbindRequests;
}
- finally
- {
- readLock.unlock();
- }
}
--
Gitblit v1.10.0