commit e4970764ff1f0d5a20356063470ab30f65c0e2b6 Author: Ryan Rawson Date: Wed Sep 8 11:51:26 2010 -0700 pre-create the metrics and remove the sync block from HBaseRpcMetrics for less contention diff --git a/src/main/java/org/apache/hadoop/hbase/ipc/HBaseRPC.java b/src/main/java/org/apache/hadoop/hbase/ipc/HBaseRPC.java index 134288b..d55fe71 100644 --- a/src/main/java/org/apache/hadoop/hbase/ipc/HBaseRPC.java +++ b/src/main/java/org/apache/hadoop/hbase/ipc/HBaseRPC.java @@ -487,54 +487,28 @@ public class HBaseRPC { * @param instance instance * @param bindAddress bind address * @param port port to bind to - * @param conf configuration - * @return Server - * @throws IOException e - */ - public static Server getServer(final Object instance, final String bindAddress, final int port, Configuration conf) - throws IOException { - return getServer(instance, bindAddress, port, 1, false, conf); - } - - /** - * Construct a server for a protocol implementation instance listening on a - * port and address. - * - * @param instance instance - * @param bindAddress bind address - * @param port port to bind to * @param numHandlers number of handlers to start * @param verbose verbose flag * @param conf configuration * @return Server * @throws IOException e */ - public static Server getServer(final Object instance, final String bindAddress, final int port, + public static Server getServer(final Object instance, + final Class[] ifaces, + final String bindAddress, final int port, final int numHandlers, final boolean verbose, Configuration conf) throws IOException { - return new Server(instance, conf, bindAddress, port, numHandlers, verbose); + return new Server(instance, ifaces, conf, bindAddress, port, numHandlers, verbose); } /** An RPC Server. */ public static class Server extends HBaseServer { private Object instance; private Class implementation; + private Class ifaces[]; private boolean verbose; - /** - * Construct an RPC server. - * @param instance the instance whose methods will be called - * @param conf the configuration to use - * @param bindAddress the address to bind on to listen for connection - * @param port the port to listen for connections on - * @throws IOException e - */ - public Server(Object instance, Configuration conf, String bindAddress, int port) - throws IOException { - this(instance, conf, bindAddress, port, 1, false); - } - private static String classNameBase(String className) { String[] names = className.split("\\.", -1); if (names == null || names.length == 0) { @@ -552,12 +526,19 @@ public class HBaseRPC { * @param verbose whether each call should be logged * @throws IOException e */ - public Server(Object instance, Configuration conf, String bindAddress, int port, + public Server(Object instance, final Class[] ifaces, + Configuration conf, String bindAddress, int port, int numHandlers, boolean verbose) throws IOException { super(bindAddress, port, Invocation.class, numHandlers, conf, classNameBase(instance.getClass().getName())); this.instance = instance; this.implementation = instance.getClass(); + this.verbose = verbose; + + this.ifaces = ifaces; + + // create metrics for the advertised interfaces this server implements. + this.rpcMetrics.createMetrics(this.ifaces); } @Override diff --git a/src/main/java/org/apache/hadoop/hbase/ipc/HBaseRpcMetrics.java b/src/main/java/org/apache/hadoop/hbase/ipc/HBaseRpcMetrics.java index 92468e3..19dbf2b 100644 --- a/src/main/java/org/apache/hadoop/hbase/ipc/HBaseRpcMetrics.java +++ b/src/main/java/org/apache/hadoop/hbase/ipc/HBaseRpcMetrics.java @@ -92,14 +92,26 @@ public class HBaseRpcMetrics implements Updater { return new MetricsTimeVaryingRate(key, this.registry); } - public synchronized void inc(String name, int amt) { + public void inc(String name, int amt) { MetricsTimeVaryingRate m = get(name); if (m == null) { - m = create(name); + LOG.warn("Got inc() request for method that doesnt exist: " + + name); + return; // ignore methods that dont exist. } m.inc(amt); } + public void createMetrics(Class []ifaces) { + for (Class iface : ifaces) { + Method[] methods = iface.getMethods(); + for (Method method : methods) { + if (get(method.getName()) == null) + create(method.getName()); + } + } + } + /** * Push the metrics to the monitoring subsystem on doUpdate() call. * @param context ctx diff --git a/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/src/main/java/org/apache/hadoop/hbase/master/HMaster.java index bc21a1e..cf54a82 100644 --- a/src/main/java/org/apache/hadoop/hbase/master/HMaster.java +++ b/src/main/java/org/apache/hadoop/hbase/master/HMaster.java @@ -184,8 +184,10 @@ implements HMasterInterface, HMasterRegionInterface, MasterServices, Server { */ HServerAddress a = new HServerAddress(getMyAddress(this.conf)); int numHandlers = conf.getInt("hbase.regionserver.handler.count", 10); - this.rpcServer = HBaseRPC.getServer(this, a.getBindAddress(), a.getPort(), - numHandlers, false, conf); + this.rpcServer = HBaseRPC.getServer(this, + new Class[]{HMasterInterface.class, HMasterRegionInterface.class}, + a.getBindAddress(), a.getPort(), + numHandlers, false, conf); this.address = new HServerAddress(rpcServer.getListenerAddress()); // set the thread name now we have an address diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index bba7b67..b8dad89 100644 --- a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -318,10 +318,17 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler, this.abortRequested = false; this.stopped = false; + + //HRegionInterface, + //HBaseRPCErrorHandler, Runnable, Watcher, Stoppable, OnlineRegions + // Server to handle client requests - this.server = HBaseRPC.getServer(this, address.getBindAddress(), address - .getPort(), conf.getInt("hbase.regionserver.handler.count", 10), false, - conf); + this.server = HBaseRPC.getServer(this, + new Class[]{HRegionInterface.class, HBaseRPCErrorHandler.class, + OnlineRegions.class}, + address.getBindAddress(), + address.getPort(), conf.getInt("hbase.regionserver.handler.count", 10), + false, conf); this.server.setErrorHandler(this); // Address is giving a default IP for the moment. Will be changed after // calling the master. @@ -667,15 +674,15 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler, + this.serverInfo.getServerAddress() + ", Now=" + hsa.toString()); this.serverInfo.setServerAddress(hsa); } - - // hack! Maps DFSClient => RegionServer for logs. HDFS made this + + // hack! Maps DFSClient => RegionServer for logs. HDFS made this // config param for task trackers, but we can piggyback off of it. if (this.conf.get("mapred.task.id") == null) { this.conf.set("mapred.task.id", "hb_rs_" + this.serverInfo.getServerName() + "_" + System.currentTimeMillis()); } - + // Master sent us hbase.rootdir to use. Should be fully qualified // path with file system specification included. Set 'fs.defaultFS' // to match the filesystem on hbase.rootdir else underlying hadoop hdfs @@ -2204,7 +2211,7 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler, byte[] regionName = e.getKey(); List actionsForRegion = e.getValue(); // sort based on the row id - this helps in the case where we reach the - // end of a region, so that we don't have to try the rest of the + // end of a region, so that we don't have to try the rest of the // actions in the list. Collections.sort(actionsForRegion); Row action = null; @@ -2238,7 +2245,7 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler, } } } - + return response; }