Browse files

Misc. JMX improvements

  • Loading branch information...
1 parent bc91ded commit 7033e0fb1753b4f25093d2bd1a0d90a255624258 @jkreps jkreps committed Jun 20, 2009
View
8 src/java/voldemort/server/VoldemortServer.java
@@ -114,14 +114,16 @@ public VoldemortServer(VoldemortConfig config, Cluster cluster) {
voldemortConfig.getCoreThreads(),
voldemortConfig.getMaxThreads(),
voldemortConfig.getSocketBufferSize(),
- "client-request-service"));
+ "client-request-server",
+ voldemortConfig.isJmxEnabled()));
if(voldemortConfig.isAdminServerEnabled())
services.add(new SocketService(requestHandlerFactory.getRequestHandler(RequestFormatType.ADMIN_HANDLER),
identityNode.getAdminPort(),
voldemortConfig.getAdminCoreThreads(),
voldemortConfig.getAdminMaxThreads(),
voldemortConfig.getAdminSocketBufferSize(),
- "admin-service"));
+ "admin-server",
+ voldemortConfig.isJmxEnabled()));
if(voldemortConfig.isJmxEnabled())
services.add(new JmxService(this,
@@ -134,7 +136,7 @@ public VoldemortServer(VoldemortConfig config, Cluster cluster) {
@Override
protected void startInner() throws VoldemortException {
- logger.info("Starting all services: " + services.size());
+ logger.info("Starting " + services.size() + " services.");
long start = System.currentTimeMillis();
for(VoldemortService service: services)
service.start();
View
10 src/java/voldemort/server/socket/SocketService.java
@@ -22,6 +22,7 @@
import voldemort.server.ServiceType;
import voldemort.server.VoldemortService;
import voldemort.server.protocol.RequestHandler;
+import voldemort.utils.JmxUtils;
/**
* The VoldemortService that loads up the socket server
@@ -32,27 +33,34 @@
@JmxManaged(description = "A server that handles remote operations on stores via tcp/ip.")
public class SocketService extends AbstractService implements VoldemortService {
+ private final String serviceName;
private final SocketServer server;
+ private final boolean enableJmx;
public SocketService(RequestHandler requestHandler,
int port,
int coreConnections,
int maxConnections,
int socketBufferSize,
- String serviceName) {
+ String serviceName,
+ boolean enableJmx) {
super(ServiceType.SOCKET);
this.server = new SocketServer(serviceName,
port,
coreConnections,
maxConnections,
socketBufferSize,
requestHandler);
+ this.serviceName = serviceName;
+ this.enableJmx = enableJmx;
}
@Override
protected void startInner() {
this.server.start();
this.server.awaitStartupCompletion();
+ if(enableJmx)
+ JmxUtils.registerMbean(serviceName, server);
}
@Override
View
21 src/java/voldemort/server/storage/StorageService.java
@@ -17,7 +17,6 @@
package voldemort.server.storage;
import java.io.File;
-import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
@@ -29,9 +28,6 @@
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.Semaphore;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-
import org.apache.log4j.Logger;
import voldemort.VoldemortException;
@@ -118,6 +114,10 @@ private void initStorageConfig(String configClassName) {
new Object[] { voldemortConfig });
logger.info("Initializing " + configuration.getType() + " storage engine.");
storageConfigs.put(configuration.getType(), configuration);
+
+ if(voldemortConfig.isJmxEnabled())
+ JmxUtils.registerMbean(configuration.getType() + "StorageConfiguration",
+ configuration);
} catch(IllegalStateException e) {
logger.error("Error loading storage configuration '" + configClassName + "'.", e);
}
@@ -183,17 +183,8 @@ public void registerEngine(StorageEngine<ByteArray, byte[]> engine) {
SystemTime.INSTANCE);
if(voldemortConfig.isStatTrackingEnabled()) {
store = new StatTrackingStore<ByteArray, byte[]>(store);
-
- if(voldemortConfig.isJmxEnabled()) {
-
- MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
- ObjectName name = JmxUtils.createObjectName(JmxUtils.getPackageName(store.getClass()),
- store.getName());
-
- if(mbeanServer.isRegistered(name))
- JmxUtils.unregisterMbean(mbeanServer, name);
- JmxUtils.registerMbean(mbeanServer, JmxUtils.createModelMBean(store), name);
- }
+ if(voldemortConfig.isJmxEnabled())
+ JmxUtils.registerMbean(store.getName(), store);
}
storeRepository.addLocalStore(store);
}
View
18 src/java/voldemort/store/bdb/BdbStorageConfiguration.java
@@ -23,6 +23,7 @@
import org.apache.log4j.Logger;
import voldemort.VoldemortException;
+import voldemort.annotations.jmx.JmxGetter;
import voldemort.server.VoldemortConfig;
import voldemort.store.StorageConfiguration;
import voldemort.store.StorageEngine;
@@ -35,6 +36,8 @@
import com.sleepycat.je.DatabaseException;
import com.sleepycat.je.Environment;
import com.sleepycat.je.EnvironmentConfig;
+import com.sleepycat.je.EnvironmentStats;
+import com.sleepycat.je.StatsConfig;
/**
* The configuration that is shared between berkeley db instances. This includes
@@ -115,6 +118,21 @@ public String getType() {
return TYPE_NAME;
}
+ public EnvironmentStats getEnvStats() {
+ try {
+ StatsConfig config = new StatsConfig();
+ config.setFast(true);
+ return environment.getStats(config);
+ } catch(DatabaseException e) {
+ throw new VoldemortException(e);
+ }
+ }
+
+ @JmxGetter(name = "stats", description = "A variety of stats about this BDB environment.")
+ public String getEnvStatsAsString() {
+ return getEnvStats().toString();
+ }
+
public void close() {
synchronized(lock) {
try {
View
41 src/java/voldemort/store/bdb/BdbStorageEngine.java
@@ -27,6 +27,7 @@
import org.apache.log4j.Logger;
import voldemort.VoldemortException;
+import voldemort.annotations.jmx.JmxGetter;
import voldemort.serialization.IdentitySerializer;
import voldemort.serialization.VersionedSerializer;
import voldemort.store.NoSuchCapabilityException;
@@ -49,11 +50,13 @@
import com.sleepycat.je.Database;
import com.sleepycat.je.DatabaseEntry;
import com.sleepycat.je.DatabaseException;
+import com.sleepycat.je.DatabaseStats;
import com.sleepycat.je.Environment;
+import com.sleepycat.je.EnvironmentConfig;
import com.sleepycat.je.LockMode;
import com.sleepycat.je.OperationStatus;
+import com.sleepycat.je.StatsConfig;
import com.sleepycat.je.Transaction;
-import com.sleepycat.je.EnvironmentConfig;
/**
* A store that uses BDB for persistence
@@ -83,14 +86,20 @@ public BdbStorageEngine(String name, Environment environment, Database database)
this.isOpen = new AtomicBoolean(true);
try {
- logger.info(" BDB[" + name + "] : cache size = " + environment.getConfig().getCacheSize());
+ logger.info(" BDB[" + name + "] : cache size = "
+ + environment.getConfig().getCacheSize());
logger.info(" BDB[" + name + "] : " + EnvironmentConfig.CLEANER_THREADS + " = "
- + environment.getConfig().getConfigParam(EnvironmentConfig.CLEANER_THREADS));
- logger.info(" BDB[" + name + "] : " + EnvironmentConfig.CLEANER_MIN_FILE_UTILIZATION + " = "
- + environment.getConfig().getConfigParam(EnvironmentConfig.CLEANER_MIN_FILE_UTILIZATION));
+ + environment.getConfig().getConfigParam(EnvironmentConfig.CLEANER_THREADS));
+ logger.info(" BDB["
+ + name
+ + "] : "
+ + EnvironmentConfig.CLEANER_MIN_FILE_UTILIZATION
+ + " = "
+ + environment.getConfig()
+ .getConfigParam(EnvironmentConfig.CLEANER_MIN_FILE_UTILIZATION));
logger.info(" BDB[" + name + "] : " + EnvironmentConfig.LOG_FILE_MAX + " = "
- + environment.getConfig().getConfigParam(EnvironmentConfig.LOG_FILE_MAX));
- } catch (DatabaseException e) {
+ + environment.getConfig().getConfigParam(EnvironmentConfig.LOG_FILE_MAX));
+ } catch(DatabaseException e) {
logger.error("Error getting config inforation for BDB at startup", e);
}
}
@@ -322,7 +331,8 @@ public void close() throws PersistenceFailureException {
private void attemptAbort(Transaction transaction) {
try {
- transaction.abort();
+ if(transaction != null)
+ transaction.abort();
} catch(Exception e) {
logger.error("Abort failed!", e);
}
@@ -338,6 +348,21 @@ private void attemptCommit(Transaction transaction) {
}
}
+ public DatabaseStats getStats() {
+ try {
+ StatsConfig config = new StatsConfig();
+ config.setFast(true);
+ return this.bdbDatabase.getStats(config);
+ } catch(DatabaseException e) {
+ throw new VoldemortException(e);
+ }
+ }
+
+ @JmxGetter(name = "stats", description = "A variety of stats about the BDB for this store.")
+ public String getStatsAsString() {
+ return getStats().toString();
+ }
+
private static class BdbStoreIterator implements
ClosableIterator<Pair<ByteArray, Versioned<byte[]>>> {
View
5 src/java/voldemort/store/socket/SocketPool.java
@@ -154,6 +154,11 @@ public int getNumberOfIdleConnections() {
return this.pool.getNumIdle();
}
+ @JmxGetter(name = "numberOfTotalConnections", description = "The total number of connections, whether active or idle.")
+ public int getTotalNumberOfConnections() {
+ return this.pool.getNumActive() + this.pool.getNumIdle();
+ }
+
@JmxGetter(name = "avgWaitTimeMs", description = "The avg. ms of wait time to acquire a connection.")
public double getAvgWaitTimeMs() {
return this.avgWaitNs.doubleValue() / Time.NS_PER_MS;
View
20 src/java/voldemort/utils/JmxUtils.java
@@ -17,6 +17,7 @@
package voldemort.utils;
import java.lang.annotation.Annotation;
+import java.lang.management.ManagementFactory;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
@@ -292,6 +293,25 @@ public static void registerMbean(MBeanServer server, ModelMBean mbean, ObjectNam
}
/**
+ * Register the given object under the package name of the object's class
+ * with the given type name.
+ *
+ * this method using the platform mbean server as returned by
+ * ManagementFactory.getPlatformMBeanServer()
+ *
+ * @param typeName The name of the type to register
+ * @param obj The object to register as an mbean
+ */
+ public static void registerMbean(String typeName, Object obj) {
+ MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+ ObjectName name = JmxUtils.createObjectName(JmxUtils.getPackageName(obj.getClass()),
+ typeName);
+ if(mbeanServer.isRegistered(name))
+ JmxUtils.unregisterMbean(mbeanServer, name);
+ JmxUtils.registerMbean(mbeanServer, JmxUtils.createModelMBean(obj), name);
+ }
+
+ /**
* Unregister the mbean with the given name
*
* @param server The server to unregister from

0 comments on commit 7033e0f

Please sign in to comment.