Author: manik.surtani(a)jboss.com
Date: 2009-03-07 13:48:08 -0500 (Sat, 07 Mar 2009)
New Revision: 7879
Added:
core/branches/flat/src/test/java/org/horizon/profiling/ProfileTestSlave.java
Modified:
core/branches/flat/src/main/java/org/horizon/commands/RPCCommand.java
core/branches/flat/src/main/java/org/horizon/commands/remote/ReplicateCommand.java
core/branches/flat/src/main/java/org/horizon/factories/ComponentRegistry.java
core/branches/flat/src/main/java/org/horizon/factories/GlobalComponentRegistry.java
core/branches/flat/src/main/java/org/horizon/marshall/HorizonMarshaller.java
core/branches/flat/src/main/java/org/horizon/remoting/InboundInvocationHandlerImpl.java
core/branches/flat/src/test/java/org/horizon/profiling/AbstractProfileTest.java
core/branches/flat/src/test/java/org/horizon/profiling/ProfileTest.java
Log:
Replication based perf improvements
Modified: core/branches/flat/src/main/java/org/horizon/commands/RPCCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/commands/RPCCommand.java 2009-03-07
13:11:36 UTC (rev 7878)
+++ core/branches/flat/src/main/java/org/horizon/commands/RPCCommand.java 2009-03-07
18:48:08 UTC (rev 7879)
@@ -2,9 +2,6 @@
import org.horizon.interceptors.InterceptorChain;
-import java.util.Collection;
-import java.util.List;
-
/**
* The RPCManager only replicates commands wrapped in an RPCCommand. As a wrapper, an
RPCCommand could contain a single
* {@link org.horizon.commands.ReplicableCommand} or a List of them.
@@ -34,23 +31,9 @@
*
* @return a list of all commands.
*/
- List<ReplicableCommand> getCommands();
+ ReplicableCommand[] getCommands();
/**
- * Adds a single command to the list of commands being wrapped
- *
- * @param command command to add
- */
- void addCommand(ReplicableCommand command);
-
- /**
- * Adds a collection of commands to the list of commands being wrapped
- *
- * @param commands commands to add
- */
- void addCommands(Collection<? extends ReplicableCommand> commands);
-
- /**
* @return the name of the cache that produced this command. This will also be the
name of the cache this command is
* intended for.
*/
Modified:
core/branches/flat/src/main/java/org/horizon/commands/remote/ReplicateCommand.java
===================================================================
---
core/branches/flat/src/main/java/org/horizon/commands/remote/ReplicateCommand.java 2009-03-07
13:11:36 UTC (rev 7878)
+++
core/branches/flat/src/main/java/org/horizon/commands/remote/ReplicateCommand.java 2009-03-07
18:48:08 UTC (rev 7879)
@@ -29,9 +29,7 @@
import org.horizon.logging.Log;
import org.horizon.logging.LogFactory;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
+import java.util.Arrays;
import java.util.List;
/**
@@ -52,20 +50,22 @@
private static final Log log = LogFactory.getLog(ReplicateCommand.class);
private static final boolean trace = log.isTraceEnabled();
- private List<ReplicableCommand> commands;
+ private ReplicableCommand[] commands;
private String cacheName;
public ReplicateCommand(List<ReplicableCommand> modifications, String cacheName)
{
if (modifications != null && modifications.size() == 1) {
- this.commands = Collections.singletonList(modifications.get(0));
+ this.commands = new ReplicableCommand[]{modifications.get(0)};
} else {
- this.commands = modifications;
+ this.commands = new ReplicateCommand[modifications.size()];
+ int i = 0;
+ for (ReplicableCommand rc : modifications) commands[i++] = rc;
}
this.cacheName = cacheName;
}
public ReplicateCommand(ReplicableCommand command, String cacheName) {
- commands = Collections.singletonList(command);
+ commands = new ReplicableCommand[]{command};
this.cacheName = cacheName;
}
@@ -85,7 +85,7 @@
*/
public Object perform(InvocationContext ctx) throws Throwable {
if (isSingleCommand()) {
- return processCommand(ctx, commands.get(0));
+ return processCommand(ctx, commands[0]);
} else {
for (ReplicableCommand command : commands) processCommand(ctx, command);
return null;
@@ -134,54 +134,41 @@
return METHOD_ID;
}
- public List<ReplicableCommand> getCommands() {
+ public ReplicableCommand[] getCommands() {
return commands;
}
- public void addCommand(ReplicableCommand command) {
- if (commands == null) {
- commands = Collections.singletonList(command);
- } else {
- upgradeCommandsListIfNeeded();
- commands.add(command);
- }
- }
-
- public void addCommands(Collection<? extends ReplicableCommand> commands) {
- upgradeCommandsListIfNeeded();
- this.commands.addAll(commands);
- }
-
- private void upgradeCommandsListIfNeeded() {
- if (!(commands instanceof ArrayList)) {
- commands = new ArrayList<ReplicableCommand>(commands);
- }
- }
-
public String getCacheName() {
return cacheName;
}
public void setCacheName(String name) {
- this.cacheName = cacheName;
+ this.cacheName = name;
}
- public ReplicableCommand getSingleCommand() {
- return commands.get(0);
+ public final ReplicableCommand getSingleCommand() {
+ return commands == null ? null : commands[0];
}
public Object[] getParameters() {
- return new Object[]{cacheName, commands};
+ int numCommands = commands == null ? 0 : commands.length;
+ Object[] retval = new Object[numCommands + 2];
+ retval[0] = cacheName;
+ retval[1] = numCommands;
+ if (numCommands > 0) System.arraycopy(commands, 0, retval, 2, numCommands);
+ return retval;
}
@SuppressWarnings("unchecked")
public void setParameters(int commandId, Object[] args) {
cacheName = (String) args[0];
- commands = (List<ReplicableCommand>) args[1];
+ int numCommands = (Integer) args[1];
+ commands = new ReplicableCommand[numCommands];
+ System.arraycopy(args, 2, commands, 0, numCommands);
}
- public boolean isSingleCommand() {
- return commands != null && commands.size() == 1;
+ public final boolean isSingleCommand() {
+ return commands != null && commands.length == 1;
}
@Override
@@ -208,18 +195,13 @@
ReplicateCommand clone;
clone = new ReplicateCommand();
clone.interceptorChain = interceptorChain;
- if (commands != null) {
- if (commands.size() == 1)
- clone.commands = Collections.singletonList(commands.get(0));
- else
- clone.commands = new ArrayList<ReplicableCommand>(commands);
- }
+ if (commands != null) clone.commands = commands.clone();
return clone;
}
public boolean containsCommandType(Class<? extends ReplicableCommand> aClass) {
- if (commands.size() == 1) {
- return commands.get(0).getClass().equals(aClass);
+ if (commands.length == 1) {
+ return commands[0].getClass().equals(aClass);
} else {
for (ReplicableCommand command : getCommands()) {
if (command.getClass().equals(aClass)) return true;
@@ -231,7 +213,7 @@
@Override
public String toString() {
return "ReplicateCommand{" +
- "commands=" + commands +
+ "commands=" + (commands == null ? "null" :
Arrays.toString(commands)) +
", cacheName='" + cacheName + '\'' +
'}';
}
Modified: core/branches/flat/src/main/java/org/horizon/factories/ComponentRegistry.java
===================================================================
---
core/branches/flat/src/main/java/org/horizon/factories/ComponentRegistry.java 2009-03-07
13:11:36 UTC (rev 7878)
+++
core/branches/flat/src/main/java/org/horizon/factories/ComponentRegistry.java 2009-03-07
18:48:08 UTC (rev 7879)
@@ -12,6 +12,7 @@
import org.horizon.logging.LogFactory;
import org.horizon.notifications.cachemanagerlistener.CacheManagerNotifier;
+import java.util.HashMap;
import java.util.Map;
/**
@@ -22,6 +23,9 @@
*/
public class ComponentRegistry extends AbstractComponentRegistry {
+ // cached component scopes
+ static final Map<Class, Scopes> componentScopeLookup = new HashMap<Class,
Scopes>();
+
GlobalComponentRegistry globalComponents;
String cacheName;
Log log = LogFactory.getLog(ComponentRegistry.class);
@@ -62,35 +66,51 @@
}
@Override
- public <T> T getComponent(Class<T> componentType, String name) {
+ public final <T> T getComponent(Class<T> componentType, String name) {
if (isGlobal(componentType)) {
return globalComponents.getComponent(componentType, name);
} else {
- return super.getComponent(componentType, name);
+ return getLocalComponent(componentType, name);
}
}
+ @SuppressWarnings("unchecked")
+ public final <T> T getLocalComponent(Class<T> componentType, String name)
{
+ Component wrapper = lookupLocalComponent(componentType, name);
+ if (wrapper == null) return null;
+
+ return (T) (wrapper.instance == NULL_COMPONENT ? null : wrapper.instance);
+ }
+
+ public final <T> T getLocalComponent(Class<T> componentType) {
+ return getLocalComponent(componentType, componentType.getName());
+ }
+
@Override
- protected Map<Class, Class<? extends AbstractComponentFactory>>
getDefaultFactoryMap() {
+ protected final Map<Class, Class<? extends AbstractComponentFactory>>
getDefaultFactoryMap() {
// delegate to parent. No sense maintaining multiple copies of this map.
return globalComponents.getDefaultFactoryMap();
}
@Override
- protected Component lookupComponent(Class componentClass, String name) {
+ protected final Component lookupComponent(Class componentClass, String name) {
if (isGlobal(componentClass)) {
return globalComponents.lookupComponent(componentClass, name);
} else {
- return super.lookupComponent(componentClass, name);
+ return lookupLocalComponent(componentClass, name);
}
}
- public GlobalComponentRegistry getGlobalComponentRegistry() {
+ protected final Component lookupLocalComponent(Class componentClass, String name) {
+ return super.lookupComponent(componentClass, name);
+ }
+
+ public final GlobalComponentRegistry getGlobalComponentRegistry() {
return globalComponents;
}
@Override
- public void registerComponent(Object component, String name) {
+ public final void registerComponent(Object component, String name) {
if (isGlobal(component.getClass())) {
globalComponents.registerComponent(component, name);
} else {
@@ -99,7 +119,12 @@
}
private boolean isGlobal(Class clazz) {
- Scopes componentScope = ScopeDetector.detectScope(clazz);
+ Scopes componentScope = componentScopeLookup.get(clazz);
+ if (componentScope == null) {
+ componentScope = ScopeDetector.detectScope(clazz);
+ componentScopeLookup.put(clazz, componentScope);
+ }
+
return componentScope == Scopes.GLOBAL;
}
Modified:
core/branches/flat/src/main/java/org/horizon/factories/GlobalComponentRegistry.java
===================================================================
---
core/branches/flat/src/main/java/org/horizon/factories/GlobalComponentRegistry.java 2009-03-07
13:11:36 UTC (rev 7878)
+++
core/branches/flat/src/main/java/org/horizon/factories/GlobalComponentRegistry.java 2009-03-07
18:48:08 UTC (rev 7879)
@@ -13,6 +13,8 @@
import javax.management.MBeanServerFactory;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
/**
* A global component registry where shared components are stored.
@@ -96,24 +98,22 @@
}
}
- public ComponentRegistry getNamedComponentRegistry(String name) {
- return getComponent(ComponentRegistry.class, NAMED_REGISTRY_PREFIX + name);
+ Map<String, ComponentRegistry> namedComponents = new HashMap<String,
ComponentRegistry>();
+
+ public final ComponentRegistry getNamedComponentRegistry(String name) {
+ return namedComponents.get(name);
}
- public void registerNamedComponentRegistry(ComponentRegistry componentRegistry, String
name) {
- registerComponent(componentRegistry, NAMED_REGISTRY_PREFIX + name);
+ public final void registerNamedComponentRegistry(ComponentRegistry componentRegistry,
String name) {
+ namedComponents.put(name, componentRegistry);
}
- public void unregisterNamedComponentRegistry(String name) {
- componentLookup.remove(NAMED_REGISTRY_PREFIX + name);
+ public final void unregisterNamedComponentRegistry(String name) {
+ namedComponents.remove(name);
}
- public void rewireNamedRegistries() {
- for (String name : componentLookup.keySet()) {
- if (name.startsWith(NAMED_REGISTRY_PREFIX)) {
- Component c = componentLookup.get(name);
- ((ComponentRegistry) c.instance).rewire();
- }
- }
+ public final void rewireNamedRegistries() {
+ for (ComponentRegistry cr : namedComponents.values())
+ cr.rewire();
}
}
Modified: core/branches/flat/src/main/java/org/horizon/marshall/HorizonMarshaller.java
===================================================================
---
core/branches/flat/src/main/java/org/horizon/marshall/HorizonMarshaller.java 2009-03-07
13:11:36 UTC (rev 7878)
+++
core/branches/flat/src/main/java/org/horizon/marshall/HorizonMarshaller.java 2009-03-07
18:48:08 UTC (rev 7879)
@@ -198,9 +198,8 @@
marshallObject(le.getTransaction(), out, refMap);
marshallObject(le.getModifications(), out, refMap);
} else if (o instanceof Serializable) {
- if (trace) {
- log.trace("Warning: using object serialization for " +
o.getClass());
- }
+ if (trace) log.trace("WARNING: using object serialization for
[{0}]", o.getClass());
+
out.writeByte(MAGICNUMBER_SERIALIZABLE);
if (useRefs) writeReference(out, createReference(o, refMap));
out.writeObject(o);
Modified:
core/branches/flat/src/main/java/org/horizon/remoting/InboundInvocationHandlerImpl.java
===================================================================
---
core/branches/flat/src/main/java/org/horizon/remoting/InboundInvocationHandlerImpl.java 2009-03-07
13:11:36 UTC (rev 7878)
+++
core/branches/flat/src/main/java/org/horizon/remoting/InboundInvocationHandlerImpl.java 2009-03-07
18:48:08 UTC (rev 7879)
@@ -47,9 +47,9 @@
throw new IllegalStateException("Cache named " + cacheName + "
exists but isn't in a state to handle invocations. Its state is " +
cr.getStatus());
}
- InterceptorChain ic = cr.getComponent(InterceptorChain.class);
- InvocationContextContainer icc =
cr.getComponent(InvocationContextContainer.class);
- CommandsFactory commandsFactory = cr.getComponent(CommandsFactory.class);
+ InterceptorChain ic = cr.getLocalComponent(InterceptorChain.class);
+ InvocationContextContainer icc =
cr.getLocalComponent(InvocationContextContainer.class);
+ CommandsFactory commandsFactory = cr.getLocalComponent(CommandsFactory.class);
cmd.setInterceptorChain(ic);
// initialize this command with components specific to the intended cache instance
Modified: core/branches/flat/src/test/java/org/horizon/profiling/AbstractProfileTest.java
===================================================================
---
core/branches/flat/src/test/java/org/horizon/profiling/AbstractProfileTest.java 2009-03-07
13:11:36 UTC (rev 7878)
+++
core/branches/flat/src/test/java/org/horizon/profiling/AbstractProfileTest.java 2009-03-07
18:48:08 UTC (rev 7879)
@@ -1,6 +1,7 @@
package org.horizon.profiling;
import org.horizon.config.Configuration;
+import org.horizon.config.GlobalConfiguration;
import org.horizon.manager.CacheManager;
import org.horizon.manager.DefaultCacheManager;
import org.horizon.test.SingleCacheManagerTest;
@@ -9,11 +10,18 @@
@Test(groups = "profiling", enabled = false, testName =
"profiling.SingleCacheManagerTest")
public abstract class AbstractProfileTest extends SingleCacheManagerTest {
+ protected static final String LOCAL_CACHE_NAME = "local";
+ protected static final String REPL_SYNC_CACHE_NAME = "repl_sync";
+
protected CacheManager createCacheManager() throws Exception {
Configuration cfg = new Configuration();
cfg.setConcurrencyLevel(2000);
- cacheManager = new DefaultCacheManager(cfg);
- cache = cacheManager.getCache();
+ cacheManager = new DefaultCacheManager(GlobalConfiguration.getClusteredDefault());
+ cacheManager.defineCache(LOCAL_CACHE_NAME, cfg);
+ Configuration replCfg = cfg.clone();
+ replCfg.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ replCfg.setFetchInMemoryState(false);
+ cacheManager.defineCache(REPL_SYNC_CACHE_NAME, replCfg);
return cacheManager;
}
}
Modified: core/branches/flat/src/test/java/org/horizon/profiling/ProfileTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/profiling/ProfileTest.java 2009-03-07
13:11:36 UTC (rev 7878)
+++ core/branches/flat/src/test/java/org/horizon/profiling/ProfileTest.java 2009-03-07
18:48:08 UTC (rev 7879)
@@ -21,7 +21,7 @@
*
* @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
*/
-@Test(groups = "profiling", enabled = true, testName =
"profiling.ProfileTest")
+@Test(groups = "profiling", enabled = false, testName =
"profiling.ProfileTest")
public class ProfileTest extends AbstractProfileTest {
/*
Test configuration options
@@ -35,12 +35,18 @@
private List<Object> keys = new ArrayList<Object>(MAX_OVERALL_KEYS);
- @Test(enabled = true)
+ @Test(enabled = false)
public void testLocalMode() throws Exception {
- runCompleteTest();
+ runCompleteTest(LOCAL_CACHE_NAME);
}
- private void runCompleteTest() throws Exception {
+ @Test(enabled = false)
+ public void testReplMode() throws Exception {
+ runCompleteTest(REPL_SYNC_CACHE_NAME);
+ }
+
+ private void runCompleteTest(String cacheName) throws Exception {
+ cache = cacheManager.getCache(cacheName);
init();
startup();
warmup();
Added: core/branches/flat/src/test/java/org/horizon/profiling/ProfileTestSlave.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/profiling/ProfileTestSlave.java
(rev 0)
+++
core/branches/flat/src/test/java/org/horizon/profiling/ProfileTestSlave.java 2009-03-07
18:48:08 UTC (rev 7879)
@@ -0,0 +1,13 @@
+package org.horizon.profiling;
+
+import org.testng.annotations.Test;
+
+@Test(groups = "profiling", enabled = false, testName =
"profiling.ProfileTestSlave")
+public class ProfileTestSlave extends AbstractProfileTest {
+ @Test(enabled = true)
+ public void testReplMode() throws Exception {
+ cache = cacheManager.getCache(REPL_SYNC_CACHE_NAME);
+ System.out.println("Waiting for test completion. Hit any key when
done.");
+ System.in.read();
+ }
+}